Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
neoppod
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
1
Issues
1
List
Boards
Labels
Milestones
Merge Requests
2
Merge Requests
2
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nexedi
neoppod
Commits
1f4f1e99
Commit
1f4f1e99
authored
Feb 20, 2019
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
go/zodb: persistent tests: Factor checkObj out of TestPersistent
We are going to use this function in other tests too.
parent
8b93cb5e
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
50 additions
and
38 deletions
+50
-38
go/zodb/persistent_test.go
go/zodb/persistent_test.go
+50
-38
No files found.
go/zodb/persistent_test.go
View file @
1f4f1e99
...
@@ -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
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment