add test for insert anonymous struct (#904)

This commit is contained in:
Lunny Xiao 2018-04-19 08:25:31 +08:00 committed by GitHub
parent fc1b13e0d8
commit e5c980f7b6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 39 additions and 0 deletions

View File

@ -741,3 +741,42 @@ func TestInsertMulti4(t *testing.T) {
assert.NoError(t, err) assert.NoError(t, err)
assert.EqualValues(t, len(users), cnt) assert.EqualValues(t, len(users), cnt)
} }
func TestAnonymousStruct(t *testing.T) {
type PlainObject struct {
ID uint64 `json:"id,string" xorm:"'ID' pk autoincr"`
Desc string `json:"desc" xorm:"'DESC' notnull"`
}
type PlainFoo struct {
PlainObject `xorm:"extends"` // primary key defined in extends struct
Width uint32 `json:"width" xorm:"'WIDTH' notnull"`
Height uint32 `json:"height" xorm:"'HEIGHT' notnull"`
Ext struct {
F1 uint32 `json:"f1,omitempty"`
F2 uint32 `json:"f2,omitempty"`
} `json:"ext" xorm:"'EXT' json notnull"`
}
assert.NoError(t, prepareEngine())
assertSync(t, new(PlainFoo))
_, err := testEngine.Insert(&PlainFoo{
PlainObject: PlainObject{
Desc: "test",
},
Width: 10,
Height: 20,
Ext: struct {
F1 uint32 `json:"f1,omitempty"`
F2 uint32 `json:"f2,omitempty"`
}{
F1: 11,
F2: 12,
},
})
assert.NoError(t, err)
}