From 4f6d2502f7dbaa3249ca280de3704fa13a529bda Mon Sep 17 00:00:00 2001 From: Alexander Neumann Date: Sat, 21 Jul 2018 14:06:19 +0200 Subject: [PATCH] restorer: Add test for restore with include filter --- internal/restorer/restorer_test.go | 31 ++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/internal/restorer/restorer_test.go b/internal/restorer/restorer_test.go index b57b6f409..83a178150 100644 --- a/internal/restorer/restorer_test.go +++ b/internal/restorer/restorer_test.go @@ -134,6 +134,7 @@ func TestRestorer(t *testing.T) { Files map[string]string ErrorsMust map[string]string ErrorsMay map[string]string + Select func(item string, dstpath string, node *restic.Node) (selectForRestore bool, childMayBeSelected bool) }{ // valid test cases { @@ -212,6 +213,31 @@ func TestRestorer(t *testing.T) { "topfile": "top-level file", }, }, + { + Snapshot: Snapshot{ + Nodes: map[string]Node{ + "dir": Dir{ + Nodes: map[string]Node{ + "file": File{"content: file\n"}, + }, + }, + }, + }, + Files: map[string]string{ + "dir/file": "content: file\n", + }, + Select: func(item, dstpath string, node *restic.Node) (selectedForRestore bool, childMayBeSelected bool) { + switch item { + case filepath.FromSlash("/dir"): + childMayBeSelected = true + case filepath.FromSlash("/dir/file"): + selectedForRestore = true + childMayBeSelected = true + } + + return selectedForRestore, childMayBeSelected + }, + }, // test cases with invalid/constructed names { @@ -293,6 +319,11 @@ func TestRestorer(t *testing.T) { item, dstpath, tempdir) return false, false } + + if test.Select != nil { + return test.Select(item, dstpath, node) + } + return true, true }