Add more tests for FindAndCount (#1621)

Add more tests for FindAndCount

Reviewed-on: https://gitea.com/xorm/xorm/pulls/1621
This commit is contained in:
Lunny Xiao 2020-03-24 02:19:56 +00:00
parent 5053c35701
commit 9dca7f0703
1 changed files with 64 additions and 0 deletions

View File

@ -553,6 +553,70 @@ func TestFindAndCountOneFuncWithDeleted(t *testing.T) {
assert.EqualValues(t, 0, cnt) assert.EqualValues(t, 0, cnt)
} }
func TestFindAndCount2(t *testing.T) {
// User
type TestFindAndCountUser struct {
Id int64 `xorm:"bigint(11) pk autoincr"`
Name string `xorm:"'name'"`
}
// Hotel
type TestFindAndCountHotel struct {
Id int64 `xorm:"bigint(11) pk autoincr"`
Name string `xorm:"'name'"`
Code string `xorm:"'code'"`
Region string `xorm:"'region'"`
CreateBy *TestFindAndCountUser `xorm:"'create_by'"`
}
assert.NoError(t, prepareEngine())
assertSync(t, new(TestFindAndCountUser), new(TestFindAndCountHotel))
var u = TestFindAndCountUser{
Name: "myname",
}
cnt, err := testEngine.Insert(&u)
assert.NoError(t, err)
assert.EqualValues(t, 1, cnt)
var hotel = TestFindAndCountHotel{
Name: "myhotel",
Code: "111",
Region: "222",
CreateBy: &u,
}
cnt, err = testEngine.Insert(&hotel)
assert.NoError(t, err)
assert.EqualValues(t, 1, cnt)
hotels := make([]*TestFindAndCountHotel, 0)
cnt, err = testEngine.
Alias("t").
Limit(10, 0).
FindAndCount(&hotels)
assert.NoError(t, err)
assert.EqualValues(t, 1, cnt)
hotels = make([]*TestFindAndCountHotel, 0)
cnt, err = testEngine.
Table(new(TestFindAndCountHotel)).
Alias("t").
Limit(10, 0).
FindAndCount(&hotels)
assert.NoError(t, err)
assert.EqualValues(t, 1, cnt)
hotels = make([]*TestFindAndCountHotel, 0)
cnt, err = testEngine.
Table(new(TestFindAndCountHotel)).
Alias("t").
Where("t.region like '6501%'").
Limit(10, 0).
FindAndCount(&hotels)
assert.NoError(t, err)
assert.EqualValues(t, 0, cnt)
}
type FindMapDevice struct { type FindMapDevice struct {
Deviceid string `xorm:"pk"` Deviceid string `xorm:"pk"`
Status int Status int