Skip to content

Commit

Permalink
is: Add e2e tests for page limit
Browse files Browse the repository at this point in the history
  • Loading branch information
ryaplots committed Oct 21, 2024
1 parent 5fa0bb1 commit 0376d91
Show file tree
Hide file tree
Showing 9 changed files with 160 additions and 64 deletions.
21 changes: 14 additions & 7 deletions pkg/identityserver/storetest/api_key_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ func (st *StoreTest) TestAPIKeyStorePagination(t *T) {
app1 := st.population.NewApplication(nil)

var all []*ttnpb.APIKey
for i := 0; i < 7; i++ {
for i := 0; i < 102; 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 @@ -253,17 +253,24 @@ func (st *StoreTest) TestAPIKeyStorePagination(t *T) {

got, err := s.FindAPIKeys(paginateCtx, app1.GetEntityIdentifiers())
if a.So(err, should.BeNil) && a.So(got, should.NotBeNil) {
if page == 4 {
a.So(got, should.HaveLength, 1)
} else {
a.So(got, should.HaveLength, 2)
}
a.So(got, should.HaveLength, 2)
for i, e := range got {
a.So(e.Name, should.Equal, all[i+2*int(page-1)].Name)
}
}

a.So(total, should.Equal, 7)
a.So(total, should.Equal, 102)
}
})

t.Run("FindAPIKeys_PageLimit", func(t *T) {
a, ctx := test.New(t)

var total uint64
paginateCtx := store.WithPagination(ctx, 0, 1, &total)
got, err := s.FindAPIKeys(paginateCtx, app1.GetEntityIdentifiers())
if a.So(err, should.BeNil) && a.So(got, should.NotBeNil) {
a.So(got, should.HaveLength, 100)
}
})
}
21 changes: 14 additions & 7 deletions pkg/identityserver/storetest/application_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ func (st *StoreTest) TestApplicationStorePagination(t *T) {
usr1 := st.population.NewUser()

var all []*ttnpb.Application
for i := 0; i < 7; i++ {
for i := 0; i < 102; i++ {
all = append(all, st.population.NewApplication(usr1.GetOrganizationOrUserIdentifiers()))
}

Expand All @@ -346,17 +346,24 @@ func (st *StoreTest) TestApplicationStorePagination(t *T) {

got, err := s.FindApplications(paginateCtx, nil, mask)
if a.So(err, should.BeNil) && a.So(got, should.NotBeNil) {
if page == 4 {
a.So(got, should.HaveLength, 1)
} else {
a.So(got, should.HaveLength, 2)
}
a.So(got, should.HaveLength, 2)
for i, e := range got {
a.So(e, should.Resemble, all[i+2*int(page-1)])
}
}

a.So(total, should.Equal, 7)
a.So(total, should.Equal, 102)
}
})

t.Run("FindApplications_PageLimit", func(t *T) {
a, ctx := test.New(t)

var total uint64
paginateCtx := store.WithPagination(ctx, 0, 1, &total)
got, err := s.FindApplications(paginateCtx, nil, mask)
if a.So(err, should.BeNil) && a.So(got, should.NotBeNil) {
a.So(got, should.HaveLength, 100)
}
})
}
21 changes: 14 additions & 7 deletions pkg/identityserver/storetest/client_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ func (st *StoreTest) TestClientStorePagination(t *T) {
usr1 := st.population.NewUser()

var all []*ttnpb.Client
for i := 0; i < 7; i++ {
for i := 0; i < 102; i++ {
all = append(all, st.population.NewClient(usr1.GetOrganizationOrUserIdentifiers()))
}

Expand All @@ -334,17 +334,24 @@ func (st *StoreTest) TestClientStorePagination(t *T) {

got, err := s.FindClients(paginateCtx, nil, mask)
if a.So(err, should.BeNil) && a.So(got, should.NotBeNil) {
if page == 4 {
a.So(got, should.HaveLength, 1)
} else {
a.So(got, should.HaveLength, 2)
}
a.So(got, should.HaveLength, 2)
for i, e := range got {
a.So(e, should.Resemble, all[i+2*int(page-1)])
}
}

a.So(total, should.Equal, 7)
a.So(total, should.Equal, 102)
}
})

