Skip to content

Commit 96638c1

Browse files
committed
修改测试用例
1 parent 99c5f1c commit 96638c1

File tree

4 files changed

+39
-5
lines changed

4 files changed

+39
-5
lines changed

builder.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ func (b *builder) PageWithCount(page, pageSize int, countColumn string) *builder
4242
return b
4343
}
4444

45-
func (b *builder) Total(countColumn string) *builder {
45+
func (b *builder) Count(countColumn string) *builder {
4646
b.page.countColumn = countColumn
4747
b.page.total = -1
4848
return b

pagehelper.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ package pagehelper
1010

1111
import (
1212
"context"
13+
"fmt"
1314
)
1415

1516
type OrderByInfo struct {
@@ -100,3 +101,7 @@ func (p *PageInfo) GetTotalPage() int64 {
100101

101102
return (p.total + int64(p.PageSize) - 1) / int64(p.PageSize)
102103
}
104+
105+
func (p *PageInfo) String() string {
106+
return fmt.Sprintf("pageNum: %d , pageSize: %d , Total: %d , TotalPage: %d", p.GetPageNum(), p.GetPageSize(), p.GetTotal(), p.GetTotalPage())
107+
}

pagehelper_test.go

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ package pagehelper
1010

1111
import (
1212
"context"
13+
_ "github.com/go-sql-driver/mysql"
1314
"github.com/xfali/gobatis"
1415
"github.com/xfali/gobatis/datasource"
1516
"strings"
@@ -105,8 +106,8 @@ func TestPageHelper2(t *testing.T) {
105106
Host: "localhost",
106107
Port: 3306,
107108
DBName: "test",
108-
Username: "root",
109-
Password: "123",
109+
Username: "test",
110+
Password: "test",
110111
Charset: "utf8",
111112
})))
112113
sessMgr := gobatis.NewSessionManager(pFac)
@@ -117,7 +118,35 @@ func TestPageHelper2(t *testing.T) {
117118
session.SetContext(ctx)
118119

119120
var ret []TestTable
120-
session.Select("SELECT * FROM TBL_TEST").Param().Result(&ret)
121+
session.Select("SELECT * FROM test_table").Param().Result(&ret)
122+
123+
t.Log(ret)
124+
}
125+
126+
func TestPageHelper3(t *testing.T) {
127+
pFac := New(gobatis.NewFactory(
128+
gobatis.SetMaxConn(100),
129+
gobatis.SetMaxIdleConn(50),
130+
gobatis.SetDataSource(&datasource.MysqlDataSource{
131+
Host: "localhost",
132+
Port: 3306,
133+
DBName: "test",
134+
Username: "test",
135+
Password: "test",
136+
Charset: "utf8",
137+
})))
138+
sessMgr := gobatis.NewSessionManager(pFac)
139+
session := sessMgr.NewSession()
140+
ctx, _ := context.WithTimeout(context.Background(), 2*time.Second)
141+
ctx = C(ctx).Page(1, 2).Count("").ASC("id").Build()
142+
143+
session.SetContext(ctx)
144+
145+
var ret []TestTable
146+
session.Select("SELECT * FROM test_table").Param().Result(&ret)
147+
148+
t.Log(ret)
149+
t.Log(GetPageInfo(session.GetContext()))
121150
}
122151

123152
func TestModifyPage(t *testing.T) {

test/builder_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ func TestBuilder2(t *testing.T) {
4141

4242
func TestBuilder3(t *testing.T) {
4343
ctx := pagehelper.C(context.Background()).Page(1, 3).Order("test", pagehelper.ASC).Build()
44-
ctx = pagehelper.C(ctx).DESC("new_field").ASC("new_field2").Total("test").Page(2,100).Build()
44+
ctx = pagehelper.C(ctx).DESC("new_field").ASC("new_field2").Count("test").Page(2,100).Build()
4545
ctx, _ = context.WithTimeout(ctx, time.Second)
4646
p := ctx.Value(pageHelperValue)
4747
o := ctx.Value(orderHelperValue)

0 commit comments

Comments
 (0)