Skip to content

Commit

Permalink
test: test limit
Browse files Browse the repository at this point in the history
  • Loading branch information
thinkgos committed Nov 21, 2024
1 parent 6c1d4a0 commit 3c3c0a8
Showing 1 changed file with 33 additions and 1 deletion.
34 changes: 33 additions & 1 deletion rapier_paginate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func Test_Paginate(t *testing.T) {
}
})

t.Run("Paginate", func(t *testing.T) {
t.Run("Pagination", func(t *testing.T) {
tests := []struct {
name string
db *gorm.DB
Expand Down Expand Up @@ -90,4 +90,36 @@ func Test_Paginate(t *testing.T) {
})
}
})
t.Run("Limit", func(t *testing.T) {
tests := []struct {
name string
db *gorm.DB
wantVars []any
want string
}{
{
name: "in range",
db: newDb().Model(Dict{}).Scopes(Limit(2, 10)).Find([]Dict{}),
wantVars: []any{10, 10},
want: "SELECT * FROM `dict` LIMIT ? OFFSET ?",
},
{
name: "page < 1",
db: newDb().Model(Dict{}).Scopes(Limit(0, 10)).Find([]Dict{}),
wantVars: []any{10},
want: "SELECT * FROM `dict` LIMIT ?",
},
{
name: "perPage < 1",
db: newDb().Model(Dict{}).Scopes(Limit(1, 0)).Find([]Dict{}),
wantVars: nil,
want: "SELECT * FROM `dict`",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
ReviewBuildDb(t, tt.db, tt.want, tt.wantVars)
})
}
})
}

0 comments on commit 3c3c0a8

Please sign in to comment.