dump: Add test for splitPath

This commit is contained in:
Michael Eischer 2020-08-29 19:36:13 +02:00
parent da4193c3ef
commit e69449bf2c
2 changed files with 28 additions and 1 deletions

View file

@ -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)
}

View 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)
}
}