Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c9b2364

Browse files
committed
feat(testutil): add GetRandomNameHyphenated
1 parent c1816e3 commit c9b2364

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

cli/templatepush_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,7 @@ func TestTemplatePush(t *testing.T) {
534534
"test_name": tt.name,
535535
}))
536536

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

539539
inv, root := clitest.New(t, "templates", "push", templateName, "-d", tempDir, "--yes")
540540
clitest.SetupConfig(t, templateAdmin, root)

coderd/templateversions_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -617,7 +617,7 @@ func TestPostTemplateVersionsByOrganization(t *testing.T) {
617617
require.NoError(t, err)
618618

619619
// Create a template version from the archive
620-
tvName := strings.ReplaceAll(testutil.GetRandomName(t), "_", "-")
620+
tvName := testutil.GetRandomNameHyphenated(t)
621621
tv, err := templateAdmin.CreateTemplateVersion(ctx, owner.OrganizationID, codersdk.CreateTemplateVersionRequest{
622622
Name: tvName,
623623
StorageMethod: codersdk.ProvisionerStorageMethodFile,

testutil/names.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package testutil
22

33
import (
44
"strconv"
5+
"strings"
56
"sync/atomic"
67
"testing"
78

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

29+
// GetRandomnameHyphenated is as GetRandomName but uses a hyphen "-" instead of
30+
// an underscore.
31+
func GetRandomNameHyphenated(t testing.TB) string {
32+
t.Helper()
33+
name := namesgenerator.GetRandomName(0)
34+
name = strings.ReplaceAll(name, "_", "-")
35+
return incSuffix(name, n.Add(1), maxNameLen)
36+
}
37+
2838
func incSuffix(s string, num int64, maxLen int) string {
2939
suffix := strconv.FormatInt(num, 10)
3040
if len(s)+len(suffix) <= maxLen {

0 commit comments

Comments
 (0)