mirror of
https://github.com/octoleo/restic.git
synced 2024-12-25 12:09:59 +00:00
restic: add test for FindTreeDirectory
This commit is contained in:
parent
a97915642c
commit
321cc35cde
@ -210,3 +210,37 @@ func benchmarkLoadTree(t *testing.B, version uint) {
|
||||
rtest.OK(t, err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestFindTreeDirectory(t *testing.T) {
|
||||
repo := repository.TestRepository(t)
|
||||
sn := restic.TestCreateSnapshot(t, repo, parseTimeUTC("2017-07-07 07:07:08"), 3, 0)
|
||||
|
||||
for _, exp := range []struct {
|
||||
subpath string
|
||||
id restic.ID
|
||||
err error
|
||||
}{
|
||||
{"", restic.TestParseID("c25199703a67455b34cc0c6e49a8ac8861b268a5dd09dc5b2e31e7380973fc97"), nil},
|
||||
{"/", restic.TestParseID("c25199703a67455b34cc0c6e49a8ac8861b268a5dd09dc5b2e31e7380973fc97"), nil},
|
||||
{".", restic.TestParseID("c25199703a67455b34cc0c6e49a8ac8861b268a5dd09dc5b2e31e7380973fc97"), nil},
|
||||
{"..", restic.ID{}, errors.New("path ..: not found")},
|
||||
{"file-1", restic.ID{}, errors.New("path file-1: not a directory")},
|
||||
{"dir-21", restic.TestParseID("76172f9dec15d7e4cb98d2993032e99f06b73b2f02ffea3b7cfd9e6b4d762712"), nil},
|
||||
{"/dir-21", restic.TestParseID("76172f9dec15d7e4cb98d2993032e99f06b73b2f02ffea3b7cfd9e6b4d762712"), nil},
|
||||
{"dir-21/", restic.TestParseID("76172f9dec15d7e4cb98d2993032e99f06b73b2f02ffea3b7cfd9e6b4d762712"), nil},
|
||||
{"dir-21/dir-24", restic.TestParseID("74626b3fb2bd4b3e572b81a4059b3e912bcf2a8f69fecd9c187613b7173f13b1"), nil},
|
||||
} {
|
||||
t.Run("", func(t *testing.T) {
|
||||
id, err := restic.FindTreeDirectory(context.TODO(), repo, sn.Tree, exp.subpath)
|
||||
if exp.err == nil {
|
||||
rtest.OK(t, err)
|
||||
rtest.Assert(t, exp.id == *id, "unexpected id, expected %v, got %v", exp.id, id)
|
||||
} else {
|
||||
rtest.Assert(t, exp.err.Error() == err.Error(), "unexpected err, expected %v, got %v", exp.err, err)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
_, err := restic.FindTreeDirectory(context.TODO(), repo, nil, "")
|
||||
rtest.Assert(t, err != nil, "missing error on null tree id")
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user