Skip to content

Commit

Permalink
add testing for update via condition bean (go-xorm#918)
Browse files Browse the repository at this point in the history
  • Loading branch information
lunny authored Apr 29, 2018
1 parent 44623fc commit d1e0fe9
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions session_update_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1229,3 +1229,57 @@ func TestUpdateMapContent(t *testing.T) {
assert.EqualValues(t, true, c3.IsMan)
assert.EqualValues(t, 1, c3.Gender)
}

func TestUpdateCondiBean(t *testing.T) {
type NeedUpdateBean struct {
Id int64
Name string
}

type NeedUpdateCondiBean struct {
Name string
}

assert.NoError(t, prepareEngine())
assertSync(t, new(NeedUpdateBean))

cnt, err := testEngine.Insert(&NeedUpdateBean{
Name: "name1",
})
assert.NoError(t, err)
assert.EqualValues(t, 1, cnt)

has, err := testEngine.Exist(&NeedUpdateBean{
Name: "name1",
})
assert.NoError(t, err)
assert.True(t, has)

cnt, err = testEngine.Update(&NeedUpdateBean{
Name: "name2",
}, &NeedUpdateCondiBean{
Name: "name1",
})
assert.NoError(t, err)
assert.EqualValues(t, 1, cnt)

has, err = testEngine.Exist(&NeedUpdateBean{
Name: "name2",
})
assert.NoError(t, err)
assert.True(t, has)

cnt, err = testEngine.Update(&NeedUpdateBean{
Name: "name1",
}, NeedUpdateCondiBean{
Name: "name2",
})
assert.NoError(t, err)
assert.EqualValues(t, 1, cnt)

has, err = testEngine.Exist(&NeedUpdateBean{
Name: "name1",
})
assert.NoError(t, err)
assert.True(t, has)
}

0 comments on commit d1e0fe9

Please sign in to comment.