t.Run("FindClients_PageLimit", func(t *T) {
a, ctx := test.New(t)

var total uint64
paginateCtx := store.WithPagination(ctx, 0, 1, &total)
got, err := s.FindClients(paginateCtx, nil, mask)
if a.So(err, should.BeNil) && a.So(got, should.NotBeNil) {
a.So(got, should.HaveLength, 100)
}
})
}
21 changes: 14 additions & 7 deletions pkg/identityserver/storetest/invitation_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ func (st *StoreTest) TestInvitationStorePagination(t *T) {
defer s.Close()

var all []*ttnpb.Invitation
for i := 0; i < 7; i++ {
for i := 0; i < 102; i++ {
created, err := s.CreateInvitation(ctx, &ttnpb.Invitation{
Email: fmt.Sprintf("user%[email protected]", i+1),
Token: fmt.Sprintf("TOKEN%d", i+1),
Expand All @@ -237,17 +237,24 @@ func (st *StoreTest) TestInvitationStorePagination(t *T) {

got, err := s.FindInvitations(paginateCtx)
if a.So(err, should.BeNil) && a.So(got, should.NotBeNil) {
if page == 4 {
a.So(got, should.HaveLength, 1)
} else {
a.So(got, should.HaveLength, 2)
}
a.So(got, should.HaveLength, 2)
for i, e := range got {
a.So(e, should.Resemble, all[i+2*int(page-1)])
}
}

a.So(total, should.Equal, 7)
a.So(total, should.Equal, 102)
}
})

t.Run("FindInvitations_PageLimit", func(t *T) {
a, ctx := test.New(t)

var total uint64
paginateCtx := store.WithPagination(store.WithOrder(ctx, "email"), 0, 1, &total)
got, err := s.FindInvitations(paginateCtx)
if a.So(err, should.BeNil) && a.So(got, should.NotBeNil) {
a.So(got, should.HaveLength, 100)
}
})
}
34 changes: 29 additions & 5 deletions pkg/identityserver/storetest/membership_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,18 +262,18 @@ func (st *StoreTest) TestMembershipStoreCRUD(t *T) {

func (st *StoreTest) TestMembershipStorePagination(t *T) {
var apps []*ttnpb.Application
for i := 0; i < 7; i++ {
for i := 0; i < 102; i++ {
apps = append(apps, st.population.NewApplication(nil))
}

var memberIDs []*ttnpb.OrganizationOrUserIdentifiers
for i := 0; i < 7; i++ {
for i := 0; i < 102; 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 < 7; i++ {
for i := 1; i < 102; i++ {
st.population.NewMembership(memberIDs[0], apps[i].GetEntityIdentifiers(), ttnpb.Right_RIGHT_APPLICATION_ALL)
}

Expand Down Expand Up @@ -312,7 +312,19 @@ func (st *StoreTest) TestMembershipStorePagination(t *T) {
}
}

a.So(total, should.Equal, 7)
a.So(total, should.Equal, 102)
}
})

t.Run("FindMembers_PageLimit", func(t *T) {
a, ctx := test.New(t)

var total uint64
paginateCtx := store.WithPagination(ctx, 0, 1, &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, 100)
}
})

Expand Down Expand Up @@ -385,7 +397,19 @@ func (st *StoreTest) TestMembershipStorePagination(t *T) {
}
}

a.So(total, should.Equal, 7)
a.So(total, should.Equal, 102)
}
})

