mirror of
https://github.com/kopia/kopia.git
synced 2026-03-05 06:47:12 -05:00
test(general): cleanup symlink tests (#4347)
Ref: feat(snapshots): Fix for #2037 Add symlink support for .kopiaignore #4190
This commit is contained in:
@@ -7,6 +7,7 @@
|
||||
"testing"
|
||||
|
||||
"github.com/kylelemons/godebug/pretty"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/kopia/kopia/fs"
|
||||
"github.com/kopia/kopia/fs/ignorefs"
|
||||
@@ -614,9 +615,8 @@ func walkTree(t *testing.T, dir fs.Directory) []string {
|
||||
relPath := path + "/" + e.Name()
|
||||
|
||||
if subdir, ok := e.(fs.Directory); ok {
|
||||
if err := walk(relPath, subdir); err != nil {
|
||||
t.Fatalf("%s not found in %s", relPath, subdir.Name())
|
||||
}
|
||||
err := walk(relPath, subdir)
|
||||
require.NoError(t, err, relPath, "not found in", subdir.Name())
|
||||
} else {
|
||||
output = append(output, relPath)
|
||||
}
|
||||
@@ -625,9 +625,8 @@ func walkTree(t *testing.T, dir fs.Directory) []string {
|
||||
})
|
||||
}
|
||||
|
||||
if err := walk(".", dir); err != nil {
|
||||
t.Fatalf("error walking tree: %v", err)
|
||||
}
|
||||
err := walk(".", dir)
|
||||
require.NoError(t, err, "error walking tree")
|
||||
|
||||
return output
|
||||
}
|
||||
@@ -637,7 +636,6 @@ func verifyDirectoryTree(t *testing.T, dir fs.Directory, expected []string) {
|
||||
|
||||
output := walkTree(t, dir)
|
||||
|
||||
if diff := pretty.Compare(output, expected); diff != "" {
|
||||
t.Errorf("unexpected directory tree, diff(-got,+want): %v\n", diff)
|
||||
}
|
||||
diff := pretty.Compare(output, expected)
|
||||
require.Empty(t, diff, "unexpected directory tree, diff(-got,+want)")
|
||||
}
|
||||
|
||||
@@ -45,25 +45,24 @@ func verifyLink(t *testing.T, path, expected string) {
|
||||
entry, err := NewEntry(path)
|
||||
require.NoError(t, err)
|
||||
|
||||
if link, ok := entry.(fs.Symlink); !ok {
|
||||
t.Errorf("entry is not a symlink: %s", path)
|
||||
} else {
|
||||
target, err := link.Resolve(ctx)
|
||||
require.NoError(t, err)
|
||||
link, ok := entry.(fs.Symlink)
|
||||
require.True(t, ok, "entry is not a symlink:", entry)
|
||||
|
||||
if f, ok := target.(fs.File); !ok {
|
||||
t.Errorf("Link does not resolve to a file: %s", path)
|
||||
} else {
|
||||
// Canonicalize paths (for example, on MacOS /var points to /private/var)
|
||||
actual, _ := filepath.EvalSymlinks(f.LocalFilesystemPath())
|
||||
expected, _ := filepath.EvalSymlinks(expected)
|
||||
target, err := link.Resolve(ctx)
|
||||
require.NoError(t, err)
|
||||
|
||||
actual = filepath.Clean(actual)
|
||||
expected = filepath.Clean(expected)
|
||||
f, ok := target.(fs.File)
|
||||
require.True(t, ok, "link does not point to a file:", path)
|
||||
|
||||
require.Equal(t, expected, actual)
|
||||
}
|
||||
}
|
||||
// Canonicalize paths (for example, on MacOS /var points to /private/var)
|
||||
// EvalSymlinks calls "Clean" on the result
|
||||
got, err := filepath.EvalSymlinks(f.LocalFilesystemPath())
|
||||
require.NoError(t, err)
|
||||
|
||||
want, err := filepath.EvalSymlinks(expected)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Equal(t, want, got)
|
||||
}
|
||||
|
||||
//nolint:gocyclo
|
||||
|
||||
Reference in New Issue
Block a user