From e69449bf2cc3a01a1869039528c22a9c72340bd5 Mon Sep 17 00:00:00 2001 From: Michael Eischer Date: Sat, 29 Aug 2020 19:36:13 +0200 Subject: [PATCH] dump: Add test for splitPath --- cmd/restic/cmd_dump.go | 2 +- cmd/restic/cmd_dump_test.go | 27 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 cmd/restic/cmd_dump_test.go diff --git a/cmd/restic/cmd_dump.go b/cmd/restic/cmd_dump.go index 4763ec55b..b8bfb1fc1 100644 --- a/cmd/restic/cmd_dump.go +++ b/cmd/restic/cmd_dump.go @@ -59,7 +59,7 @@ func splitPath(p string) []string { if d == "" || d == "/" { return []string{f} } - s := splitPath(path.Clean(path.Join("/", d))) + s := splitPath(path.Join("/", d)) return append(s, f) } diff --git a/cmd/restic/cmd_dump_test.go b/cmd/restic/cmd_dump_test.go new file mode 100644 index 000000000..aa43117ee --- /dev/null +++ b/cmd/restic/cmd_dump_test.go @@ -0,0 +1,27 @@ +package main + +import ( + "testing" + + rtest "github.com/restic/restic/internal/test" +) + +func TestDumpSplitPath(t *testing.T) { + testPaths := []struct { + path string + result []string + }{ + {"", []string{""}}, + {"test", []string{"test"}}, + {"test/dir", []string{"test", "dir"}}, + {"test/dir/sub", []string{"test", "dir", "sub"}}, + {"/", []string{""}}, + {"/test", []string{"test"}}, + {"/test/dir", []string{"test", "dir"}}, + {"/test/dir/sub", []string{"test", "dir", "sub"}}, + } + for _, path := range testPaths { + parts := splitPath(path.path) + rtest.Equals(t, path.result, parts) + } +}