Commit 09d4b801 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 6b2d1781
...@@ -123,60 +123,86 @@ func TestLoad(t *testing.T) { ...@@ -123,60 +123,86 @@ func TestLoad(t *testing.T) {
// iterate tidMin..tidMax and expect db entries in expectv // iterate tidMin..tidMax and expect db entries in expectv
func testIterate(t *testing.T, fs *FileStorage, tidMin, tidMax zodb.Tid, expectv []dbEntry) { func testIterate(t *testing.T, fs *FileStorage, tidMin, tidMax zodb.Tid, expectv []dbEntry) {
iter := fs.Iterate(tidMin, tidMax) iter := fs.Iterate(tidMin, tidMax)
fsi := iter.(*iterator)
for k := 0; ; k++ { for k := 0; ; k++ {
subj := fmt.Sprintf("iterating %v..%v: step %v/%v", tidMin, tidMax, k+1, len(expectv)) txnErrorf := func(format string, a ...interface{}) {
subj := fmt.Sprintf("iterating %v..%v: step %v/%v:", tidMin, tidMax, k+1, len(expectv))
msg := fmt.Sprintf(format, a...)
t.Errorf("%v: %v", subj, msg)
}
txni, dataIter, err := iter.NextTxn() txni, dataIter, err := iter.NextTxn()
if err != nil { if err != nil {
if err == io.EOF { if err == io.EOF {
if k != len(expectv) { if k != len(expectv) {
t.Errorf("%v: steps underrun", subj) txnErrorf("steps underrun")
} }
break break
} }
t.Errorf("%v: %v", subj, err) txnErrorf("%v", err)
} }
if k >= len(expectv) { if k >= len(expectv) {
t.Errorf("%v: steps overrun", subj) txnErrorf("steps overrun")
} }
dbe := expectv[k] dbe := expectv[k]
// TODO also check .Pos, .LenPrev, .Len in iter.txnIter.* // assert txni points to where we expect - this will allow us
if !reflect.DeepEqual(*txni, dbe.Header.TxnInfo) { // not only to check .TxnInfo but also .Pos, .LenPrev, .Len etc in
t.Errorf("%v: unexpected txn entry:\nhave: %q\nwant: %q", subj, *txni, dbe.Header.TxnInfo) // whole expected TxnHeader
if txni != &fsi.txnIter.Txnh.TxnInfo {
t.Fatal("unexpected txni pointer")
}
if !reflect.DeepEqual(fsi.txnIter.Txnh, dbe.Header) {
txnErrorf("unexpected txn entry:\nhave: %q\nwant: %q", fsi.txnIter.Txnh, dbe.Header)
} }
ndata := len(dbe.Entryv)
for kdata := 0; ; kdata++ { for kdata := 0; ; kdata++ {
dsubj := fmt.Sprintf("%v: dstep %v/%v", subj, kdata, ndata) dataErrorf := func(format string, a...interface{}) {
dsubj := fmt.Sprintf("dstep %v/%v", kdata, len(dbe.Entryv))
msg := fmt.Sprintf(format, a...)
txnErrorf("%v: %v", dsubj, msg)
}
datai, err := dataIter.NextData() datai, err := dataIter.NextData()
if err != nil { if err != nil {
if err == io.EOF { if err == io.EOF {
if kdata != ndata { if kdata != len(dbe.Entryv) {
t.Errorf("%v: data steps underrun", dsubj) dataErrorf("dsteps underrun")
} }
break break
} }
t.Errorf("%v: %v", dsubj, err) dataErrorf("%v", err)
} }
if kdata > ndata { if kdata > len(dbe.Entryv) {
t.Errorf("%v: dsteps overrun", dsubj) dataErrorf("dsteps overrun")
} }
txe := dbe.Entryv[kdata] txe := dbe.Entryv[kdata]
dh := txe.Header
// assert datai pointes to where we expect - this will allow us
// not only to check oid/tid/data but also to check whole data header.
if datai != &fsi.dataIter.sri {
t.Fatal("unexpected datai pointer")
}
if !reflect.DeepEqual(fsi.dataIter.Datah, dh) {
dataErrorf("unexpected data entry:\nhave: %q\nwant: %q", fsi.dataIter.Datah, dh)
}
// XXX -> func // check what was actually returned - since it is not in ^^^ data structure
if datai.Oid != txe.Header.Oid { if datai.Oid != dh.Oid {
t.Errorf("%v: oid mismatch ...", dsubj) // XXX dataErrorf("oid mismatch: have %v; want %v", datai.Oid, dh.Oid)
} }
if datai.Tid != txe.Header.Tid { if datai.Tid != dh.Tid {
t.Errorf("%v: tid mismatch ...", dsubj) // XXX dataErrorf("tid mismatch: have %v; want %v", datai.Tid, dh.Tid)
} }
if !bytes.Equal(datai.Data, txe.Data()) { if !bytes.Equal(datai.Data, txe.Data()) {
t.Errorf("%v: data mismatch ...", dsubj) // XXX dataErrorf("data mismatch:\nhave %q\nwant %q", datai.Data, txe.Data())
} }
// TODO .DataTid // TODO .DataTid
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment