Skip to content

Commit e5c980f

Browse files
authored
add test for insert anonymous struct (go-xorm#904)
1 parent fc1b13e commit e5c980f

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

session_insert_test.go

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -741,3 +741,42 @@ func TestInsertMulti4(t *testing.T) {
741741
assert.NoError(t, err)
742742
assert.EqualValues(t, len(users), cnt)
743743
}
744+
745+
func TestAnonymousStruct(t *testing.T) {
746+
type PlainObject struct {
747+
ID uint64 `json:"id,string" xorm:"'ID' pk autoincr"`
748+
Desc string `json:"desc" xorm:"'DESC' notnull"`
749+
}
750+
751+
type PlainFoo struct {
752+
PlainObject `xorm:"extends"` // primary key defined in extends struct
753+
754+
Width uint32 `json:"width" xorm:"'WIDTH' notnull"`
755+
Height uint32 `json:"height" xorm:"'HEIGHT' notnull"`
756+
757+
Ext struct {
758+
F1 uint32 `json:"f1,omitempty"`
759+
F2 uint32 `json:"f2,omitempty"`
760+
} `json:"ext" xorm:"'EXT' json notnull"`
761+
}
762+
763+
assert.NoError(t, prepareEngine())
764+
assertSync(t, new(PlainFoo))
765+
766+
_, err := testEngine.Insert(&PlainFoo{
767+
PlainObject: PlainObject{
768+
Desc: "test",
769+
},
770+
Width: 10,
771+
Height: 20,
772+
773+
Ext: struct {
774+
F1 uint32 `json:"f1,omitempty"`
775+
F2 uint32 `json:"f2,omitempty"`
776+
}{
777+
F1: 11,
778+
F2: 12,
779+
},
780+
})
781+
assert.NoError(t, err)
782+
}

0 commit comments

Comments
 (0)