From f3e1623be72c9bea936ca7c1e83f7d9bc5476a09 Mon Sep 17 00:00:00 2001 From: Darya Plotnytska Date: Wed, 23 Oct 2024 09:44:56 +0200 Subject: [PATCH] is: Add second page defaults test --- pkg/identityserver/storetest/api_key_store.go | 8 +++++++- .../storetest/application_store.go | 8 +++++++- pkg/identityserver/storetest/client_store.go | 8 +++++++- .../storetest/invitation_store.go | 8 +++++++- .../storetest/membership_store.go | 20 ++++++++++++++----- pkg/identityserver/storetest/oauth_store.go | 20 ++++++++++++++----- .../storetest/organization_store.go | 9 +++++++-- .../storetest/user_session_store.go | 9 +++++++-- pkg/identityserver/storetest/user_store.go | 3 +-- 9 files changed, 73 insertions(+), 20 deletions(-) diff --git a/pkg/identityserver/storetest/api_key_store.go b/pkg/identityserver/storetest/api_key_store.go index d9fbb622e1..0ea50c8a24 100644 --- a/pkg/identityserver/storetest/api_key_store.go +++ b/pkg/identityserver/storetest/api_key_store.go @@ -277,7 +277,7 @@ func (st *StoreTest) TestAPIKeyStorePaginationDefaults(t *T) { app1 := st.population.NewApplication(nil) var all []*ttnpb.APIKey - for i := 0; i < 10; i++ { + for i := 0; i < 15; i++ { _, key := st.population.NewAPIKey(app1.GetEntityIdentifiers(), ttnpb.Right_RIGHT_APPLICATION_ALL) key.Name = fmt.Sprintf("Key %d", i) all = append(all, key) @@ -305,5 +305,11 @@ func (st *StoreTest) TestAPIKeyStorePaginationDefaults(t *T) { if a.So(err, should.BeNil) && a.So(got, should.NotBeNil) { a.So(got, should.HaveLength, 7) } + + paginateCtx = store.WithPagination(ctx, 0, 2, &total) + got, err = s.FindAPIKeys(paginateCtx, app1.GetEntityIdentifiers()) + if a.So(err, should.BeNil) && a.So(got, should.NotBeNil) { + a.So(got, should.HaveLength, 7) + } }) } diff --git a/pkg/identityserver/storetest/application_store.go b/pkg/identityserver/storetest/application_store.go index ff77321fa3..573f51b86a 100644 --- a/pkg/identityserver/storetest/application_store.go +++ b/pkg/identityserver/storetest/application_store.go @@ -369,7 +369,7 @@ func (st *StoreTest) TestApplicationStorePaginationDefaults(t *T) { usr1 := st.population.NewUser() - for i := 0; i < 10; i++ { + for i := 0; i < 15; i++ { st.population.NewApplication(usr1.GetOrganizationOrUserIdentifiers()) } @@ -394,5 +394,11 @@ func (st *StoreTest) TestApplicationStorePaginationDefaults(t *T) { if a.So(err, should.BeNil) && a.So(got, should.NotBeNil) { a.So(got, should.HaveLength, 7) } + + paginateCtx = store.WithPagination(ctx, 0, 2, &total) + got, err = s.FindApplications(paginateCtx, nil, mask) + if a.So(err, should.BeNil) && a.So(got, should.NotBeNil) { + a.So(got, should.HaveLength, 7) + } }) } diff --git a/pkg/identityserver/storetest/client_store.go b/pkg/identityserver/storetest/client_store.go index 488e789cea..d8cdb28552 100644 --- a/pkg/identityserver/storetest/client_store.go +++ b/pkg/identityserver/storetest/client_store.go @@ -357,7 +357,7 @@ func (st *StoreTest) TestClientStorePaginationDefaults(t *T) { usr1 := st.population.NewUser() - for i := 0; i < 10; i++ { + for i := 0; i < 15; i++ { st.population.NewClient(usr1.GetOrganizationOrUserIdentifiers()) } @@ -382,5 +382,11 @@ func (st *StoreTest) TestClientStorePaginationDefaults(t *T) { if a.So(err, should.BeNil) && a.So(got, should.NotBeNil) { a.So(got, should.HaveLength, 7) } + + paginateCtx = store.WithPagination(ctx, 0, 2, &total) + got, err = s.FindClients(paginateCtx, nil, mask) + if a.So(err, should.BeNil) && a.So(got, should.NotBeNil) { + a.So(got, should.HaveLength, 7) + } }) } diff --git a/pkg/identityserver/storetest/invitation_store.go b/pkg/identityserver/storetest/invitation_store.go index 81fd21ac6e..70fc0c6ccf 100644 --- a/pkg/identityserver/storetest/invitation_store.go +++ b/pkg/identityserver/storetest/invitation_store.go @@ -271,7 +271,7 @@ func (st *StoreTest) TestInvitationStorePaginationDefaults(t *T) { } defer s.Close() - for i := 0; i < 10; i++ { + for i := 0; i < 15; i++ { _, err := s.CreateInvitation(ctx, &ttnpb.Invitation{ Email: fmt.Sprintf("user%d@example.com", i+1), Token: fmt.Sprintf("TOKEN%d", i+1), @@ -291,5 +291,11 @@ func (st *StoreTest) TestInvitationStorePaginationDefaults(t *T) { if a.So(err, should.BeNil) && a.So(got, should.NotBeNil) { a.So(got, should.HaveLength, 7) } + + paginateCtx = store.WithPagination(store.WithOrder(ctx, "email"), 0, 2, &total) + got, err = s.FindInvitations(paginateCtx) + if a.So(err, should.BeNil) && a.So(got, should.NotBeNil) { + a.So(got, should.HaveLength, 7) + } }) } diff --git a/pkg/identityserver/storetest/membership_store.go b/pkg/identityserver/storetest/membership_store.go index bdcd6a149e..1fff7b14da 100644 --- a/pkg/identityserver/storetest/membership_store.go +++ b/pkg/identityserver/storetest/membership_store.go @@ -397,18 +397,18 @@ func (st *StoreTest) TestMembershipStorePaginationDefaults(t *T) { }) var apps []*ttnpb.Application - for i := 0; i < 10; i++ { + for i := 0; i < 15; i++ { apps = append(apps, st.population.NewApplication(nil)) } var memberIDs []*ttnpb.OrganizationOrUserIdentifiers - for i := 0; i < 10; i++ { + for i := 0; i < 15; i++ { ids := st.population.NewUser().GetOrganizationOrUserIdentifiers() memberIDs = append(memberIDs, ids) st.population.NewMembership(ids, apps[0].GetEntityIdentifiers(), ttnpb.Right_RIGHT_APPLICATION_ALL) } - for i := 1; i < 10; i++ { + for i := 1; i < 15; i++ { st.population.NewMembership(memberIDs[0], apps[i].GetEntityIdentifiers(), ttnpb.Right_RIGHT_APPLICATION_ALL) } @@ -428,11 +428,16 @@ func (st *StoreTest) TestMembershipStorePaginationDefaults(t *T) { var total uint64 paginateCtx := store.WithPagination(ctx, 0, 0, &total) - got, err := s.FindMembers(paginateCtx, apps[0].GetEntityIdentifiers()) if a.So(err, should.BeNil) && a.So(got, should.NotBeNil) { a.So(got, should.HaveLength, 7) } + + paginateCtx = store.WithPagination(ctx, 0, 2, &total) + got, err = s.FindMembers(paginateCtx, apps[0].GetEntityIdentifiers()) + if a.So(err, should.BeNil) && a.So(got, should.NotBeNil) { + a.So(got, should.HaveLength, 7) + } }) t.Run("FindMemberships_PageLimit", func(t *T) { @@ -440,10 +445,15 @@ func (st *StoreTest) TestMembershipStorePaginationDefaults(t *T) { var total uint64 paginateCtx := store.WithPagination(ctx, 0, 0, &total) - got, err := s.FindMemberships(paginateCtx, memberIDs[0], "application", false) if a.So(err, should.BeNil) && a.So(got, should.NotBeNil) { a.So(got, should.HaveLength, 7) } + + paginateCtx = store.WithPagination(ctx, 0, 2, &total) + got, err = s.FindMemberships(paginateCtx, memberIDs[0], "application", false) + if a.So(err, should.BeNil) && a.So(got, should.NotBeNil) { + a.So(got, should.HaveLength, 7) + } }) } diff --git a/pkg/identityserver/storetest/oauth_store.go b/pkg/identityserver/storetest/oauth_store.go index db5b1b942d..b6cf59f01e 100644 --- a/pkg/identityserver/storetest/oauth_store.go +++ b/pkg/identityserver/storetest/oauth_store.go @@ -463,7 +463,7 @@ func (st *StoreTest) TestOAuthStorePaginationDefaults(t *T) { usr1 := st.population.NewUser() var clients []*ttnpb.Client - for i := 0; i < 10; i++ { + for i := 0; i < 15; i++ { clients = append(clients, st.population.NewClient(usr1.GetOrganizationOrUserIdentifiers())) } @@ -477,7 +477,7 @@ func (st *StoreTest) TestOAuthStorePaginationDefaults(t *T) { } defer s.Close() - for i := 0; i < 10; i++ { + for i := 0; i < 15; i++ { _, err := s.Authorize(ctx, &ttnpb.OAuthClientAuthorization{ UserIds: usr1.GetIds(), ClientIds: clients[i].GetIds(), @@ -489,7 +489,7 @@ func (st *StoreTest) TestOAuthStorePaginationDefaults(t *T) { time.Sleep(test.Delay) } - for i := 0; i < 10; i++ { + for i := 0; i < 15; i++ { _, err := s.CreateAccessToken(ctx, &ttnpb.OAuthAccessToken{ UserIds: usr1.GetIds(), ClientIds: clients[0].GetIds(), @@ -507,11 +507,16 @@ func (st *StoreTest) TestOAuthStorePaginationDefaults(t *T) { var total uint64 paginateCtx := store.WithPagination(store.WithOrder(ctx, "created_at"), 0, 0, &total) - got, err := s.ListAuthorizations(paginateCtx, usr1.GetIds()) if a.So(err, should.BeNil) && a.So(got, should.NotBeNil) { a.So(got, should.HaveLength, 7) } + + paginateCtx = store.WithPagination(store.WithOrder(ctx, "created_at"), 0, 2, &total) + got, err = s.ListAuthorizations(paginateCtx, usr1.GetIds()) + if a.So(err, should.BeNil) && a.So(got, should.NotBeNil) { + a.So(got, should.HaveLength, 7) + } }) t.Run("ListAccessTokens_PageLimit", func(t *T) { @@ -519,10 +524,15 @@ func (st *StoreTest) TestOAuthStorePaginationDefaults(t *T) { var total uint64 paginateCtx := store.WithPagination(store.WithOrder(ctx, "created_at"), 0, 0, &total) - got, err := s.ListAccessTokens(paginateCtx, usr1.GetIds(), clients[0].GetIds()) if a.So(err, should.BeNil) && a.So(got, should.NotBeNil) { a.So(got, should.HaveLength, 7) } + + paginateCtx = store.WithPagination(store.WithOrder(ctx, "created_at"), 0, 2, &total) + got, err = s.ListAccessTokens(paginateCtx, usr1.GetIds(), clients[0].GetIds()) + if a.So(err, should.BeNil) && a.So(got, should.NotBeNil) { + a.So(got, should.HaveLength, 7) + } }) } diff --git a/pkg/identityserver/storetest/organization_store.go b/pkg/identityserver/storetest/organization_store.go index d6d86814c0..21e4de7197 100644 --- a/pkg/identityserver/storetest/organization_store.go +++ b/pkg/identityserver/storetest/organization_store.go @@ -359,7 +359,7 @@ func (st *StoreTest) TestOrganizationStorePaginationDefaults(t *T) { usr1 := st.population.NewUser() - for i := 0; i < 10; i++ { + for i := 0; i < 15; i++ { st.population.NewOrganization(usr1.GetOrganizationOrUserIdentifiers()) } @@ -380,10 +380,15 @@ func (st *StoreTest) TestOrganizationStorePaginationDefaults(t *T) { var total uint64 paginateCtx := store.WithPagination(ctx, 0, 0, &total) - got, err := s.FindOrganizations(paginateCtx, nil, mask) if a.So(err, should.BeNil) && a.So(got, should.NotBeNil) { a.So(got, should.HaveLength, 7) } + + paginateCtx = store.WithPagination(ctx, 0, 2, &total) + got, err = s.FindOrganizations(paginateCtx, nil, mask) + if a.So(err, should.BeNil) && a.So(got, should.NotBeNil) { + a.So(got, should.HaveLength, 7) + } }) } diff --git a/pkg/identityserver/storetest/user_session_store.go b/pkg/identityserver/storetest/user_session_store.go index 31ce81eb76..2f01b86e28 100644 --- a/pkg/identityserver/storetest/user_session_store.go +++ b/pkg/identityserver/storetest/user_session_store.go @@ -250,7 +250,7 @@ func (st *StoreTest) TestUserSessionStorePaginationDefaults(t *T) { } defer s.Close() - for i := 0; i < 10; i++ { + for i := 0; i < 15; i++ { _, err := s.CreateSession(ctx, &ttnpb.UserSession{ UserIds: usr1.GetIds(), SessionId: fmt.Sprintf("SESS%d", i+1), @@ -267,10 +267,15 @@ func (st *StoreTest) TestUserSessionStorePaginationDefaults(t *T) { var total uint64 paginateCtx := store.WithPagination(store.WithOrder(ctx, "created_at"), 0, 0, &total) - got, err := s.FindSessions(paginateCtx, usr1.GetIds()) if a.So(err, should.BeNil) && a.So(got, should.NotBeNil) { a.So(got, should.HaveLength, 7) } + + paginateCtx = store.WithPagination(store.WithOrder(ctx, "created_at"), 0, 2, &total) + got, err = s.FindSessions(paginateCtx, usr1.GetIds()) + if a.So(err, should.BeNil) && a.So(got, should.NotBeNil) { + a.So(got, should.HaveLength, 7) + } }) } diff --git a/pkg/identityserver/storetest/user_store.go b/pkg/identityserver/storetest/user_store.go index 5bea958d3e..529f97881d 100644 --- a/pkg/identityserver/storetest/user_store.go +++ b/pkg/identityserver/storetest/user_store.go @@ -479,7 +479,7 @@ func (st *StoreTest) TestUserStorePaginationDefaults(t *T) { DefaultLimit: 7, }) - for i := 0; i < 20; i++ { + for i := 0; i < 15; i++ { st.population.NewUser() } @@ -500,7 +500,6 @@ func (st *StoreTest) TestUserStorePaginationDefaults(t *T) { var total uint64 paginateCtx := store.WithPagination(ctx, 0, 0, &total) - got, err := s.FindUsers(paginateCtx, nil, mask) if a.So(err, should.BeNil) && a.So(got, should.NotBeNil) { a.So(got, should.HaveLength, 7)