aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorn-peugnet <n.peugnet@free.fr>2021-09-22 14:39:02 +0200
committern-peugnet <n.peugnet@free.fr>2021-09-22 14:39:02 +0200
commitf3f0f3d451a667c7a12f23baf08853f12cbea4c0 (patch)
treeb020684bd939dde093cbc18fc7a3376918e0ca08
parentd736642d6ea3ae42de3a30f39881c88a00e1a1f9 (diff)
downloaddna-backup-f3f0f3d451a667c7a12f23baf08853f12cbea4c0.tar.gz
dna-backup-f3f0f3d451a667c7a12f23baf08853f12cbea4c0.zip
misc tests and log messages
-rw-r--r--repo.go6
-rw-r--r--slice/slice_test.go19
2 files changed, 22 insertions, 3 deletions
diff --git a/repo.go b/repo.go
index b080cf0..ac8ef71 100644
--- a/repo.go
+++ b/repo.go
@@ -203,7 +203,7 @@ func listFiles(path string) []File {
err := filepath.Walk(path,
func(p string, i fs.FileInfo, err error) error {
if err != nil {
- logger.Error(err)
+ logger.Warning(err)
return err
}
if i.IsDir() {
@@ -332,7 +332,7 @@ func slice2fileList(s slice.Slice) (ret []File) {
func (r *Repo) storeFileList(version int, list []File) {
dest := filepath.Join(r.path, fmt.Sprintf(versionFmt, version), filesName)
delta := slice.Diff(fileList2slice(r.files), fileList2slice(list))
- logger.Info("files delta: ", delta)
+ logger.Info("files delta del: ", len(delta.Del), ", ins: ", len(delta.Ins))
storeBasicStruct(dest, utils.NopWriteWrapper, delta)
}
@@ -705,7 +705,7 @@ func slice2recipe(s slice.Slice) (ret []Chunk) {
func (r *Repo) storeRecipe(version int, recipe []Chunk) {
dest := filepath.Join(r.path, fmt.Sprintf(versionFmt, version), recipeName)
delta := slice.Diff(recipe2slice(r.recipe), recipe2slice(recipe))
- logger.Info("recipe delta: ", delta)
+ logger.Info("recipe delta del: ", len(delta.Del), ", ins:", len(delta.Ins))
storeBasicStruct(dest, utils.NopWriteWrapper, delta)
}
diff --git a/slice/slice_test.go b/slice/slice_test.go
index 0cf1c40..d678fc7 100644
--- a/slice/slice_test.go
+++ b/slice/slice_test.go
@@ -29,3 +29,22 @@ func TestEmptyPatch(t *testing.T) {
actual := Patch(source, patch)
testutils.AssertSame(t, target, actual, "Target obtained from patch application")
}
+
+type i struct {
+ int
+}
+
+func TestStruct(t *testing.T) {
+ c1, c2, c3, c4, c5, c6, c7, c8 := &i{1}, &i{2}, &i{3}, &i{4}, &i{5}, &i{6}, &i{7}, &i{8}
+ source := Slice{c1, c2, c3, c4}
+ target := Slice{&i{5}, c2, c5, c6, &i{4}, c7, &i{8}}
+ patch := Diff(source, target)
+ testutils.AssertSame(t, []Del{0, 2}, patch.Del, "Patch del part")
+ testutils.AssertSame(t, []Ins{
+ {0, Slice{c5}},
+ {2, Slice{c5, c6}},
+ {5, Slice{c7, c8}},
+ }, patch.Ins, "Patch ins part")
+ actual := Patch(source, patch)
+ testutils.AssertSame(t, target, actual, "Target obtained from patch application")
+}