add UT case for package gdb

This commit is contained in:
John Guo
2022-03-31 21:40:28 +08:00
parent 66803fd664
commit 52d8371ba9

View File

@ -24,6 +24,7 @@ import (
"github.com/gogf/gf/v2/os/gtime"
"github.com/gogf/gf/v2/test/gtest"
"github.com/gogf/gf/v2/text/gstr"
"github.com/gogf/gf/v2/util/guid"
"github.com/gogf/gf/v2/util/gutil"
)
@ -688,6 +689,18 @@ func Test_Model_Count(t *testing.T) {
t.AssertNil(err)
t.Assert(count, TableSize)
})
// Count with cache, check internal ctx data feature.
gtest.C(t, func(t *gtest.T) {
for i := 0; i < 10; i++ {
count, err := db.Model(table).Cache(gdb.CacheOption{
Duration: time.Second * 10,
Name: guid.S(),
Force: false,
}).Count()
t.AssertNil(err)
t.Assert(count, TableSize)
}
})
gtest.C(t, func(t *gtest.T) {
count, err := db.Model(table).FieldsEx("id").Where("id>8").Count()
t.AssertNil(err)