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:
parent
5053c35701
commit
9dca7f0703
|
@ -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
|
||||||
|
|
Loading…
Reference in New Issue