1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
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)
}
}
}
|