chore: move gofakeit integration testing calls (#10684)

# Which Problems Are Solved

Flakiness and conflicts in value from gofakeit.

# How the Problems Are Solved

Move Gofakeit calls to the integration package, to guarantee proper
usage and values for integration testing.

# Additional Changes

None

# Additional Context

None

(cherry picked from commit 492f1826ee)
This commit is contained in:
Stefan Benz
2025-09-10 08:00:31 +02:00
committed by Livio Spring
parent 78ded99017
commit b892fc9b28
70 changed files with 1404 additions and 1293 deletions

View File

@@ -13,7 +13,6 @@ import (
"testing"
"time"
"github.com/brianvoe/gofakeit/v6"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"golang.org/x/text/language"
@@ -50,7 +49,7 @@ func init() {
func TestBulk(t *testing.T) {
iamOwnerCtx := Instance.WithAuthorization(CTX, integration.UserTypeIAMOwner)
secondaryOrg := Instance.CreateOrganization(iamOwnerCtx, integration.OrganizationName(), gofakeit.Email())
secondaryOrg := Instance.CreateOrganization(iamOwnerCtx, integration.OrganizationName(), integration.Email())
createdSecondaryOrgUser := createHumanUser(t, iamOwnerCtx, secondaryOrg.OrganizationId, 0)
bulkMinimalUpdateSecondaryOrgJson := test.Must(json.Marshal(buildMinimalUpdateRequest(createdSecondaryOrgUser.UserId)))
@@ -480,7 +479,7 @@ func TestBulk(t *testing.T) {
},
{
name: "fail on errors",
body: withUsername(bulkFailOnErrorsJson, gofakeit.Username()),
body: withUsername(bulkFailOnErrorsJson, integration.Username()),
want: &scim.BulkResponse{
Schemas: []schemas.ScimSchemaType{schemas.IdBulkResponse},
Operations: []*scim.BulkResponseOperation{
@@ -680,7 +679,7 @@ func buildTooManyOperationsRequest() *scim.BulkRequest {
req.Operations[i] = &scim.BulkRequestOperation{
Method: http.MethodPost,
Path: "/Users",
Data: withUsername(minimalUserJson, gofakeit.Username()),
Data: withUsername(minimalUserJson, integration.Username()),
}
}

View File

@@ -9,8 +9,6 @@ import (
"testing"
"time"
"github.com/brianvoe/gofakeit/v6"
"github.com/zitadel/zitadel/internal/integration"
"github.com/zitadel/zitadel/pkg/grpc/org/v2"
)
@@ -35,7 +33,7 @@ func TestMain(m *testing.M) {
CTX = Instance.WithAuthorizationToken(ctx, integration.UserTypeOrgOwner)
iamOwnerCtx := Instance.WithAuthorizationToken(CTX, integration.UserTypeIAMOwner)
SecondaryOrganization = Instance.CreateOrganization(iamOwnerCtx, integration.OrganizationName(), gofakeit.Email())
SecondaryOrganization = Instance.CreateOrganization(iamOwnerCtx, integration.OrganizationName(), integration.Email())
return m.Run()
}())

View File

@@ -13,7 +13,6 @@ import (
"text/template"
"time"
"github.com/brianvoe/gofakeit/v6"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"golang.org/x/text/language"
@@ -173,7 +172,7 @@ func withUsername(fixture []byte, username string) []byte {
}
func TestCreateUser(t *testing.T) {
minimalUsername := gofakeit.Username()
minimalUsername := integration.Username()
tests := []struct {
name string
body []byte
@@ -278,21 +277,21 @@ func TestCreateUser(t *testing.T) {
},
{
name: "not authenticated",
body: withUsername(minimalUserJson, gofakeit.Username()),
body: withUsername(minimalUserJson, integration.Username()),
ctx: context.Background(),
wantErr: true,
errorStatus: http.StatusUnauthorized,
},
{
name: "no permissions",
body: withUsername(minimalUserJson, gofakeit.Username()),
body: withUsername(minimalUserJson, integration.Username()),
ctx: Instance.WithAuthorization(CTX, integration.UserTypeNoPermission),
wantErr: true,
errorStatus: http.StatusNotFound,
},
{
name: "another org",
body: withUsername(minimalUserJson, gofakeit.Username()),
body: withUsername(minimalUserJson, integration.Username()),
orgID: SecondaryOrganization.OrganizationId,
wantErr: true,
errorStatus: http.StatusNotFound,
@@ -356,7 +355,7 @@ func TestCreateUser(t *testing.T) {
}
func TestCreateUser_duplicate(t *testing.T) {
parsedMinimalUserJson := withUsername(minimalUserJson, gofakeit.Username())
parsedMinimalUserJson := withUsername(minimalUserJson, integration.Username())
createdUser, err := Instance.Client.SCIM.Users.Create(CTX, Instance.DefaultOrg.Id, parsedMinimalUserJson)
require.NoError(t, err)
@@ -370,7 +369,7 @@ func TestCreateUser_duplicate(t *testing.T) {
}
func TestCreateUser_metadata(t *testing.T) {
username := gofakeit.Username()
username := integration.Username()
createdUser, err := Instance.Client.SCIM.Users.Create(CTX, Instance.DefaultOrg.Id, withUsername(fullUserJson, username))
require.NoError(t, err)
@@ -408,7 +407,7 @@ func TestCreateUser_scopedExternalID(t *testing.T) {
require.NoError(t, err)
ctx := integration.WithAuthorizationToken(CTX, callingUserPat)
setProvisioningDomain(t, callingUserId, "fooBar")
createdUser, err := Instance.Client.SCIM.Users.Create(ctx, Instance.DefaultOrg.Id, withUsername(fullUserJson, gofakeit.Username()))
createdUser, err := Instance.Client.SCIM.Users.Create(ctx, Instance.DefaultOrg.Id, withUsername(fullUserJson, integration.Username()))
require.NoError(t, err)
retryDuration, tick := integration.WaitForAndTickWithMaxDuration(ctx, time.Minute)
require.EventuallyWithT(t, func(tt *assert.CollectT) {

View File

@@ -8,7 +8,6 @@ import (
"testing"
"time"
"github.com/brianvoe/gofakeit/v6"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"google.golang.org/grpc/codes"
@@ -77,9 +76,9 @@ func TestDeleteUser_errors(t *testing.T) {
func TestDeleteUser_ensureReallyDeleted(t *testing.T) {
// create user and dependencies
createUserResp := Instance.CreateHumanUser(CTX)
proj := Instance.CreateProject(CTX, t, "", gofakeit.AppName(), false, false)
proj := Instance.CreateProject(CTX, t, Instance.DefaultOrg.GetId(), integration.ProjectName(), false, false)
Instance.CreateProjectUserGrant(t, CTX, proj.Id, createUserResp.UserId)
Instance.CreateProjectUserGrant(t, CTX, Instance.DefaultOrg.GetId(), proj.Id, createUserResp.UserId)
// delete user via scim
err := Instance.Client.SCIM.Users.Delete(CTX, Instance.DefaultOrg.Id, createUserResp.UserId)

View File

@@ -9,7 +9,6 @@ import (
"testing"
"time"
"github.com/brianvoe/gofakeit/v6"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"golang.org/x/text/language"
@@ -108,7 +107,7 @@ func TestGetUser(t *testing.T) {
{
name: "created via scim",
setup: func(t *testing.T) testCase {
username := gofakeit.Username()
username := integration.Username()
createdUser, err := Instance.Client.SCIM.Users.Create(CTX, Instance.DefaultOrg.Id, withUsername(fullUserJson, username))
require.NoError(t, err)
return testCase{
@@ -221,7 +220,7 @@ func TestGetUser(t *testing.T) {
{
name: "scoped externalID",
setup: func(t *testing.T) testCase {
createdUser, err := Instance.Client.SCIM.Users.Create(CTX, Instance.DefaultOrg.Id, withUsername(fullUserJson, gofakeit.Username()))
createdUser, err := Instance.Client.SCIM.Users.Create(CTX, Instance.DefaultOrg.Id, withUsername(fullUserJson, integration.Username()))
require.NoError(t, err)
callingUserId, callingUserPat, err := Instance.CreateMachineUserPATWithMembership(CTX, "ORG_OWNER")
require.NoError(t, err)

View File

@@ -9,11 +9,11 @@ import (
"strings"
"testing"
"github.com/brianvoe/gofakeit/v6"
"github.com/muhlemmer/gu"
"github.com/stretchr/testify/require"
"github.com/zitadel/zitadel/internal/api/scim/resources"
"github.com/zitadel/zitadel/internal/integration"
"github.com/zitadel/zitadel/pkg/grpc/object/v2"
user_v2 "github.com/zitadel/zitadel/pkg/grpc/user/v2"
)
@@ -27,7 +27,7 @@ var totalCountOfHumanUsers = 13
// these should never be modified.
// This allows testing list requests without filters.
iamOwnerCtx := Instance.WithAuthorization(CTX, integration.UserTypeIAMOwner)
secondaryOrg := Instance.CreateOrganization(iamOwnerCtx, gofakeit.Name(), gofakeit.Email())
secondaryOrg := Instance.CreateOrganization(iamOwnerCtx, integration.OrganizationName(), integration.Email())
secondaryOrgCreatedUserIDs := createUsers(t, iamOwnerCtx, secondaryOrg.OrganizationId)
testsInitializedUtc := time.Now().UTC()
@@ -292,8 +292,8 @@ var totalCountOfHumanUsers = 13
UserId: userID,
Profile: &user_v2.SetHumanProfile{
GivenName: "scim-user-given-name-modified-0: " + gofakeit.FirstName(),
FamilyName: "scim-user-family-name-modified-0: " + gofakeit.LastName(),
GivenName: "scim-user-given-name-modified-0: " + integration.FirstName(),
FamilyName: "scim-user-family-name-modified-0: " + integration.LastName(),
},
})
require.NoError(t, err)
@@ -348,7 +348,7 @@ var totalCountOfHumanUsers = 13
name: "do not count user of other org",
prepare: func(t require.TestingT) *scim.ListRequest {
iamOwnerCtx := Instance.WithAuthorization(CTX, integration.UserTypeIAMOwner)
org := Instance.CreateOrganization(iamOwnerCtx, gofakeit.Name(), gofakeit.Email())
org := Instance.CreateOrganization(iamOwnerCtx, integration.OrganizationName(), integration.Email())
resp := createHumanUser(t, iamOwnerCtx, org.OrganizationId, 102)
return &scim.ListRequest{
@@ -442,7 +442,7 @@ func createUsers(t *testing.T, ctx context.Context, orgID string) []string {
// create the full scim user if on primary org
if orgID == Instance.DefaultOrg.Id {
fullUserCreatedResp, err := Instance.Client.SCIM.Users.Create(ctx, orgID, withUsername(fullUserJson, gofakeit.Username()))
fullUserCreatedResp, err := Instance.Client.SCIM.Users.Create(ctx, orgID, withUsername(fullUserJson, integration.Username()))
require.NoError(t, err)
createdUserIDs = append(createdUserIDs, fullUserCreatedResp.ID)
count--
@@ -473,15 +473,15 @@ func createHumanUser(t require.TestingT, ctx context.Context, orgID string, i in
OrgId: orgID,
},
},
Username: gu.Ptr(fmt.Sprintf("scim-username-%d: %s", i, gofakeit.Username())),
Username: gu.Ptr(fmt.Sprintf("scim-username-%d: %s", i, integration.Username())),
Profile: &user_v2.SetHumanProfile{
GivenName: fmt.Sprintf("scim-givenname-%d: %s", i, gofakeit.FirstName()),
FamilyName: fmt.Sprintf("scim-familyname-%d: %s", i, gofakeit.LastName()),
GivenName: fmt.Sprintf("scim-givenname-%d: %s", i, integration.FirstName()),
FamilyName: fmt.Sprintf("scim-familyname-%d: %s", i, integration.LastName()),
PreferredLanguage: gu.Ptr("en-US"),
Gender: gu.Ptr(user_v2.Gender_GENDER_MALE),
},
Email: &user_v2.SetHumanEmail{
Email: fmt.Sprintf("scim-email-%d-%d@example.com", i, gofakeit.Number(0, 1_000_000)),
Email: fmt.Sprintf("scim-email-%d-%d@example.com", i, integration.Number()),
},
})
require.NoError(t, err)

View File

@@ -11,7 +11,6 @@ import (
"testing"
"time"
"github.com/brianvoe/gofakeit/v6"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"golang.org/x/text/language"
@@ -200,28 +199,28 @@ func TestReplaceUser(t *testing.T) {
},
{
name: "not authenticated",
body: withUsername(minimalUserJson, gofakeit.Username()),
body: withUsername(minimalUserJson, integration.Username()),
ctx: context.Background(),
wantErr: true,
errorStatus: http.StatusUnauthorized,
},
{
name: "no permissions",
body: withUsername(minimalUserJson, gofakeit.Username()),
body: withUsername(minimalUserJson, integration.Username()),
ctx: Instance.WithAuthorization(CTX, integration.UserTypeNoPermission),
wantErr: true,
errorStatus: http.StatusNotFound,
},
{
name: "another org",
body: withUsername(minimalUserJson, gofakeit.Username()),
body: withUsername(minimalUserJson, integration.Username()),
replaceUserOrgID: SecondaryOrganization.OrganizationId,
wantErr: true,
errorStatus: http.StatusNotFound,
},
{
name: "another org with permissions",
body: withUsername(minimalUserJson, gofakeit.Username()),
body: withUsername(minimalUserJson, integration.Username()),
replaceUserOrgID: SecondaryOrganization.OrganizationId,
ctx: Instance.WithAuthorization(CTX, integration.UserTypeIAMOwner),
wantErr: true,
@@ -231,7 +230,7 @@ func TestReplaceUser(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
// use iam owner => we don't want to test permissions of the create endpoint.
createdUser, err := Instance.Client.SCIM.Users.Create(Instance.WithAuthorization(CTX, integration.UserTypeIAMOwner), Instance.DefaultOrg.Id, withUsername(fullUserJson, gofakeit.Username()))
createdUser, err := Instance.Client.SCIM.Users.Create(Instance.WithAuthorization(CTX, integration.UserTypeIAMOwner), Instance.DefaultOrg.Id, withUsername(fullUserJson, integration.Username()))
require.NoError(t, err)
ctx := tt.ctx
@@ -290,7 +289,7 @@ func TestReplaceUser(t *testing.T) {
func TestReplaceUser_removeOldMetadata(t *testing.T) {
// ensure old metadata is removed correctly
username := gofakeit.Username()
username := integration.Username()
createdUser, err := Instance.Client.SCIM.Users.Create(CTX, Instance.DefaultOrg.Id, withUsername(fullUserJson, username))
require.NoError(t, err)
@@ -315,10 +314,10 @@ func TestReplaceUser_removeOldMetadata(t *testing.T) {
func TestReplaceUser_emailType(t *testing.T) {
// ensure old metadata is removed correctly
createdUser, err := Instance.Client.SCIM.Users.Create(CTX, Instance.DefaultOrg.Id, withUsername(fullUserJson, gofakeit.Username()))
createdUser, err := Instance.Client.SCIM.Users.Create(CTX, Instance.DefaultOrg.Id, withUsername(fullUserJson, integration.Username()))
require.NoError(t, err)
replacedUsername := gofakeit.Username()
replacedUsername := integration.Username()
_, err = Instance.Client.SCIM.Users.Replace(CTX, Instance.DefaultOrg.Id, createdUser.ID, withUsername(minimalUserWithEmailTypeReplaceJson, replacedUsername))
require.NoError(t, err)
@@ -340,7 +339,7 @@ func TestReplaceUser_emailType(t *testing.T) {
}
func TestReplaceUser_scopedExternalID(t *testing.T) {
createdUser, err := Instance.Client.SCIM.Users.Create(CTX, Instance.DefaultOrg.Id, withUsername(fullUserJson, gofakeit.Username()))
createdUser, err := Instance.Client.SCIM.Users.Create(CTX, Instance.DefaultOrg.Id, withUsername(fullUserJson, integration.Username()))
require.NoError(t, err)
callingUserId, callingUserPat, err := Instance.CreateMachineUserPATWithMembership(CTX, "ORG_OWNER")
require.NoError(t, err)

View File

@@ -11,7 +11,6 @@ import (
"testing"
"time"
"github.com/brianvoe/gofakeit/v6"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"golang.org/x/text/language"
@@ -53,7 +52,7 @@ func TestUpdateUser(t *testing.T) {
{
name: "not authenticated",
setup: func(t *testing.T) testCase {
username := gofakeit.Username()
username := integration.Username()
created, err := Instance.Client.SCIM.Users.Create(CTX, Instance.DefaultOrg.Id, withUsername(fullUserJson, username))
require.NoError(t, err)
return testCase{
@@ -68,7 +67,7 @@ func TestUpdateUser(t *testing.T) {
{
name: "no permissions",
setup: func(t *testing.T) testCase {
username := gofakeit.Username()
username := integration.Username()
created, err := Instance.Client.SCIM.Users.Create(CTX, Instance.DefaultOrg.Id, withUsername(fullUserJson, username))
require.NoError(t, err)
return testCase{
@@ -83,7 +82,7 @@ func TestUpdateUser(t *testing.T) {
{
name: "other org",
setup: func(t *testing.T) testCase {
username := gofakeit.Username()
username := integration.Username()
created, err := Instance.Client.SCIM.Users.Create(CTX, Instance.DefaultOrg.Id, withUsername(fullUserJson, username))
require.NoError(t, err)
return testCase{
@@ -98,7 +97,7 @@ func TestUpdateUser(t *testing.T) {
{
name: "other org with permissions",
setup: func(t *testing.T) testCase {
username := gofakeit.Username()
username := integration.Username()
created, err := Instance.Client.SCIM.Users.Create(CTX, Instance.DefaultOrg.Id, withUsername(fullUserJson, username))
require.NoError(t, err)
return testCase{
@@ -114,7 +113,7 @@ func TestUpdateUser(t *testing.T) {
{
name: "invalid patch json",
setup: func(t *testing.T) testCase {
username := gofakeit.Username()
username := integration.Username()
created, err := Instance.Client.SCIM.Users.Create(CTX, Instance.DefaultOrg.Id, withUsername(fullUserJson, username))
require.NoError(t, err)
return testCase{
@@ -128,7 +127,7 @@ func TestUpdateUser(t *testing.T) {
{
name: "password complexity violation",
setup: func(t *testing.T) testCase {
username := gofakeit.Username()
username := integration.Username()
created, err := Instance.Client.SCIM.Users.Create(CTX, Instance.DefaultOrg.Id, withUsername(fullUserJson, username))
require.NoError(t, err)
return testCase{
@@ -142,7 +141,7 @@ func TestUpdateUser(t *testing.T) {
{
name: "invalid profile url",
setup: func(t *testing.T) testCase {
username := gofakeit.Username()
username := integration.Username()
created, err := Instance.Client.SCIM.Users.Create(CTX, Instance.DefaultOrg.Id, withUsername(fullUserJson, username))
require.NoError(t, err)
return testCase{
@@ -156,7 +155,7 @@ func TestUpdateUser(t *testing.T) {
{
name: "invalid time zone",
setup: func(t *testing.T) testCase {
username := gofakeit.Username()
username := integration.Username()
created, err := Instance.Client.SCIM.Users.Create(CTX, Instance.DefaultOrg.Id, withUsername(fullUserJson, username))
require.NoError(t, err)
return testCase{
@@ -170,7 +169,7 @@ func TestUpdateUser(t *testing.T) {
{
name: "invalid locale",
setup: func(t *testing.T) testCase {
username := gofakeit.Username()
username := integration.Username()
created, err := Instance.Client.SCIM.Users.Create(CTX, Instance.DefaultOrg.Id, withUsername(fullUserJson, username))
require.NoError(t, err)
return testCase{
@@ -195,7 +194,7 @@ func TestUpdateUser(t *testing.T) {
{
name: "full",
setup: func(t *testing.T) testCase {
username := gofakeit.Username()
username := integration.Username()
created, err := Instance.Client.SCIM.Users.Create(CTX, Instance.DefaultOrg.Id, withUsername(fullUserJson, username))
require.NoError(t, err)
return testCase{