Skip to content

Commit 409e2c7

Browse files
fix: use random names for TestUpdateUserProfile (coder#15868)
Fixes a flake seen in https://github.com/coder/coder/actions/runs/12346801529/job/34452940351 It's possible but exceedingly rare for the randomly generated username to be exactly 32 characters. Then, appending a `1` to that username causes the username to be invalid and the test to fail. Instead of appending we'll just generate a new username that is <=32 characters. The `UpdateSelf` subtest has the same appending, but uses a fixed username that is less than 32 characters, so it doesn't need to be changed.
1 parent c92f480 commit 409e2c7

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

coderd/users_test.go

+7-5
Original file line numberDiff line numberDiff line change
@@ -1005,22 +1005,24 @@ func TestUpdateUserProfile(t *testing.T) {
10051005
firstUser := coderdtest.CreateFirstUser(t, client)
10061006
numLogs++ // add an audit log for login
10071007

1008-
memberClient, memberUser := coderdtest.CreateAnotherUser(t, client, firstUser.OrganizationID)
1008+
memberClient, _ := coderdtest.CreateAnotherUser(t, client, firstUser.OrganizationID)
10091009
numLogs++ // add an audit log for user creation
10101010

10111011
ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong)
10121012
defer cancel()
10131013

1014+
newUsername := coderdtest.RandomUsername(t)
1015+
newName := coderdtest.RandomName(t)
10141016
userProfile, err := memberClient.UpdateUserProfile(ctx, codersdk.Me, codersdk.UpdateUserProfileRequest{
1015-
Username: memberUser.Username + "1",
1016-
Name: memberUser.Name + "1",
1017+
Username: newUsername,
1018+
Name: newName,
10171019
})
10181020
numLogs++ // add an audit log for user update
10191021
numLogs++ // add an audit log for API key creation
10201022

10211023
require.NoError(t, err)
1022-
require.Equal(t, memberUser.Username+"1", userProfile.Username)
1023-
require.Equal(t, memberUser.Name+"1", userProfile.Name)
1024+
require.Equal(t, newUsername, userProfile.Username)
1025+
require.Equal(t, newName, userProfile.Name)
10241026

10251027
require.Len(t, auditor.AuditLogs(), numLogs)
10261028
require.Equal(t, database.AuditActionWrite, auditor.AuditLogs()[numLogs-1].Action)

0 commit comments

Comments
 (0)