Skip to content

Commit 3684fc6

Browse files
committed
is: Add page limit test to search requests
1 parent 341fd9a commit 3684fc6

File tree

1 file changed

+128
-42
lines changed

1 file changed

+128
-42
lines changed

pkg/identityserver/storetest/entity_search.go

Lines changed: 128 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -630,30 +630,34 @@ func (st *StoreTest) TestEntitySearch(t *T) {
630630
}
631631

632632
func (st *StoreTest) TestEntitySearchPagination(t *T) {
633+
store.SetPaginationDefaults(store.PaginationDefaults{
634+
DefaultLimit: 7,
635+
})
636+
633637
var users []*ttnpb.User
634-
for i := 0; i < 7; i++ {
638+
for i := 0; i < 15; i++ {
635639
users = append(users, st.population.NewUser())
636640
}
637641

638642
var applications []*ttnpb.Application
639-
for i := 0; i < 7; i++ {
643+
for i := 0; i < 15; i++ {
640644
applications = append(applications, st.population.NewApplication(users[0].GetOrganizationOrUserIdentifiers()))
641645
}
642646
var clients []*ttnpb.Client
643-
for i := 0; i < 7; i++ {
647+
for i := 0; i < 15; i++ {
644648
clients = append(clients, st.population.NewClient(users[0].GetOrganizationOrUserIdentifiers()))
645649
}
646650
var gateways []*ttnpb.Gateway
647-
for i := 0; i < 7; i++ {
651+
for i := 0; i < 15; i++ {
648652
gateways = append(gateways, st.population.NewGateway(users[0].GetOrganizationOrUserIdentifiers()))
649653
}
650654
var organizations []*ttnpb.Organization
651-
for i := 0; i < 7; i++ {
655+
for i := 0; i < 15; i++ {
652656
organizations = append(organizations, st.population.NewOrganization(users[0].GetOrganizationOrUserIdentifiers()))
653657
}
654658

655659
var endDevices []*ttnpb.EndDevice
656-
for i := 0; i < 7; i++ {
660+
for i := 0; i < 15; i++ {
657661
endDevices = append(endDevices, st.population.NewEndDevice(applications[0].GetIds()))
658662
}
659663

@@ -676,17 +680,30 @@ func (st *StoreTest) TestEntitySearchPagination(t *T) {
676680

677681
got, err := s.SearchApplications(paginateCtx, nil, &ttnpb.SearchApplicationsRequest{})
678682
if a.So(err, should.BeNil) && a.So(got, should.NotBeNil) {
679-
if page == 4 {
680-
a.So(got, should.HaveLength, 1)
681-
} else {
682-
a.So(got, should.HaveLength, 2)
683-
}
683+
a.So(got, should.HaveLength, 2)
684684
for i, e := range got {
685685
a.So(e, should.Resemble, applications[i+2*int(page-1)].Ids)
686686
}
687687
}
688688

689-
a.So(total, should.Equal, 7)
689+
a.So(total, should.Equal, 15)
690+
}
691+
})
692+
693+
t.Run("Applications_PageLimit", func(t *T) {
694+
a, ctx := test.New(t)
695+
696+
var total uint64
697+
paginateCtx := store.WithPagination(ctx, 0, 0, &total)
698+
got, err := s.SearchApplications(paginateCtx, nil, &ttnpb.SearchApplicationsRequest{})
699+
if a.So(err, should.BeNil) && a.So(got, should.NotBeNil) {
700+
a.So(got, should.HaveLength, 7)
701+
}
702+
703+
paginateCtx = store.WithPagination(ctx, 0, 2, &total)
704+
got, err = s.SearchApplications(paginateCtx, nil, &ttnpb.SearchApplicationsRequest{})
705+
if a.So(err, should.BeNil) && a.So(got, should.NotBeNil) {
706+
a.So(got, should.HaveLength, 7)
690707
}
691708
})
692709

@@ -699,17 +716,30 @@ func (st *StoreTest) TestEntitySearchPagination(t *T) {
699716

700717
got, err := s.SearchClients(paginateCtx, nil, &ttnpb.SearchClientsRequest{})
701718
if a.So(err, should.BeNil) && a.So(got, should.NotBeNil) {
702-
if page == 4 {
703-
a.So(got, should.HaveLength, 1)
704-
} else {
705-
a.So(got, should.HaveLength, 2)
706-
}
719+
a.So(got, should.HaveLength, 2)
707720
for i, e := range got {
708721
a.So(e, should.Resemble, clients[i+2*int(page-1)].Ids)
709722
}
710723
}
711724

712-
a.So(total, should.Equal, 7)
725+
a.So(total, should.Equal, 15)
726+
}
727+
})
728+
729+
t.Run("Clients_PageLimit", func(t *T) {
730+
a, ctx := test.New(t)
731+
732+
var total uint64
733+
paginateCtx := store.WithPagination(ctx, 0, 0, &total)
734+
got, err := s.SearchClients(paginateCtx, nil, &ttnpb.SearchClientsRequest{})
735+
if a.So(err, should.BeNil) && a.So(got, should.NotBeNil) {
736+
a.So(got, should.HaveLength, 7)
737+
}
738+
739+
paginateCtx = store.WithPagination(ctx, 0, 2, &total)
740+
got, err = s.SearchClients(paginateCtx, nil, &ttnpb.SearchClientsRequest{})
741+
if a.So(err, should.BeNil) && a.So(got, should.NotBeNil) {
742+
a.So(got, should.HaveLength, 7)
713743
}
714744
})
715745

@@ -724,17 +754,34 @@ func (st *StoreTest) TestEntitySearchPagination(t *T) {
724754
ApplicationIds: applications[0].GetIds(),
725755
})
726756
if a.So(err, should.BeNil) && a.So(got, should.NotBeNil) {
727-
if page == 4 {
728-
a.So(got, should.HaveLength, 1)
729-
} else {
730-
a.So(got, should.HaveLength, 2)
731-
}
757+
a.So(got, should.HaveLength, 2)
732758
for i, e := range got {
733759
a.So(e, should.Resemble, endDevices[i+2*int(page-1)].Ids)
734760
}
735761
}
736762

737-
a.So(total, should.Equal, 7)
763+
a.So(total, should.Equal, 15)
764+
}
765+
})
766+
767+
t.Run("EndDevices_PageLimit", func(t *T) {
768+
a, ctx := test.New(t)
769+
770+
var total uint64
771+
paginateCtx := store.WithPagination(ctx, 0, 0, &total)
772+
got, err := s.SearchEndDevices(paginateCtx, &ttnpb.SearchEndDevicesRequest{
773+
ApplicationIds: applications[0].GetIds(),
774+
})
775+
if a.So(err, should.BeNil) && a.So(got, should.NotBeNil) {
776+
a.So(got, should.HaveLength, 7)
777+
}
778+
779+
paginateCtx = store.WithPagination(ctx, 0, 2, &total)
780+
got, err = s.SearchEndDevices(paginateCtx, &ttnpb.SearchEndDevicesRequest{
781+
ApplicationIds: applications[0].GetIds(),
782+
})
783+
if a.So(err, should.BeNil) && a.So(got, should.NotBeNil) {
784+
a.So(got, should.HaveLength, 7)
738785
}
739786
})
740787

