aboutsummaryrefslogtreecommitdiff
path: root/librsync/helpers_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'librsync/helpers_test.go')
-rw-r--r--librsync/helpers_test.go38
1 files changed, 38 insertions, 0 deletions
diff --git a/librsync/helpers_test.go b/librsync/helpers_test.go
new file mode 100644
index 0000000..c12992f
--- /dev/null
+++ b/librsync/helpers_test.go
@@ -0,0 +1,38 @@
+package librsync
+
+import (
+ "bytes"
+ "github.com/kch42/golibrsync/librsync/testdata"
+ "testing"
+)
+
+func TestHelpers(t *testing.T) {
+ basis := bytes.NewReader(testdata.RandomData())
+ mutation := bytes.NewReader(testdata.Mutation())
+
+ delta := new(bytes.Buffer)
+ if err := InstantDelta(basis, mutation, delta); err != nil {
+ t.Fatalf("InstantDelta failed: %s", err)
+ }
+
+ if !bytes.Equal(delta.Bytes(), testdata.Delta()) {
+ if path, err := dump(delta); err == nil {
+ t.Fatalf("Deltas do not match. Generated delta dumped to %s", path)
+ } else {
+ t.Fatalf("Deltas do not match. Could not dump delta: %s", err)
+ }
+ }
+
+ newfile := new(bytes.Buffer)
+ if err := Patch(basis, delta, newfile); err != nil {
+ t.Fatalf("Patch failed: %s", err)
+ }
+
+ if !bytes.Equal(newfile.Bytes(), testdata.Mutation()) {
+ if path, err := dump(newfile); err == nil {
+ t.Fatalf("patch result and mutation are not equal. Result dumped to %s", path)
+ } else {
+ t.Fatalf("patch result and mutation are not equal. Could not dump result: %s", err)
+ }
+ }
+}