This fixes various test issues with Go 1.20. - Most tests rewritten to use fakefs where possible - Some tests that were already skipped, or dubious (invasive, unmaintainable, unclear what they even tested) have been removed - Some actual code rewritten to better support testing in fakefs Co-authored-by: Eric P <eric@kastelo.net>
This commit is contained in:
@@ -8,14 +8,13 @@ package osutil_test
|
||||
|
||||
import (
|
||||
"io"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/syncthing/syncthing/lib/build"
|
||||
"github.com/syncthing/syncthing/lib/fs"
|
||||
"github.com/syncthing/syncthing/lib/osutil"
|
||||
"github.com/syncthing/syncthing/lib/rand"
|
||||
)
|
||||
|
||||
func TestIsDeleted(t *testing.T) {
|
||||
@@ -41,9 +40,9 @@ func TestIsDeleted(t *testing.T) {
|
||||
{filepath.Join("del", "del", "del"), true},
|
||||
}
|
||||
|
||||
testFs := fs.NewFilesystem(fs.FilesystemTypeBasic, "testdata")
|
||||
testFs := fs.NewFilesystem(fs.FilesystemTypeFake, "testdata")
|
||||
|
||||
testFs.MkdirAll("dir", 0777)
|
||||
testFs.MkdirAll("dir", 0o777)
|
||||
for _, f := range []string{"file", "del.file", "dir.file", filepath.Join("dir", "file")} {
|
||||
fd, err := testFs.Create(f)
|
||||
if err != nil {
|
||||
@@ -51,21 +50,9 @@ func TestIsDeleted(t *testing.T) {
|
||||
}
|
||||
fd.Close()
|
||||
}
|
||||
if !build.IsWindows {
|
||||
// Can't create unreadable dir on windows
|
||||
testFs.MkdirAll("inacc", 0777)
|
||||
if err := testFs.Chmod("inacc", 0000); err == nil {
|
||||
if _, err := testFs.Lstat(filepath.Join("inacc", "file")); fs.IsPermission(err) {
|
||||
// May fail e.g. if tests are run as root -> just skip
|
||||
cases = append(cases, tc{"inacc", false}, tc{filepath.Join("inacc", "file"), false})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for _, n := range []string{"Dir", "File", "Del"} {
|
||||
if err := fs.DebugSymlinkForTestsOnly(testFs, testFs, strings.ToLower(n), "linkTo"+n); err != nil {
|
||||
if build.IsWindows {
|
||||
t.Skip("Symlinks aren't working")
|
||||
}
|
||||
if err := testFs.CreateSymlink(strings.ToLower(n), "linkTo"+n); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
@@ -75,13 +62,10 @@ func TestIsDeleted(t *testing.T) {
|
||||
t.Errorf("IsDeleted(%v) != %v", c.path, c.isDel)
|
||||
}
|
||||
}
|
||||
|
||||
testFs.Chmod("inacc", 0777)
|
||||
os.RemoveAll("testdata")
|
||||
}
|
||||
|
||||
func TestRenameOrCopy(t *testing.T) {
|
||||
sameFs := fs.NewFilesystem(fs.FilesystemTypeBasic, t.TempDir())
|
||||
sameFs := fs.NewFilesystem(fs.FilesystemTypeFake, rand.String(32)+"?content=true")
|
||||
tests := []struct {
|
||||
src fs.Filesystem
|
||||
dst fs.Filesystem
|
||||
@@ -93,13 +77,13 @@ func TestRenameOrCopy(t *testing.T) {
|
||||
file: "file",
|
||||
},
|
||||
{
|
||||
src: fs.NewFilesystem(fs.FilesystemTypeBasic, t.TempDir()),
|
||||
dst: fs.NewFilesystem(fs.FilesystemTypeBasic, t.TempDir()),
|
||||
src: fs.NewFilesystem(fs.FilesystemTypeFake, rand.String(32)+"?content=true"),
|
||||
dst: fs.NewFilesystem(fs.FilesystemTypeFake, rand.String(32)+"?content=true"),
|
||||
file: "file",
|
||||
},
|
||||
{
|
||||
src: fs.NewFilesystem(fs.FilesystemTypeFake, `fake://fake/?files=1&seed=42`),
|
||||
dst: fs.NewFilesystem(fs.FilesystemTypeBasic, t.TempDir()),
|
||||
dst: fs.NewFilesystem(fs.FilesystemTypeFake, rand.String(32)+"?content=true"),
|
||||
file: osutil.NativeFilename(`05/7a/4d52f284145b9fe8`),
|
||||
},
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user