Skip to content

Commit

Permalink
add test for update map (go-xorm#883)
Browse files Browse the repository at this point in the history
  • Loading branch information
lunny authored Apr 11, 2018
1 parent 6542364 commit 3ef987a
Showing 1 changed file with 50 additions and 1 deletion.
51 changes: 50 additions & 1 deletion session_update_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -892,7 +892,6 @@ func TestUpdateSameMapper(t *testing.T) {
}

{

col1 := &UpdateIncr{}
err = testEngine.Sync(col1)
if err != nil {
Expand Down Expand Up @@ -1164,3 +1163,53 @@ func TestUpdateMapCondition(t *testing.T) {
assert.True(t, has)
assert.EqualValues(t, "string1", c2.String)
}

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

type UpdateMapContent struct {
Id int64
Name string
IsMan bool
Age int
Gender int // 1 is man, 2 is woman
}

assertSync(t, new(UpdateMapContent))

var c = UpdateMapContent{
Name: "lunny",
IsMan: true,
Gender: 1,
Age: 18,
}
_, err := testEngine.Insert(&c)
assert.NoError(t, err)
assert.EqualValues(t, 18, c.Age)

cnt, err := testEngine.Table(new(UpdateMapContent)).ID(c.Id).Update(map[string]interface{}{"age": 0})
assert.NoError(t, err)
assert.EqualValues(t, 1, cnt)

var c1 UpdateMapContent
has, err := testEngine.ID(c.Id).Get(&c1)
assert.NoError(t, err)
assert.True(t, has)
assert.EqualValues(t, 0, c1.Age)

cnt, err = testEngine.Table(new(UpdateMapContent)).ID(c.Id).Update(map[string]interface{}{
"age": 16,
"is_man": false,
"gender": 2,
})
assert.NoError(t, err)
assert.EqualValues(t, 1, cnt)

var c2 UpdateMapContent
has, err = testEngine.ID(c.Id).Get(&c2)
assert.NoError(t, err)
assert.True(t, has)
assert.EqualValues(t, 16, c2.Age)
assert.EqualValues(t, false, c2.IsMan)
assert.EqualValues(t, 2, c2.Gender)
}

0 comments on commit 3ef987a

Please sign in to comment.