Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion cli/templatepush_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@ func TestTemplatePush(t *testing.T) {
"test_name": tt.name,
}))

templateName := strings.ReplaceAll(testutil.GetRandomName(t), "_", "-")
templateName := testutil.GetRandomNameHyphenated(t)

inv, root := clitest.New(t, "templates", "push", templateName, "-d", tempDir, "--yes")
clitest.SetupConfig(t, templateAdmin, root)
Expand Down
2 changes: 1 addition & 1 deletion coderd/templateversions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -617,7 +617,7 @@ func TestPostTemplateVersionsByOrganization(t *testing.T) {
require.NoError(t, err)

// Create a template version from the archive
tvName := strings.ReplaceAll(testutil.GetRandomName(t), "_", "-")
tvName := testutil.GetRandomNameHyphenated(t)
tv, err := templateAdmin.CreateTemplateVersion(ctx, owner.OrganizationID, codersdk.CreateTemplateVersionRequest{
Name: tvName,
StorageMethod: codersdk.ProvisionerStorageMethodFile,
Expand Down
10 changes: 10 additions & 0 deletions testutil/names.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package testutil

import (
"strconv"
"strings"
"sync/atomic"
"testing"

Expand All @@ -25,6 +26,15 @@ func GetRandomName(t testing.TB) string {
return incSuffix(name, n.Add(1), maxNameLen)
}

// GetRandomnameHyphenated is as GetRandomName but uses a hyphen "-" instead of
// an underscore.
func GetRandomNameHyphenated(t testing.TB) string {
t.Helper()
name := namesgenerator.GetRandomName(0)
name = strings.ReplaceAll(name, "_", "-")
return incSuffix(name, n.Add(1), maxNameLen)
}

func incSuffix(s string, num int64, maxLen int) string {
suffix := strconv.FormatInt(num, 10)
if len(s)+len(suffix) <= maxLen {
Expand Down
Loading