Skip to content
This repository has been archived by the owner on Sep 7, 2021. It is now read-only.
This repository is currently being migrated. It's locked while the migration is in progress.

Add insert multi omit tests #1439

Merged
merged 1 commit into from
Sep 27, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions session_insert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -957,3 +957,46 @@ func TestMultipleInsertTableName(t *testing.T) {

assert.NoError(t, trans.Commit())
}

func TestInsertMultiWithOmit(t *testing.T) {
assert.NoError(t, prepareEngine())

type TestMultiOmit struct {
Id int64 `xorm:"int(11) pk"`
Name string `xorm:"varchar(255)"`
Omitted string `xorm:"varchar(255) 'omitted'"`
}

assert.NoError(t, testEngine.Sync2(new(TestMultiOmit)))

l := []interface{}{
TestMultiOmit{Id: 1, Name: "1", Omitted: "1"},
TestMultiOmit{Id: 2, Name: "1", Omitted: "2"},
TestMultiOmit{Id: 3, Name: "1", Omitted: "3"},
}

check := func() {
var ls []TestMultiOmit
err := testEngine.Find(&ls)
assert.NoError(t, err)
assert.EqualValues(t, 3, len(ls))

for e := range ls {
assert.EqualValues(t, "", ls[e].Omitted)
}
}

num, err := testEngine.Omit("omitted").Insert(l...)
assert.NoError(t, err)
assert.EqualValues(t, 3, num)
check()

num, err = testEngine.Delete(TestMultiOmit{Name: "1"})
assert.NoError(t, err)
assert.EqualValues(t, 3, num)

num, err = testEngine.Omit("omitted").Insert(l)
assert.NoError(t, err)
assert.EqualValues(t, 3, num)
check()
}