From a9307417e1b0a05152ef606e5628e2ca80a71b70 Mon Sep 17 00:00:00 2001 From: "Jerry Y. Chen" Date: Mon, 4 Oct 2021 18:19:10 +0800 Subject: [PATCH] test: add filter test case to integration test --- paginator_test.go | 29 +++++++++++++++++++++++++++++ seed_test.go | 15 ++++++++++----- 2 files changed, 39 insertions(+), 5 deletions(-) diff --git a/paginator_test.go b/paginator_test.go index 2596899..b1a8dda 100644 --- a/paginator_test.go +++ b/paginator_test.go @@ -356,6 +356,35 @@ func TestPaginator_Paginator(t *testing.T) { }, wantErr: false, }, + { + name: "Filter Page 2", + fields: fields{ + Page: Page{ + Number: 2, + Size: 2, + }, + Filter: map[string]string{ + "active": "true", + }, + }, + args: args{ + dest: []*tests.User{}, + }, + wantPage: Page{ + Number: 2, + Size: 2, + Total: 2, + }, + wantDest: []*tests.User{ + { + Name: "John", + }, + { + Name: "Julia", + }, + }, + wantErr: false, + }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { diff --git a/seed_test.go b/seed_test.go index 62e3012..87810d3 100644 --- a/seed_test.go +++ b/seed_test.go @@ -4,18 +4,23 @@ import "gorm.io/gorm/utils/tests" var mockUsers = []tests.User{ { - Name: "Jane", + Name: "Jane", + Active: false, }, { - Name: "Jack", + Name: "Jack", + Active: true, }, { - Name: "Jill", + Name: "Jill", + Active: true, }, { - Name: "John", + Name: "John", + Active: true, }, { - Name: "Julia", + Name: "Julia", + Active: true, }, }