lib/fs: Add test that symlinks are skipped on walk (#5644)

This commit is contained in:
Simon Frei
2019-04-10 22:36:37 +02:00
committed by GitHub
parent 9b2a73f9ab
commit 79360e2205
2 changed files with 47 additions and 0 deletions

41
lib/fs/walkfs_test.go Normal file
View File

@@ -0,0 +1,41 @@
// Copyright (C) 2019 The Syncthing Authors.
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this file,
// You can obtain one at https://mozilla.org/MPL/2.0/.
package fs
import (
"runtime"
"testing"
)
func testWalkSkipSymlink(t *testing.T, fsType FilesystemType, uri string) {
if runtime.GOOS == "windows" {
t.Skip("Symlinks on windows")
}
fs := NewFilesystem(fsType, uri)
if err := fs.MkdirAll("target/foo", 0755); err != nil {
t.Fatal(err)
}
if err := fs.Mkdir("towalk", 0755); err != nil {
t.Fatal(err)
}
if err := fs.CreateSymlink("target", "towalk/symlink"); err != nil {
t.Fatal(err)
}
if err := fs.Walk("towalk", func(path string, info FileInfo, err error) error {
if err != nil {
t.Fatal(err)
}
if info.Name() != "symlink" && info.Name() != "towalk" {
t.Fatal("Walk unexpected file", info.Name())
}
return nil
}); err != nil {
t.Fatal(err)
}
}