Skip to content

fix: increase workspace name randomess in tests #7018

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 6, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions coderd/coderdtest/coderdtest.go
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ func CreateAnotherUser(t *testing.T, client *codersdk.Client, organizationID uui
func createAnotherUserRetry(t *testing.T, client *codersdk.Client, organizationID uuid.UUID, retries int, roles ...string) (*codersdk.Client, codersdk.User) {
req := codersdk.CreateUserRequest{
Email: namesgenerator.GetRandomName(10) + "@coder.com",
Username: randomUsername(),
Username: randomUsername(t),
Password: "SomeSecurePassword!",
OrganizationID: organizationID,
}
Expand Down Expand Up @@ -589,8 +589,8 @@ func CreateWorkspaceBuild(
// compatibility with testing. The name assigned is randomly generated.
func CreateTemplate(t *testing.T, client *codersdk.Client, organization uuid.UUID, version uuid.UUID, mutators ...func(*codersdk.CreateTemplateRequest)) codersdk.Template {
req := codersdk.CreateTemplateRequest{
Name: randomUsername(),
Description: randomUsername(),
Name: randomUsername(t),
Description: randomUsername(t),
VersionID: version,
}
for _, mut := range mutators {
Expand Down Expand Up @@ -709,7 +709,7 @@ func CreateWorkspace(t *testing.T, client *codersdk.Client, organization uuid.UU
t.Helper()
req := codersdk.CreateWorkspaceRequest{
TemplateID: templateID,
Name: randomUsername(),
Name: randomUsername(t),
AutostartSchedule: ptr.Ref("CRON_TZ=US/Central 30 9 * * 1-5"),
TTLMillis: ptr.Ref((8 * time.Hour).Milliseconds()),
}
Expand Down Expand Up @@ -1065,8 +1065,10 @@ func NewAzureInstanceIdentity(t *testing.T, instanceID string) (x509.VerifyOptio
}
}

func randomUsername() string {
return strings.ReplaceAll(namesgenerator.GetRandomName(10), "_", "-")
func randomUsername(t testing.TB) string {
suffix, err := cryptorand.String(3)
require.NoError(t, err)
return strings.ReplaceAll(namesgenerator.GetRandomName(10), "_", "-") + "-" + suffix
}

// Used to easily create an HTTP transport!
Expand Down