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:
Stefan Benz
2024-10-17 23:20:57 +02:00
committed by GitHub
parent cc8d4fe17c
commit 8d97363642
47 changed files with 719 additions and 649 deletions

View File

@@ -8,6 +8,7 @@ import (
"testing"
"time"
"github.com/brianvoe/gofakeit/v6"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"google.golang.org/protobuf/types/known/timestamppb"
@@ -67,7 +68,7 @@ func TestServer_GetIDPByID(t *testing.T) {
IamCTX,
&idp.GetIDPByIDRequest{},
func(ctx context.Context, request *idp.GetIDPByIDRequest) *idpAttr {
name := fmt.Sprintf("GetIDPByID%d", time.Now().UnixNano())
name := fmt.Sprintf("GetIDPByID-%s", gofakeit.AppName())
resp := Instance.AddGenericOAuthProvider(ctx, name)
request.Id = resp.Id
return &idpAttr{
@@ -115,7 +116,7 @@ func TestServer_GetIDPByID(t *testing.T) {
UserCTX,
&idp.GetIDPByIDRequest{},
func(ctx context.Context, request *idp.GetIDPByIDRequest) *idpAttr {
name := fmt.Sprintf("GetIDPByID%d", time.Now().UnixNano())
name := fmt.Sprintf("GetIDPByID-%s", gofakeit.AppName())
resp := Instance.AddGenericOAuthProvider(IamCTX, name)
request.Id = resp.Id
return &idpAttr{
@@ -136,7 +137,7 @@ func TestServer_GetIDPByID(t *testing.T) {
CTX,
&idp.GetIDPByIDRequest{},
func(ctx context.Context, request *idp.GetIDPByIDRequest) *idpAttr {
name := fmt.Sprintf("GetIDPByID%d", time.Now().UnixNano())
name := fmt.Sprintf("GetIDPByID-%s", gofakeit.AppName())
resp := Instance.AddOrgGenericOAuthProvider(ctx, name)
request.Id = resp.Id
return &idpAttr{
@@ -184,7 +185,7 @@ func TestServer_GetIDPByID(t *testing.T) {
UserCTX,
&idp.GetIDPByIDRequest{},
func(ctx context.Context, request *idp.GetIDPByIDRequest) *idpAttr {
name := fmt.Sprintf("GetIDPByID%d", time.Now().UnixNano())
name := fmt.Sprintf("GetIDPByID-%s", gofakeit.AppName())
resp := Instance.AddOrgGenericOAuthProvider(CTX, name)
request.Id = resp.Id
return &idpAttr{
@@ -203,20 +204,14 @@ func TestServer_GetIDPByID(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
idpAttr := tt.args.dep(tt.args.ctx, tt.args.req)
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, getErr := Client.GetIDPByID(tt.args.ctx, tt.args.req)
assertErr := assert.NoError
got, err := Client.GetIDPByID(tt.args.ctx, tt.args.req)
if tt.wantErr {
assertErr = assert.Error
}
assertErr(ttt, getErr)
if getErr != nil {
require.Error(ttt, err)
return
}
require.NoError(ttt, err)
// set provided info from creation
tt.want.Idp.Details = idpAttr.Details
@@ -229,7 +224,7 @@ func TestServer_GetIDPByID(t *testing.T) {
tt.want.Idp.Details = got.Idp.Details
// to check the rest of the content
assert.Equal(ttt, tt.want.Idp, got.Idp)
}, retryDuration, time.Second)
}, retryDuration, tick)
})
}
}