Skip to content

Commit

Permalink
is: Add second page defaults test
Browse files Browse the repository at this point in the history
  • Loading branch information
ryaplots committed Oct 23, 2024
1 parent a3e2495 commit f3e1623
Show file tree
Hide file tree
Showing 9 changed files with 73 additions and 20 deletions.
8 changes: 7 additions & 1 deletion pkg/identityserver/storetest/api_key_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
}
})
}
8 changes: 7 additions & 1 deletion pkg/identityserver/storetest/application_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}

Expand All @@ -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)
}
})
}
8 changes: 7 additions & 1 deletion pkg/identityserver/storetest/client_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}

Expand All @@ -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)
}
})
}
8 changes: 7 additions & 1 deletion pkg/identityserver/storetest/invitation_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -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%[email protected]", i+1),
Token: fmt.Sprintf("TOKEN%d", i+1),
Expand All @@ -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)
}
})
}
20 changes: 15 additions & 5 deletions pkg/identityserver/storetest/membership_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand All @@ -428,22 +428,32 @@ 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) {
a, ctx := test.New(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)
}
})
}
20 changes: 15 additions & 5 deletions pkg/identityserver/storetest/oauth_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()))
}

Expand All @@ -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(),
Expand All @@ -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(),
Expand All @@ -507,22 +507,32 @@ 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) {
a, ctx := test.New(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)
}
})
}
9 changes: 7 additions & 2 deletions pkg/identityserver/storetest/organization_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}

Expand All @@ -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)
}
})
}
9 changes: 7 additions & 2 deletions pkg/identityserver/storetest/user_session_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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)
}
})
}
3 changes: 1 addition & 2 deletions pkg/identityserver/storetest/user_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}

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

0 comments on commit f3e1623

Please sign in to comment.