mirror of
https://github.com/octoleo/restic.git
synced 2024-12-22 02:48:55 +00:00
dump: Add test for splitPath
This commit is contained in:
parent
da4193c3ef
commit
e69449bf2c
@ -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 New Issue
Block a user