diff --git a/pkg/identityserver/storetest/entity_search.go b/pkg/identityserver/storetest/entity_search.go index e44501a30ed..8197c59719b 100644 --- a/pkg/identityserver/storetest/entity_search.go +++ b/pkg/identityserver/storetest/entity_search.go @@ -630,6 +630,10 @@ func (st *StoreTest) TestEntitySearch(t *T) { } func (st *StoreTest) TestEntitySearchPagination(t *T) { + store.SetPaginationDefaults(store.PaginationDefaults{ + DefaultLimit: 3, + }) + var users []*ttnpb.User for i := 0; i < 7; i++ { users = append(users, st.population.NewUser()) @@ -690,6 +694,23 @@ func (st *StoreTest) TestEntitySearchPagination(t *T) { } }) + t.Run("Applications_PageLimit", func(t *T) { + a, ctx := test.New(t) + + var total uint64 + paginateCtx := store.WithPagination(ctx, 0, 0, &total) + got, err := s.SearchApplications(paginateCtx, nil, &ttnpb.SearchApplicationsRequest{}) + if a.So(err, should.BeNil) && a.So(got, should.NotBeNil) { + a.So(got, should.HaveLength, 3) + } + + paginateCtx = store.WithPagination(ctx, 0, 2, &total) + got, err = s.SearchApplications(paginateCtx, nil, &ttnpb.SearchApplicationsRequest{}) + if a.So(err, should.BeNil) && a.So(got, should.NotBeNil) { + a.So(got, should.HaveLength, 3) + } + }) + t.Run("Clients_Paginated", func(t *T) { a, ctx := test.New(t) @@ -713,6 +734,23 @@ func (st *StoreTest) TestEntitySearchPagination(t *T) { } }) + t.Run("Clients_PageLimit", func(t *T) { + a, ctx := test.New(t) + + var total uint64 + paginateCtx := store.WithPagination(ctx, 0, 0, &total) + got, err := s.SearchClients(paginateCtx, nil, &ttnpb.SearchClientsRequest{}) + if a.So(err, should.BeNil) && a.So(got, should.NotBeNil) { + a.So(got, should.HaveLength, 3) + } + + paginateCtx = store.WithPagination(ctx, 0, 2, &total) + got, err = s.SearchClients(paginateCtx, nil, &ttnpb.SearchClientsRequest{}) + if a.So(err, should.BeNil) && a.So(got, should.NotBeNil) { + a.So(got, should.HaveLength, 3) + } + }) + t.Run("EndDevices_Paginated", func(t *T) { a, ctx := test.New(t) @@ -738,6 +776,27 @@ func (st *StoreTest) TestEntitySearchPagination(t *T) { } }) + t.Run("EndDevices_PageLimit", func(t *T) { + a, ctx := test.New(t) + + var total uint64 + paginateCtx := store.WithPagination(ctx, 0, 0, &total) + got, err := s.SearchEndDevices(paginateCtx, &ttnpb.SearchEndDevicesRequest{ + ApplicationIds: applications[0].GetIds(), + }) + if a.So(err, should.BeNil) && a.So(got, should.NotBeNil) { + a.So(got, should.HaveLength, 3) + } + + paginateCtx = store.WithPagination(ctx, 0, 2, &total) + got, err = s.SearchEndDevices(paginateCtx, &ttnpb.SearchEndDevicesRequest{ + ApplicationIds: applications[0].GetIds(), + }) + if a.So(err, should.BeNil) && a.So(got, should.NotBeNil) { + a.So(got, should.HaveLength, 3) + } + }) + t.Run("Gateways_Paginated", func(t *T) { a, ctx := test.New(t) @@ -761,6 +820,23 @@ func (st *StoreTest) TestEntitySearchPagination(t *T) { } }) + t.Run("Gateways_PageLimit", func(t *T) { + a, ctx := test.New(t) + + var total uint64 + paginateCtx := store.WithPagination(ctx, 0, 0, &total) + got, err := s.SearchGateways(paginateCtx, nil, &ttnpb.SearchGatewaysRequest{}) + if a.So(err, should.BeNil) && a.So(got, should.NotBeNil) { + a.So(got, should.HaveLength, 3) + } + + paginateCtx = store.WithPagination(ctx, 0, 2, &total) + got, err = s.SearchGateways(paginateCtx, nil, &ttnpb.SearchGatewaysRequest{}) + if a.So(err, should.BeNil) && a.So(got, should.NotBeNil) { + a.So(got, should.HaveLength, 3) + } + }) + t.Run("Organizations_Paginated", func(t *T) { a, ctx := test.New(t) @@ -784,6 +860,23 @@ func (st *StoreTest) TestEntitySearchPagination(t *T) { } }) + t.Run("Organizations_PageLimit", func(t *T) { + a, ctx := test.New(t) + + var total uint64 + paginateCtx := store.WithPagination(ctx, 0, 0, &total) + got, err := s.SearchOrganizations(paginateCtx, nil, &ttnpb.SearchOrganizationsRequest{}) + if a.So(err, should.BeNil) && a.So(got, should.NotBeNil) { + a.So(got, should.HaveLength, 3) + } + + paginateCtx = store.WithPagination(ctx, 0, 2, &total) + got, err = s.SearchOrganizations(paginateCtx, nil, &ttnpb.SearchOrganizationsRequest{}) + if a.So(err, should.BeNil) && a.So(got, should.NotBeNil) { + a.So(got, should.HaveLength, 3) + } + }) + t.Run("Users_Paginated", func(t *T) { a, ctx := test.New(t) @@ -806,4 +899,21 @@ func (st *StoreTest) TestEntitySearchPagination(t *T) { a.So(total, should.Equal, 7) } }) + + t.Run("Users_PageLimit", func(t *T) { + a, ctx := test.New(t) + + var total uint64 + paginateCtx := store.WithPagination(ctx, 0, 0, &total) + got, err := s.SearchUsers(paginateCtx, &ttnpb.SearchUsersRequest{}) + if a.So(err, should.BeNil) && a.So(got, should.NotBeNil) { + a.So(got, should.HaveLength, 3) + } + + paginateCtx = store.WithPagination(ctx, 0, 2, &total) + got, err = s.SearchUsers(paginateCtx, &ttnpb.SearchUsersRequest{}) + if a.So(err, should.BeNil) && a.So(got, should.NotBeNil) { + a.So(got, should.HaveLength, 3) + } + }) }