2
2
mirror of https://github.com/octoleo/restic.git synced 2024-11-21 20:35:12 +00:00

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