@@ -747,17 +794,30 @@ func (st *StoreTest) TestEntitySearchPagination(t *T) {
747794

748795
got, err := s.SearchGateways(paginateCtx, nil, &ttnpb.SearchGatewaysRequest{})
749796
if a.So(err, should.BeNil) && a.So(got, should.NotBeNil) {
750-
if page == 4 {
751-
a.So(got, should.HaveLength, 1)
752-
} else {
753-
a.So(got, should.HaveLength, 2)
754-
}
797+
a.So(got, should.HaveLength, 2)
755798
for i, e := range got {
756799
a.So(e, should.Resemble, gateways[i+2*int(page-1)].Ids)
757800
}
758801
}
759802

760-
a.So(total, should.Equal, 7)
803+
a.So(total, should.Equal, 15)
804+
}
805+
})
806+
807+
t.Run("Gateways_PageLimit", func(t *T) {
808+
a, ctx := test.New(t)
809+
810+
var total uint64
811+
paginateCtx := store.WithPagination(ctx, 0, 0, &total)
812+
got, err := s.SearchGateways(paginateCtx, nil, &ttnpb.SearchGatewaysRequest{})
813+
if a.So(err, should.BeNil) && a.So(got, should.NotBeNil) {
814+
a.So(got, should.HaveLength, 7)
815+
}
816+
817+
paginateCtx = store.WithPagination(ctx, 0, 2, &total)
818+
got, err = s.SearchGateways(paginateCtx, nil, &ttnpb.SearchGatewaysRequest{})
819+
if a.So(err, should.BeNil) && a.So(got, should.NotBeNil) {
820+
a.So(got, should.HaveLength, 7)
761821
}
762822
})
763823

