Commit 1f4f1e99 authored by Kirill Smelkov's avatar Kirill Smelkov

go/zodb: persistent tests: Factor checkObj out of TestPersistent

We are going to use this function in other tests too.
parent 8b93cb5e
...@@ -66,47 +66,59 @@ func init() { ...@@ -66,47 +66,59 @@ func init() {
RegisterClassAlias("t.zodb.MyOldObject", "t.zodb.MyObject") RegisterClassAlias("t.zodb.MyOldObject", "t.zodb.MyObject")
} }
func TestPersistent(t *testing.T) { // checkObj verifies current state of persistent object.
assert := require.New(t) //
// one can bind checkObj to t via tCheckObj.
func checkObj(t testing.TB, obj IPersistent, jar *Connection, oid Oid, serial Tid, state ObjectState, refcnt int32) {
t.Helper()
xbase := reflect.ValueOf(obj).Elem().FieldByName("Persistent")
pbase := xbase.Addr().Interface().(*Persistent)
// checkObj verifies current state of persistent object. badf := func(format string, argv ...interface{}) {
checkObj := func(obj IPersistent, jar *Connection, oid Oid, serial Tid, state ObjectState, refcnt int32) {
t.Helper() t.Helper()
xbase := reflect.ValueOf(obj).Elem().FieldByName("Persistent") msg := fmt.Sprintf(format, argv...)
pbase := xbase.Addr().Interface().(*Persistent) t.Fatalf("%#v: %s", obj, msg)
}
badf := func(format string, argv ...interface{}) {
t.Helper() zc := pbase.zclass
msg := fmt.Sprintf(format, argv...) //zc.class
t.Fatalf("%#v: %s", obj, msg) if typ := reflect.TypeOf(obj).Elem(); typ != zc.typ {
} badf("invalid zclass: .typ = %s ; want %s", zc.typ, typ)
}
zc := pbase.zclass //zc.stateType
//zc.class
if typ := reflect.TypeOf(obj).Elem(); typ != zc.typ { if pbase.jar != jar {
badf("invalid zclass: .typ = %s ; want %s", zc.typ, typ) badf("invalid jar")
} }
//zc.stateType if pbase.oid != oid {
badf("invalid oid: %s ; want %s", pbase.oid, oid)
if pbase.jar != jar { }
badf("invalid jar") if pbase.serial != serial {
} badf("invalid serial: %s ; want %s", pbase.serial, serial)
if pbase.oid != oid { }
badf("invalid oid: %s ; want %s", pbase.oid, oid) if pbase.state != state {
} badf("invalid state: %s ; want %s", pbase.state, state)
if pbase.serial != serial { }
badf("invalid serial: %s ; want %s", pbase.serial, serial) if pbase.refcnt != refcnt {
} badf("invalid refcnt: %s ; want %s", pbase.refcnt, refcnt)
if pbase.state != state {
badf("invalid state: %s ; want %s", pbase.state, state)
}
if pbase.refcnt != refcnt {
badf("invalid refcnt: %s ; want %s", pbase.refcnt, refcnt)
}
if pbase.instance != obj {
badf("base.instance != obj")
}
} }
if pbase.instance != obj {
badf("base.instance != obj")
}
}
// tCheckObj binds checkObj to t.
func tCheckObj(t testing.TB) func(IPersistent, *Connection, Oid, Tid, ObjectState, int32) {
return func(obj IPersistent, jar *Connection, oid Oid, serial Tid, state ObjectState, refcnt int32) {
t.Helper()
checkObj(t, obj, jar, oid, serial, state, refcnt)
}
}
func TestPersistent(t *testing.T) {
assert := require.New(t)
checkObj := tCheckObj(t)
// unknown type -> Broken // unknown type -> Broken
xobj := newGhost("t.unknown", 10, nil) xobj := newGhost("t.unknown", 10, nil)
......
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