mirror of
https://github.com/zitadel/zitadel.git
synced 2025-08-12 03:57:32 +00:00
chore: improve integration tests (#8727)
Improve integration tests: - spliting the tests in TokenExchange to isolated instances and in parallel - corrected some test structure so that the check for Details is no done anymore if the test already failed - replace required-calls with assert-calls to not stop the testing - add gofakeit for application, project and usernames(emails) - add eventually checks for testing in actions v2, so the request only get called when the execution is defined - check for length of results in list/search endpoints to avoid index errors
This commit is contained in:
@@ -4,11 +4,11 @@ package org_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"os"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/brianvoe/gofakeit/v6"
|
||||
"github.com/muhlemmer/gu"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
@@ -75,7 +75,7 @@ func TestServer_AddOrganization(t *testing.T) {
|
||||
name: "invalid admin type",
|
||||
ctx: CTX,
|
||||
req: &org.AddOrganizationRequest{
|
||||
Name: fmt.Sprintf("%d", time.Now().UnixNano()),
|
||||
Name: gofakeit.AppName(),
|
||||
Admins: []*org.AddOrganizationRequest_Admin{
|
||||
{},
|
||||
},
|
||||
@@ -86,7 +86,7 @@ func TestServer_AddOrganization(t *testing.T) {
|
||||
name: "admin with init",
|
||||
ctx: CTX,
|
||||
req: &org.AddOrganizationRequest{
|
||||
Name: fmt.Sprintf("%d", time.Now().UnixNano()),
|
||||
Name: gofakeit.AppName(),
|
||||
Admins: []*org.AddOrganizationRequest_Admin{
|
||||
{
|
||||
UserType: &org.AddOrganizationRequest_Admin_Human{
|
||||
@@ -96,7 +96,7 @@ func TestServer_AddOrganization(t *testing.T) {
|
||||
FamilyName: "lastname",
|
||||
},
|
||||
Email: &user.SetHumanEmail{
|
||||
Email: fmt.Sprintf("%d@mouse.com", time.Now().UnixNano()),
|
||||
Email: gofakeit.Email(),
|
||||
Verification: &user.SetHumanEmail_ReturnCode{
|
||||
ReturnCode: &user.ReturnEmailVerificationCode{},
|
||||
},
|
||||
@@ -121,7 +121,7 @@ func TestServer_AddOrganization(t *testing.T) {
|
||||
name: "existing user and new human with idp",
|
||||
ctx: CTX,
|
||||
req: &org.AddOrganizationRequest{
|
||||
Name: fmt.Sprintf("%d", time.Now().UnixNano()),
|
||||
Name: gofakeit.AppName(),
|
||||
Admins: []*org.AddOrganizationRequest_Admin{
|
||||
{
|
||||
UserType: &org.AddOrganizationRequest_Admin_UserId{UserId: User.GetUserId()},
|
||||
@@ -134,7 +134,7 @@ func TestServer_AddOrganization(t *testing.T) {
|
||||
FamilyName: "lastname",
|
||||
},
|
||||
Email: &user.SetHumanEmail{
|
||||
Email: fmt.Sprintf("%d@mouse.com", time.Now().UnixNano()),
|
||||
Email: gofakeit.Email(),
|
||||
Verification: &user.SetHumanEmail_IsVerified{
|
||||
IsVerified: true,
|
||||
},
|
||||
|
@@ -83,10 +83,10 @@ func TestServer_ListOrganizations(t *testing.T) {
|
||||
func(ctx context.Context, request *org.ListOrganizationsRequest) ([]orgAttr, error) {
|
||||
count := 3
|
||||
orgs := make([]orgAttr, count)
|
||||
prefix := fmt.Sprintf("ListOrgs%d", time.Now().UnixNano())
|
||||
prefix := fmt.Sprintf("ListOrgs-%s", gofakeit.AppName())
|
||||
for i := 0; i < count; i++ {
|
||||
name := prefix + strconv.Itoa(i)
|
||||
orgResp := Instance.CreateOrganization(ctx, name, fmt.Sprintf("%d@mouse.com", time.Now().UnixNano()))
|
||||
orgResp := Instance.CreateOrganization(ctx, name, gofakeit.Email())
|
||||
orgs[i] = orgAttr{
|
||||
ID: orgResp.GetOrganizationId(),
|
||||
Name: name,
|
||||
@@ -399,25 +399,19 @@ func TestServer_ListOrganizations(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
retryDuration := time.Minute
|
||||
if ctxDeadline, ok := CTX.Deadline(); ok {
|
||||
retryDuration = time.Until(ctxDeadline)
|
||||
}
|
||||
retryDuration, tick := integration.WaitForAndTickWithMaxDuration(CTX, time.Minute)
|
||||
require.EventuallyWithT(t, func(ttt *assert.CollectT) {
|
||||
got, listErr := Client.ListOrganizations(tt.args.ctx, tt.args.req)
|
||||
assertErr := assert.NoError
|
||||
got, err := Client.ListOrganizations(tt.args.ctx, tt.args.req)
|
||||
if tt.wantErr {
|
||||
assertErr = assert.Error
|
||||
}
|
||||
assertErr(ttt, listErr)
|
||||
if listErr != nil {
|
||||
require.Error(ttt, err)
|
||||
return
|
||||
}
|
||||
require.NoError(ttt, err)
|
||||
|
||||
// totalResult is unrelated to the tests here so gets carried over, can vary from the count of results due to permissions
|
||||
tt.want.Details.TotalResult = got.Details.TotalResult
|
||||
// always first check length, otherwise its failed anyway
|
||||
assert.Len(ttt, got.Result, len(tt.want.Result))
|
||||
require.Len(ttt, got.Result, len(tt.want.Result))
|
||||
|
||||
for i := range tt.want.Result {
|
||||
// domain from result, as it is generated though the create
|
||||
@@ -430,7 +424,7 @@ func TestServer_ListOrganizations(t *testing.T) {
|
||||
assert.Contains(ttt, got.Result, tt.want.Result[i])
|
||||
}
|
||||
integration.AssertListDetails(t, tt.want, got)
|
||||
}, retryDuration, time.Millisecond*100, "timeout waiting for expected user result")
|
||||
}, retryDuration, tick, "timeout waiting for expected user result")
|
||||
})
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user