From 3e866db2accc6ed5aa65befdf21474dbc7b1ec18 Mon Sep 17 00:00:00 2001 From: n-peugnet Date: Thu, 9 Sep 2021 16:21:20 +0200 Subject: first add of restore function to Repo --- repo_test.go | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) (limited to 'repo_test.go') diff --git a/repo_test.go b/repo_test.go index 29282bc..5127263 100644 --- a/repo_test.go +++ b/repo_test.go @@ -230,13 +230,44 @@ func TestBsdiff(t *testing.T) { func TestCommit(t *testing.T) { dest := t.TempDir() - source := "testdata" + source := path.Join("testdata", "logs") repo := NewRepo(dest) repo.Commit(source) recipe := loadRecipe(path.Join(dest, "00000", recipeName)) log.Println(recipe) } +func TestRestore(t *testing.T) { + dest := t.TempDir() + source := path.Join("testdata", "repo_8k") + repo := NewRepo(source) + repo.Restore(dest) + destFiles := listFiles(dest) + sourceFiles := listFiles(path.Join("testdata", "logs")) + sfCount := len(sourceFiles) + if sfCount <= 0 { + t.Fatalf("No source files: %d", sfCount) + } + dfCount := len(destFiles) + if sfCount != dfCount { + t.Fatalf("Incorrect number for destination files: %d, should be %d", dfCount, sfCount) + } + for i, sf := range sourceFiles { + sfContent, err := os.ReadFile(sf.Path) + if err != nil { + t.Fatalf("Error reading from source file '%s': %s", sf.Path, err) + } + df := destFiles[i] + dfContent, err := os.ReadFile(df.Path) + if err != nil { + t.Fatalf("Error reading from source file '%s': %s", df.Path, err) + } + if bytes.Compare(sfContent, dfContent) != 0 { + t.Errorf("File content of '%s' does not match '%s'", df.Path, sf.Path) + } + } +} + func assertLen(t *testing.T, expected int, actual interface{}, prefix string) { s := reflect.ValueOf(actual) if s.Len() != expected { -- cgit v1.2.3