forked from TrueCloudLab/restic
dump: Add test for splitPath
This commit is contained in:
parent
da4193c3ef
commit
e69449bf2c
2 changed files with 28 additions and 1 deletions
|
@ -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)
|
||||
}
|
||||
|
||||
|
|
27
cmd/restic/cmd_dump_test.go
Normal file
27
cmd/restic/cmd_dump_test.go
Normal file
|
@ -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)
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue