mirror of
https://github.com/zitadel/zitadel.git
synced 2024-12-14 20:08:02 +00:00
74 lines
1.1 KiB
Go
74 lines
1.1 KiB
Go
|
package database
|
||
|
|
||
|
import (
|
||
|
"testing"
|
||
|
)
|
||
|
|
||
|
func TestPagination_Write(t *testing.T) {
|
||
|
type fields struct {
|
||
|
Limit uint32
|
||
|
Offset uint32
|
||
|
}
|
||
|
tests := []struct {
|
||
|
name string
|
||
|
fields fields
|
||
|
want wantQuery
|
||
|
}{
|
||
|
{
|
||
|
name: "no values",
|
||
|
fields: fields{
|
||
|
Limit: 0,
|
||
|
Offset: 0,
|
||
|
},
|
||
|
want: wantQuery{
|
||
|
query: "",
|
||
|
args: []any{},
|
||
|
},
|
||
|
},
|
||
|
{
|
||
|
name: "limit",
|
||
|
fields: fields{
|
||
|
Limit: 10,
|
||
|
Offset: 0,
|
||
|
},
|
||
|
want: wantQuery{
|
||
|
query: " LIMIT $1",
|
||
|
args: []any{uint32(10)},
|
||
|
},
|
||
|
},
|
||
|
{
|
||
|
name: "offset",
|
||
|
fields: fields{
|
||
|
Limit: 0,
|
||
|
Offset: 10,
|
||
|
},
|
||
|
want: wantQuery{
|
||
|
query: " OFFSET $1",
|
||
|
args: []any{uint32(10)},
|
||
|
},
|
||
|
},
|
||
|
{
|
||
|
name: "both",
|
||
|
fields: fields{
|
||
|
Limit: 10,
|
||
|
Offset: 10,
|
||
|
},
|
||
|
want: wantQuery{
|
||
|
query: " LIMIT $1 OFFSET $2",
|
||
|
args: []any{uint32(10), uint32(10)},
|
||
|
},
|
||
|
},
|
||
|
}
|
||
|
for _, tt := range tests {
|
||
|
var stmt Statement
|
||
|
t.Run(tt.name, func(t *testing.T) {
|
||
|
p := &Pagination{
|
||
|
Limit: tt.fields.Limit,
|
||
|
Offset: tt.fields.Offset,
|
||
|
}
|
||
|
p.Write(&stmt)
|
||
|
assertQuery(t, &stmt, tt.want)
|
||
|
})
|
||
|
}
|
||
|
}
|