Skip to content

Commit

Permalink
is: Add page limit test to search requests
Browse files Browse the repository at this point in the history
  • Loading branch information
ryaplots committed Nov 18, 2024
1 parent 341fd9a commit 6368bef
Showing 1 changed file with 110 additions and 0 deletions.
110 changes: 110 additions & 0 deletions pkg/identityserver/storetest/entity_search.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down Expand Up @@ -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)

Expand All @@ -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)

Expand All @@ -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)

Expand All @@ -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)

Expand All @@ -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)

Expand All @@ -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)
}
})
}

0 comments on commit 6368bef

Please sign in to comment.