t.Run("FindMemberships_PageLimit", func(t *T) {
a, ctx := test.New(t)

var total uint64
paginateCtx := store.WithPagination(ctx, 0, 1, &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, 100)
}
})
}
40 changes: 30 additions & 10 deletions pkg/identityserver/storetest/oauth_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ func (st *StoreTest) TestOAuthStorePagination(t *T) {
usr1 := st.population.NewUser()

var clients []*ttnpb.Client
for i := 0; i < 7; i++ {
for i := 0; i < 102; i++ {
clients = append(clients, st.population.NewClient(usr1.GetOrganizationOrUserIdentifiers()))
}

Expand All @@ -377,7 +377,7 @@ func (st *StoreTest) TestOAuthStorePagination(t *T) {
defer s.Close()

var authorizations []*ttnpb.OAuthClientAuthorization
for i := 0; i < 7; i++ {
for i := 0; i < 102; i++ {
created, err := s.Authorize(ctx, &ttnpb.OAuthClientAuthorization{
UserIds: usr1.GetIds(),
ClientIds: clients[i].GetIds(),
Expand All @@ -391,7 +391,7 @@ func (st *StoreTest) TestOAuthStorePagination(t *T) {
}

var accessTokens []*ttnpb.OAuthAccessToken
for i := 0; i < 7; i++ {
for i := 0; i < 102; i++ {
created, err := s.CreateAccessToken(ctx, &ttnpb.OAuthAccessToken{
UserIds: usr1.GetIds(),
ClientIds: clients[0].GetIds(),
Expand Down Expand Up @@ -424,7 +424,7 @@ func (st *StoreTest) TestOAuthStorePagination(t *T) {
}
}

a.So(total, should.Equal, 7)
a.So(total, should.Equal, 102)
}
})

Expand All @@ -437,17 +437,37 @@ func (st *StoreTest) TestOAuthStorePagination(t *T) {

got, err := s.ListAccessTokens(paginateCtx, usr1.GetIds(), clients[0].GetIds())
if a.So(err, should.BeNil) && a.So(got, should.NotBeNil) {
if page == 4 {
a.So(got, should.HaveLength, 1)
} else {
a.So(got, should.HaveLength, 2)
}
a.So(got, should.HaveLength, 2)
for i, e := range got {
a.So(e, should.Resemble, accessTokens[i+2*int(page-1)])
}
}

a.So(total, should.Equal, 7)
a.So(total, should.Equal, 102)
}
})

t.Run("ListAuthorizations_PageLimit", func(t *T) {
a, ctx := test.New(t)

var total uint64
paginateCtx := store.WithPagination(store.WithOrder(ctx, "created_at"), 0, 1, &total)

got, err := s.ListAuthorizations(paginateCtx, usr1.GetIds())
if a.So(err, should.BeNil) && a.So(got, should.NotBeNil) {
a.So(got, should.HaveLength, 100)
}
})

t.Run("ListAccessTokens_PageLimit", func(t *T) {
a, ctx := test.New(t)

var total uint64
paginateCtx := store.WithPagination(store.WithOrder(ctx, "created_at"), 0, 1, &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, 100)
}
})
}
22 changes: 15 additions & 7 deletions pkg/identityserver/storetest/organization_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ func (st *StoreTest) TestOrganizationStorePagination(t *T) {
usr1 := st.population.NewUser()

var all []*ttnpb.Organization
for i := 0; i < 7; i++ {
for i := 0; i < 102; i++ {
all = append(all, st.population.NewOrganization(usr1.GetOrganizationOrUserIdentifiers()))
}

Expand All @@ -336,17 +336,25 @@ func (st *StoreTest) TestOrganizationStorePagination(t *T) {

got, err := s.FindOrganizations(paginateCtx, nil, mask)
if a.So(err, should.BeNil) && a.So(got, should.NotBeNil) {
if page == 4 {
a.So(got, should.HaveLength, 1)
} else {
a.So(got, should.HaveLength, 2)
}
a.So(got, should.HaveLength, 2)
for i, e := range got {
a.So(e, should.Resemble, all[i+2*int(page-1)])
}
}

a.So(total, should.Equal, 7)
a.So(total, should.Equal, 102)
}
})

t.Run("FindOrganizations_PageLimit", func(t *T) {
a, ctx := test.New(t)

var total uint64
paginateCtx := store.WithPagination(ctx, 0, 1, &total)

got, err := s.FindOrganizations(paginateCtx, nil, mask)
if a.So(err, should.BeNil) && a.So(got, should.NotBeNil) {
a.So(got, should.HaveLength, 100)
}
})
}
22 changes: 15 additions & 7 deletions pkg/identityserver/storetest/user_session_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ func (st *StoreTest) TestUserSessionStorePagination(t *T) {
defer s.Close()

var sessions []*ttnpb.UserSession
for i := 0; i < 7; i++ {
for i := 0; i < 102; i++ {
created, err := s.CreateSession(ctx, &ttnpb.UserSession{
UserIds: usr1.GetIds(),
SessionId: fmt.Sprintf("SESS%d", i+1),
Expand All @@ -215,17 +215,25 @@ func (st *StoreTest) TestUserSessionStorePagination(t *T) {

got, err := s.FindSessions(paginateCtx, usr1.GetIds())
if a.So(err, should.BeNil) && a.So(got, should.NotBeNil) {
if page == 4 {
a.So(got, should.HaveLength, 1)
} else {
a.So(got, should.HaveLength, 2)
}
a.So(got, should.HaveLength, 2)
for i, e := range got {
a.So(e, should.Resemble, sessions[i+2*int(page-1)])
}
}

a.So(total, should.Equal, 7)
a.So(total, should.Equal, 102)
}
})

t.Run("FindSessions_PageLimit", func(t *T) {
a, ctx := test.New(t)

var total uint64
paginateCtx := store.WithPagination(store.WithOrder(ctx, "created_at"), 0, 1, &total)

got, err := s.FindSessions(paginateCtx, usr1.GetIds())
if a.So(err, should.BeNil) && a.So(got, should.NotBeNil) {
a.So(got, should.HaveLength, 100)
}
})
}
Loading

0 comments on commit 0376d91

Please sign in to comment.