@@ -770,17 +830,30 @@ func (st *StoreTest) TestEntitySearchPagination(t *T) {
770830

771831
got, err := s.SearchOrganizations(paginateCtx, nil, &ttnpb.SearchOrganizationsRequest{})
772832
if a.So(err, should.BeNil) && a.So(got, should.NotBeNil) {
773-
if page == 4 {
774-
a.So(got, should.HaveLength, 1)
775-
} else {
776-
a.So(got, should.HaveLength, 2)
777-
}
833+
a.So(got, should.HaveLength, 2)
778834
for i, e := range got {
779835
a.So(e, should.Resemble, organizations[i+2*int(page-1)].Ids)
780836
}
781837
}
782838

783-
a.So(total, should.Equal, 7)
839+
a.So(total, should.Equal, 15)
840+
}
841+
})
842+
843+
t.Run("Organizations_PageLimit", func(t *T) {
844+
a, ctx := test.New(t)
845+
846+
var total uint64
847+
paginateCtx := store.WithPagination(ctx, 0, 0, &total)
848+
got, err := s.SearchOrganizations(paginateCtx, nil, &ttnpb.SearchOrganizationsRequest{})
849+
if a.So(err, should.BeNil) && a.So(got, should.NotBeNil) {
850+
a.So(got, should.HaveLength, 7)
851+
}
852+
853+
paginateCtx = store.WithPagination(ctx, 0, 2, &total)
854+
got, err = s.SearchOrganizations(paginateCtx, nil, &ttnpb.SearchOrganizationsRequest{})
855+
if a.So(err, should.BeNil) && a.So(got, should.NotBeNil) {
856+
a.So(got, should.HaveLength, 7)
784857
}
785858
})
786859

@@ -793,17 +866,30 @@ func (st *StoreTest) TestEntitySearchPagination(t *T) {
793866

794867
got, err := s.SearchUsers(paginateCtx, &ttnpb.SearchUsersRequest{})
795868
if a.So(err, should.BeNil) && a.So(got, should.NotBeNil) {
796-
if page == 4 {
797-
a.So(got, should.HaveLength, 1)
798-
} else {
799-
a.So(got, should.HaveLength, 2)
800-
}
869+
a.So(got, should.HaveLength, 2)
801870
for i, e := range got {
802871
a.So(e, should.Resemble, users[i+2*int(page-1)].Ids)
803872
}
804873
}
805874

806-
a.So(total, should.Equal, 7)
875+
a.So(total, should.Equal, 15)
876+
}
877+
})
878+
879+
t.Run("Users_PageLimit", func(t *T) {
880+
a, ctx := test.New(t)
881+
882+
var total uint64
883+
paginateCtx := store.WithPagination(ctx, 0, 0, &total)
884+
got, err := s.SearchUsers(paginateCtx, &ttnpb.SearchUsersRequest{})
885+
if a.So(err, should.BeNil) && a.So(got, should.NotBeNil) {
886+
a.So(got, should.HaveLength, 7)
887+
}
888+
889+
paginateCtx = store.WithPagination(ctx, 0, 2, &total)
890+
got, err = s.SearchUsers(paginateCtx, &ttnpb.SearchUsersRequest{})
891+
if a.So(err, should.BeNil) && a.So(got, should.NotBeNil) {
892+
a.So(got, should.HaveLength, 7)
807893
}
808894
})
809895
}

0 commit comments

Comments
 (0)