aboutsummaryrefslogtreecommitdiff
path: root/recipe_test.go
diff options
context:
space:
mode:
authorn-peugnet <n.peugnet@free.fr>2021-09-21 12:45:44 +0200
committern-peugnet <n.peugnet@free.fr>2021-09-21 12:45:44 +0200
commit737b29efd7f63a3b44243fd83cdb67518a82be14 (patch)
treeced91e7bca06fe01f9caa7c5d7de1804b1fe5c7e /recipe_test.go
parentd7faf55344a3d86e6d64618ead449b3fbbd88612 (diff)
downloaddna-backup-737b29efd7f63a3b44243fd83cdb67518a82be14.tar.gz
dna-backup-737b29efd7f63a3b44243fd83cdb67518a82be14.zip
add patch and diff logic for recipes
Diffstat (limited to 'recipe_test.go')
-rw-r--r--recipe_test.go24
1 files changed, 24 insertions, 0 deletions
diff --git a/recipe_test.go b/recipe_test.go
new file mode 100644
index 0000000..f5c9b29
--- /dev/null
+++ b/recipe_test.go
@@ -0,0 +1,24 @@
+package main
+
+import "testing"
+
+func TestRecipe(t *testing.T) {
+ c1 := &StoredChunk{Id: &ChunkId{0, 1}}
+ c2 := &StoredChunk{Id: &ChunkId{0, 2}}
+ c3 := &StoredChunk{Id: &ChunkId{0, 3}}
+ c4 := &StoredChunk{Id: &ChunkId{0, 4}}
+ c5 := &StoredChunk{Id: &ChunkId{0, 5}}
+ c6 := &StoredChunk{Id: &ChunkId{0, 6}}
+ c7 := &StoredChunk{Id: &ChunkId{0, 7}}
+ source := Recipe{c1, c2, c3, c4}
+ target := Recipe{c2, c5, c3, c6, c4, c7}
+ patch := diffRecipe(source, target)
+ assertSame(t, []RecipeDel{0}, patch.Del, "Patch del part")
+ assertSame(t, []RecipeIns{
+ {1, []Chunk{c5}},
+ {3, []Chunk{c6}},
+ {5, []Chunk{c7}},
+ }, patch.Ins, "Patch ins part")
+ actual := patchRecipe(source, patch)
+ assertSame(t, target, actual, "Target obtained from patch application")
+}