Skip to content

Commit 758751e

Browse files
committed
fixup tests
1 parent a5af580 commit 758751e

File tree

9 files changed

+62
-63
lines changed

9 files changed

+62
-63
lines changed

cli/clitest/golden.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"strings"
1212
"testing"
1313

14+
"github.com/google/uuid"
1415
"github.com/stretchr/testify/require"
1516

1617
"github.com/coder/coder/v2/cli/config"

cli/server_createadminuser.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,11 @@ func (r *RootCmd) newCreateAdminUserCommand() *serpent.Command {
8484
validateInputs := func(username, email, password string) error {
8585
// Use the validator tags so we match the API's validation.
8686
req := codersdk.CreateUserRequest{
87-
Username: "username",
88-
Name: "Admin User",
89-
Email: "email@coder.com",
90-
Password: "ValidPa$$word123!",
91-
OrganizationID: uuid.New(),
87+
Username: "username",
88+
Name: "Admin User",
89+
Email: "email@coder.com",
90+
Password: "ValidPa$$word123!",
91+
OrganizationIDs: []uuid.UUID{uuid.New()},
9292
}
9393
if username != "" {
9494
req.Username = username

cli/user_delete_test.go

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"testing"
66

7+
"github.com/google/uuid"
78
"github.com/stretchr/testify/require"
89

910
"github.com/coder/coder/v2/cli/clitest"
@@ -27,12 +28,12 @@ func TestUserDelete(t *testing.T) {
2728
require.NoError(t, err)
2829

2930
_, err = client.CreateUser(ctx, codersdk.CreateUserRequest{
30-
Email: "colin5@coder.com",
31-
Username: "coolin",
32-
Password: pw,
33-
UserLoginType: codersdk.LoginTypePassword,
34-
OrganizationID: owner.OrganizationID,
35-
DisableLogin: false,
31+
Email: "colin5@coder.com",
32+
Username: "coolin",
33+
Password: pw,
34+
UserLoginType: codersdk.LoginTypePassword,
35+
OrganizationIDs: []uuid.UUID{owner.OrganizationID},
36+
DisableLogin: false,
3637
})
3738
require.NoError(t, err)
3839

@@ -58,12 +59,12 @@ func TestUserDelete(t *testing.T) {
5859
require.NoError(t, err)
5960

6061
user, err := client.CreateUser(ctx, codersdk.CreateUserRequest{
61-
Email: "colin5@coder.com",
62-
Username: "coolin",
63-
Password: pw,
64-
UserLoginType: codersdk.LoginTypePassword,
65-
OrganizationID: owner.OrganizationID,
66-
DisableLogin: false,
62+
Email: "colin5@coder.com",
63+
Username: "coolin",
64+
Password: pw,
65+
UserLoginType: codersdk.LoginTypePassword,
66+
OrganizationIDs: []uuid.UUID{owner.OrganizationID},
67+
DisableLogin: false,
6768
})
6869
require.NoError(t, err)
6970

@@ -89,12 +90,12 @@ func TestUserDelete(t *testing.T) {
8990
require.NoError(t, err)
9091

9192
user, err := client.CreateUser(ctx, codersdk.CreateUserRequest{
92-
Email: "colin5@coder.com",
93-
Username: "coolin",
94-
Password: pw,
95-
UserLoginType: codersdk.LoginTypePassword,
96-
OrganizationID: owner.OrganizationID,
97-
DisableLogin: false,
93+
Email: "colin5@coder.com",
94+
Username: "coolin",
95+
Password: pw,
96+
UserLoginType: codersdk.LoginTypePassword,
97+
OrganizationIDs: []uuid.UUID{owner.OrganizationID},
98+
DisableLogin: false,
9899
})
99100
require.NoError(t, err)
100101

cli/usercreate.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"strings"
66

77
"github.com/go-playground/validator/v10"
8+
"github.com/google/uuid"
89
"golang.org/x/xerrors"
910

1011
"github.com/coder/pretty"
@@ -95,12 +96,12 @@ func (r *RootCmd) userCreate() *serpent.Command {
9596
}
9697

9798
_, err = client.CreateUser(inv.Context(), codersdk.CreateUserRequest{
98-
Email: email,
99-
Username: username,
100-
Name: name,
101-
Password: password,
102-
OrganizationID: organization.ID,
103-
UserLoginType: userLoginType,
99+
Email: email,
100+
Username: username,
101+
Name: name,
102+
Password: password,
103+
OrganizationIDs: []uuid.UUID{organization.ID},
104+
UserLoginType: userLoginType,
104105
})
105106
if err != nil {
106107
return err

coderd/workspaceapps/apptest/apptest.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1207,10 +1207,10 @@ func Run(t *testing.T, appHostIsPrimary bool, factory DeploymentFactory) {
12071207
// since they have access to everything.
12081208
ownerClient = appDetails.SDKClient
12091209
user, err := ownerClient.CreateUser(ctx, codersdk.CreateUserRequest{
1210-
Email: "user@coder.com",
1211-
Username: "user",
1212-
Password: password,
1213-
OrganizationID: appDetails.FirstUser.OrganizationID,
1210+
Email: "user@coder.com",
1211+
Username: "user",
1212+
Password: password,
1213+
OrganizationIDs: []uuid.UUID{appDetails.FirstUser.OrganizationID},
12141214
})
12151215
require.NoError(t, err)
12161216

@@ -1259,10 +1259,10 @@ func Run(t *testing.T, appHostIsPrimary bool, factory DeploymentFactory) {
12591259
})
12601260
require.NoError(t, err)
12611261
userInOtherOrg, err := ownerClient.CreateUser(ctx, codersdk.CreateUserRequest{
1262-
Email: "no-template-access@coder.com",
1263-
Username: "no-template-access",
1264-
Password: password,
1265-
OrganizationID: otherOrg.ID,
1262+
Email: "no-template-access@coder.com",
1263+
Username: "no-template-access",
1264+
Password: password,
1265+
OrganizationIDs: []uuid.UUID{otherOrg.ID},
12661266
})
12671267
require.NoError(t, err)
12681268

enterprise/coderd/groups_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -758,10 +758,10 @@ func TestGroup(t *testing.T) {
758758

759759
// cannot explicitly set a dormant user status so must create a new user
760760
anotherUser, err := userAdminClient.CreateUser(ctx, codersdk.CreateUserRequest{
761-
Email: "coder@coder.com",
762-
Username: "coder",
763-
Password: "SomeStrongPassword!",
764-
OrganizationID: user.OrganizationID,
761+
Email: "coder@coder.com",
762+
Username: "coder",
763+
Password: "SomeStrongPassword!",
764+
OrganizationIDs: []uuid.UUID{user.OrganizationID},
765765
})
766766
require.NoError(t, err)
767767

enterprise/coderd/scim.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -234,9 +234,9 @@ func (api *API) scimPostUser(rw http.ResponseWriter, r *http.Request) {
234234
//nolint:gocritic // needed for SCIM
235235
dbUser, err = api.AGPL.CreateUser(dbauthz.AsSystemRestricted(ctx), api.Database, agpl.CreateUserRequest{
236236
CreateUserRequest: codersdk.CreateUserRequest{
237-
Username: sUser.UserName,
238-
Email: email,
239-
OrganizationID: defaultOrganization.ID,
237+
Username: sUser.UserName,
238+
Email: email,
239+
OrganizationIDs: []uuid.UUID{defaultOrganization.ID},
240240
},
241241
LoginType: database.LoginTypeOIDC,
242242
// Do not send notifications to user admins as SCIM endpoint might be called sequentially to all users.

enterprise/coderd/users_test.go

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
"time"
88

99
"github.com/google/uuid"
10-
"github.com/stretchr/testify/assert"
1110
"github.com/stretchr/testify/require"
1211

1312
"github.com/coder/coder/v2/coderd/coderdtest"
@@ -510,10 +509,10 @@ func TestEnterprisePostUser(t *testing.T) {
510509
})
511510

512511
_, err := notInOrg.CreateUser(ctx, codersdk.CreateUserRequest{
513-
Email: "some@domain.com",
514-
Username: "anotheruser",
515-
Password: "SomeSecurePassword!",
516-
OrganizationID: org.ID,
512+
Email: "some@domain.com",
513+
Username: "anotheruser",
514+
Password: "SomeSecurePassword!",
515+
OrganizationIDs: []uuid.UUID{org.ID},
517516
})
518517
var apiErr *codersdk.Error
519518
require.ErrorAs(t, err, &apiErr)
@@ -544,10 +543,10 @@ func TestEnterprisePostUser(t *testing.T) {
544543
org := coderdenttest.CreateOrganization(t, other, coderdenttest.CreateOrganizationOptions{})
545544

546545
_, err := notInOrg.CreateUser(ctx, codersdk.CreateUserRequest{
547-
Email: "some@domain.com",
548-
Username: "anotheruser",
549-
Password: "SomeSecurePassword!",
550-
OrganizationID: org.ID,
546+
Email: "some@domain.com",
547+
Username: "anotheruser",
548+
Password: "SomeSecurePassword!",
549+
OrganizationIDs: []uuid.UUID{org.ID},
551550
})
552551
var apiErr *codersdk.Error
553552
require.ErrorAs(t, err, &apiErr)
@@ -559,7 +558,7 @@ func TestEnterprisePostUser(t *testing.T) {
559558
dv := coderdtest.DeploymentValues(t)
560559
dv.Experiments = []string{string(codersdk.ExperimentMultiOrganization)}
561560

562-
client, firstUser := coderdenttest.New(t, &coderdenttest.Options{
561+
client, _ := coderdenttest.New(t, &coderdenttest.Options{
563562
Options: &coderdtest.Options{
564563
DeploymentValues: dv,
565564
},
@@ -578,14 +577,11 @@ func TestEnterprisePostUser(t *testing.T) {
578577

579578
// nolint:gocritic // intentional using the owner.
580579
// Manually making a user with the request instead of the coderdtest util
581-
user, err := client.CreateUser(ctx, codersdk.CreateUserRequest{
580+
_, err := client.CreateUser(ctx, codersdk.CreateUserRequest{
582581
Email: "another@user.org",
583582
Username: "someone-else",
584583
Password: "SomeSecurePassword!",
585584
})
586-
require.NoError(t, err)
587-
588-
require.Len(t, user.OrganizationIDs, 1)
589-
assert.Equal(t, firstUser.OrganizationID, user.OrganizationIDs[0])
585+
require.ErrorContains(t, err, "No organization specified")
590586
})
591587
}

scaletest/createworkspaces/run.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,10 @@ func (r *Runner) Run(ctx context.Context, id string, logs io.Writer) error {
7373
_, _ = fmt.Fprintln(logs, "Creating user:")
7474

7575
user, err = r.client.CreateUser(ctx, codersdk.CreateUserRequest{
76-
OrganizationID: r.cfg.User.OrganizationID,
77-
Username: r.cfg.User.Username,
78-
Email: r.cfg.User.Email,
79-
Password: password,
76+
OrganizationIDs: []uuid.UUID{r.cfg.User.OrganizationID},
77+
Username: r.cfg.User.Username,
78+
Email: r.cfg.User.Email,
79+
Password: password,
8080
})
8181
if err != nil {
8282
return xerrors.Errorf("create user: %w", err)

0 commit comments

Comments
 (0)