add TestInsertMulti2Interface testcase

testcase for session.insert with `[]interface{}{struct, ...}` and `[]interface{}{*sturct, ...}`
This commit is contained in:
joelBai 2020-01-06 02:43:17 +00:00
parent c349d36e95
commit 4eab4b6751
1 changed files with 30 additions and 0 deletions

View File

@ -564,6 +564,36 @@ func TestInsertMulti2(t *testing.T) {
assert.EqualValues(t, len(users2), cnt) assert.EqualValues(t, len(users2), cnt)
} }
func TestInsertMulti2Interface(t *testing.T) {
assert.NoError(t, prepareEngine())
assertSync(t, new(Userinfo))
users := []interface{}{
Userinfo{Username: "xlw", Departname: "dev", Alias: "lunny2", Created: time.Now()},
Userinfo{Username: "xlw2", Departname: "dev", Alias: "lunny3", Created: time.Now()},
Userinfo{Username: "xlw11", Departname: "dev", Alias: "lunny2", Created: time.Now()},
Userinfo{Username: "xlw22", Departname: "dev", Alias: "lunny3", Created: time.Now()},
}
cnt, err := testEngine.Insert(&users)
if err != nil {
t.Error(err)
panic(err)
}
assert.EqualValues(t, len(users), cnt)
users2 := []interface{}{
&Userinfo{Username: "1xlw", Departname: "dev", Alias: "lunny2", Created: time.Now()},
&Userinfo{Username: "1xlw2", Departname: "dev", Alias: "lunny3", Created: time.Now()},
&Userinfo{Username: "1xlw11", Departname: "dev", Alias: "lunny2", Created: time.Now()},
&Userinfo{Username: "1xlw22", Departname: "dev", Alias: "lunny3", Created: time.Now()},
}
cnt, err = testEngine.Insert(&users2)
assert.NoError(t, err)
assert.EqualValues(t, len(users2), cnt)
}
func TestInsertTwoTable(t *testing.T) { func TestInsertTwoTable(t *testing.T) {
assert.NoError(t, prepareEngine()) assert.NoError(t, prepareEngine())