Skip to content

Commit

Permalink
Merge pull request #2 from Leukocyte-Lab/test/paginator
Browse files Browse the repository at this point in the history
test/paginator
  • Loading branch information
knowlet authored Oct 5, 2021
2 parents 77746ae + a930741 commit 61a0dd7
Show file tree
Hide file tree
Showing 7 changed files with 1,084 additions and 1 deletion.
37 changes: 36 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,44 @@ module github.com/Leukocyte-Lab/gorm-paginator

go 1.17

require gorm.io/gorm v1.21.15
require (
github.com/DATA-DOG/go-sqlmock v1.5.0
github.com/ory/dockertest v3.3.5+incompatible
github.com/stretchr/testify v1.7.0
gorm.io/driver/postgres v1.1.2
gorm.io/gorm v1.21.15
)

require (
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 // indirect
github.com/Microsoft/go-winio v0.5.0 // indirect
github.com/Nvveen/Gotty v0.0.0-20120604004816-cd527374f1e5 // indirect
github.com/cenkalti/backoff v2.2.1+incompatible // indirect
github.com/containerd/continuity v0.2.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/docker/go-connections v0.4.0 // indirect
github.com/docker/go-units v0.4.0 // indirect
github.com/gotestyourself/gotestyourself v2.2.0+incompatible // indirect
github.com/jackc/chunkreader/v2 v2.0.1 // indirect
github.com/jackc/pgconn v1.10.0 // indirect
github.com/jackc/pgio v1.0.0 // indirect
github.com/jackc/pgpassfile v1.0.0 // indirect
github.com/jackc/pgproto3/v2 v2.1.1 // indirect
github.com/jackc/pgservicefile v0.0.0-20200714003250-2b9c44734f2b // indirect
github.com/jackc/pgtype v1.8.1 // indirect
github.com/jackc/pgx/v4 v4.13.0 // indirect
github.com/jinzhu/inflection v1.0.0 // indirect
github.com/jinzhu/now v1.1.2 // indirect
github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/opencontainers/image-spec v1.0.1 // indirect
github.com/opencontainers/runc v1.0.2 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/sirupsen/logrus v1.8.1 // indirect
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519 // indirect
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110 // indirect
golang.org/x/sys v0.0.0-20210616094352-59db8d763f22 // indirect
golang.org/x/text v0.3.7 // indirect
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c // indirect
gotest.tools v2.2.0+incompatible // indirect
)
371 changes: 371 additions & 0 deletions go.sum

Large diffs are not rendered by default.

87 changes: 87 additions & 0 deletions helper_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
package paginator

import (
"reflect"
"testing"
)

func Test_GenPage(t *testing.T) {
type args struct {
pageNo int
pageSize int
}
tests := []struct {
name string
args args
want Page
}{
// test case
{
name: "General",
args: args{
pageNo: 1,
pageSize: 10,
},
want: Page{
Number: 1,
Size: 10,
Total: 0,
},
},
{
name: "Large PageSize",
args: args{
pageNo: 1,
pageSize: 999999,
},
want: Page{
Number: 1,
Size: 100,
Total: 0,
},
},
{
name: "Zero PageSize",
args: args{
pageNo: 1,
pageSize: 0,
},
want: Page{
Number: 1,
Size: 20,
Total: 0,
},
},
{
name: "Nagtive PageSize",
args: args{
pageNo: 1,
pageSize: -1,
},
want: Page{
Number: 1,
Size: 20,
Total: 0,
},
},
{
name: "Nagtive PageNumber",
args: args{
pageNo: -1,
pageSize: 1,
},
want: Page{
Number: 1,
Size: 1,
Total: 0,
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := GenPage(tt.args.pageNo, tt.args.pageSize); !reflect.DeepEqual(got, tt.want) {
t.Errorf("GenPage() = %v, want %v", got, tt.want)
}
})
}
}
Loading

0 comments on commit 61a0dd7

Please sign in to comment.