chore(testutil): add testutil.GetRandomName that does not return duplicates (#14020)

Fixes #13910

Adds testutil.GetRandomName that replaces namesgenerator.GetRandomName but instead appends a monotonically increasing integer instead of a number between 1 and 10.
This commit is contained in:
Cian Johnston
2024-07-26 09:44:34 +01:00
committed by GitHub
parent 96011e1b29
commit 37a859f071
5 changed files with 78 additions and 56 deletions

View File

@ -4,11 +4,11 @@ import (
"strings"
"testing"
"github.com/moby/moby/pkg/namesgenerator"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/coder/coder/v2/coderd/httpapi"
"github.com/coder/coder/v2/testutil"
)
func TestUsernameValid(t *testing.T) {
@ -168,7 +168,7 @@ func TestGeneratedTemplateVersionNameValid(t *testing.T) {
t.Parallel()
for i := 0; i < 1000; i++ {
name := namesgenerator.GetRandomName(1)
name := testutil.GetRandomName(t)
err := httpapi.TemplateVersionNameValid(name)
require.NoError(t, err, "invalid template version name: %s", name)
}