Skip to content

Commit a5af580

Browse files
committed
fixup tests to use slice of org ids
1 parent 59b8a78 commit a5af580

File tree

4 files changed

+114
-113
lines changed

4 files changed

+114
-113
lines changed

cli/clitest/golden.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -184,10 +184,10 @@ func prepareTestData(t *testing.T) (*codersdk.Client, map[string]string) {
184184
})
185185
firstUser := coderdtest.CreateFirstUser(t, rootClient)
186186
secondUser, err := rootClient.CreateUser(ctx, codersdk.CreateUserRequest{
187-
Email: "testuser2@coder.com",
188-
Username: "testuser2",
189-
Password: coderdtest.FirstUserParams.Password,
190-
OrganizationID: firstUser.OrganizationID,
187+
Email: "testuser2@coder.com",
188+
Username: "testuser2",
189+
Password: coderdtest.FirstUserParams.Password,
190+
OrganizationIDs: []uuid.UUID{firstUser.OrganizationID},
191191
})
192192
require.NoError(t, err)
193193
version := coderdtest.CreateTemplateVersion(t, rootClient, firstUser.OrganizationID, nil)

coderd/coderdtest/coderdtest.go

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -646,11 +646,11 @@ func CreateFirstUser(t testing.TB, client *codersdk.Client) codersdk.CreateFirst
646646
// CreateAnotherUser creates and authenticates a new user.
647647
// Roles can include org scoped roles with 'roleName:<organization_id>'
648648
func CreateAnotherUser(t testing.TB, client *codersdk.Client, organizationID uuid.UUID, roles ...rbac.RoleIdentifier) (*codersdk.Client, codersdk.User) {
649-
return createAnotherUserRetry(t, client, organizationID, 5, roles)
649+
return createAnotherUserRetry(t, client, []uuid.UUID{organizationID}, 5, roles)
650650
}
651651

652652
func CreateAnotherUserMutators(t testing.TB, client *codersdk.Client, organizationID uuid.UUID, roles []rbac.RoleIdentifier, mutators ...func(r *codersdk.CreateUserRequest)) (*codersdk.Client, codersdk.User) {
653-
return createAnotherUserRetry(t, client, organizationID, 5, roles, mutators...)
653+
return createAnotherUserRetry(t, client, []uuid.UUID{organizationID}, 5, roles, mutators...)
654654
}
655655

656656
// AuthzUserSubject does not include the user's groups.
@@ -676,13 +676,13 @@ func AuthzUserSubject(user codersdk.User, orgID uuid.UUID) rbac.Subject {
676676
}
677677
}
678678

679-
func createAnotherUserRetry(t testing.TB, client *codersdk.Client, organizationID uuid.UUID, retries int, roles []rbac.RoleIdentifier, mutators ...func(r *codersdk.CreateUserRequest)) (*codersdk.Client, codersdk.User) {
679+
func createAnotherUserRetry(t testing.TB, client *codersdk.Client, organizationIDs []uuid.UUID, retries int, roles []rbac.RoleIdentifier, mutators ...func(r *codersdk.CreateUserRequest)) (*codersdk.Client, codersdk.User) {
680680
req := codersdk.CreateUserRequest{
681-
Email: namesgenerator.GetRandomName(10) + "@coder.com",
682-
Username: RandomUsername(t),
683-
Name: RandomName(t),
684-
Password: "SomeSecurePassword!",
685-
OrganizationID: organizationID,
681+
Email: namesgenerator.GetRandomName(10) + "@coder.com",
682+
Username: RandomUsername(t),
683+
Name: RandomName(t),
684+
Password: "SomeSecurePassword!",
685+
OrganizationIDs: organizationIDs,
686686
}
687687
for _, m := range mutators {
688688
m(&req)
@@ -694,7 +694,7 @@ func createAnotherUserRetry(t testing.TB, client *codersdk.Client, organizationI
694694
if err != nil && retries >= 0 && xerrors.As(err, &apiError) {
695695
if apiError.StatusCode() == http.StatusConflict {
696696
retries--
697-
return createAnotherUserRetry(t, client, organizationID, retries, roles)
697+
return createAnotherUserRetry(t, client, organizationIDs, retries, roles)
698698
}
699699
}
700700
require.NoError(t, err)
@@ -763,8 +763,9 @@ func createAnotherUserRetry(t testing.TB, client *codersdk.Client, organizationI
763763
require.NoError(t, err, "update site roles")
764764

765765
// isMember keeps track of which orgs the user was added to as a member
766-
isMember := map[uuid.UUID]bool{
767-
organizationID: true,
766+
isMember := make(map[uuid.UUID]bool)
767+
for _, orgID := range organizationIDs {
768+
isMember[orgID] = true
768769
}
769770

770771
// Update org roles

coderd/userauth_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1471,10 +1471,10 @@ func TestUserLogout(t *testing.T) {
14711471
password = "SomeSecurePassword123!"
14721472
)
14731473
newUser, err := client.CreateUser(ctx, codersdk.CreateUserRequest{
1474-
Email: email,
1475-
Username: username,
1476-
Password: password,
1477-
OrganizationID: firstUser.OrganizationID,
1474+
Email: email,
1475+
Username: username,
1476+
Password: password,
1477+
OrganizationIDs: []uuid.UUID{firstUser.OrganizationID},
14781478
})
14791479
require.NoError(t, err)
14801480

0 commit comments

Comments
 (0)