68 lines
1.3 KiB
Go
68 lines
1.3 KiB
Go
|
package change
|
||
|
|
||
|
import (
|
||
|
"bytes"
|
||
|
"reflect"
|
||
|
"testing"
|
||
|
)
|
||
|
|
||
|
func (lhs Change) AssertEqual(t *testing.T, rhs Change) {
|
||
|
if lhs.CollectionID != rhs.CollectionID {
|
||
|
t.Fatal(lhs.CollectionID, rhs.CollectionID)
|
||
|
}
|
||
|
if lhs.ItemID != rhs.ItemID {
|
||
|
t.Fatal(lhs.ItemID, rhs.ItemID)
|
||
|
}
|
||
|
if lhs.Store != rhs.Store {
|
||
|
t.Fatal(lhs.Store, rhs.Store)
|
||
|
}
|
||
|
|
||
|
if len(lhs.Data) != len(rhs.Data) {
|
||
|
t.Fatal(len(lhs.Data), len(rhs.Data))
|
||
|
}
|
||
|
|
||
|
if len(lhs.Data) != 0 {
|
||
|
if !reflect.DeepEqual(lhs.Data, rhs.Data) {
|
||
|
t.Fatal(lhs.Data, rhs.Data)
|
||
|
}
|
||
|
}
|
||
|
|
||
|
if len(lhs.WritePageIDs) != len(rhs.WritePageIDs) {
|
||
|
t.Fatal(len(lhs.WritePageIDs), len(rhs.WritePageIDs))
|
||
|
}
|
||
|
|
||
|
if len(lhs.WritePageIDs) != 0 {
|
||
|
if !reflect.DeepEqual(lhs.WritePageIDs, rhs.WritePageIDs) {
|
||
|
t.Fatal(lhs.WritePageIDs, rhs.WritePageIDs)
|
||
|
}
|
||
|
}
|
||
|
|
||
|
if len(lhs.ClearPageIDs) != len(rhs.ClearPageIDs) {
|
||
|
t.Fatal(len(lhs.ClearPageIDs), len(rhs.ClearPageIDs))
|
||
|
}
|
||
|
|
||
|
if len(lhs.ClearPageIDs) != 0 {
|
||
|
if !reflect.DeepEqual(lhs.ClearPageIDs, rhs.ClearPageIDs) {
|
||
|
t.Fatal(lhs.ClearPageIDs, rhs.ClearPageIDs)
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func TestChangeWriteToReadFrom(t *testing.T) {
|
||
|
out := Change{}
|
||
|
|
||
|
for i := 0; i < 100; i++ {
|
||
|
in := randChange()
|
||
|
buf := &bytes.Buffer{}
|
||
|
if err := in.writeTo(buf); err != nil {
|
||
|
t.Fatal(err)
|
||
|
}
|
||
|
|
||
|
if err := out.readFrom(buf); err != nil {
|
||
|
t.Fatal(err)
|
||
|
}
|
||
|
|
||
|
in.AssertEqual(t, out)
|
||
|
}
|
||
|
}
|