diff options
author | n-peugnet <n.peugnet@free.fr> | 2021-09-09 16:21:20 +0200 |
---|---|---|
committer | n-peugnet <n.peugnet@free.fr> | 2021-09-09 16:21:20 +0200 |
commit | 3e866db2accc6ed5aa65befdf21474dbc7b1ec18 (patch) | |
tree | 62670e092cbc41817edc76317a0ac2482b9480af /repo_test.go | |
parent | 11404879f2e7ee02118852b6b42e19f99cb2edd9 (diff) | |
download | dna-backup-3e866db2accc6ed5aa65befdf21474dbc7b1ec18.tar.gz dna-backup-3e866db2accc6ed5aa65befdf21474dbc7b1ec18.zip |
first add of restore function to Repo
Diffstat (limited to 'repo_test.go')
-rw-r--r-- | repo_test.go | 33 |
1 files changed, 32 insertions, 1 deletions
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 { |