mirror of
https://github.com/restic/restic.git
synced 2025-12-13 11:22:25 +00:00
dump: Add test for splitPath
This commit is contained in:
@@ -59,7 +59,7 @@ func splitPath(p string) []string {
|
|||||||
if d == "" || d == "/" {
|
if d == "" || d == "/" {
|
||||||
return []string{f}
|
return []string{f}
|
||||||
}
|
}
|
||||||
s := splitPath(path.Clean(path.Join("/", d)))
|
s := splitPath(path.Join("/", d))
|
||||||
return append(s, f)
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user