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

@ -7,13 +7,13 @@ import (
"net/url"
"testing"
"github.com/moby/moby/pkg/namesgenerator"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"golang.org/x/oauth2"
"github.com/coder/coder/v2/coderd/httpmw"
"github.com/coder/coder/v2/codersdk"
"github.com/coder/coder/v2/testutil"
)
type testOAuth2Provider struct {
@ -128,7 +128,7 @@ func TestOAuth2(t *testing.T) {
})
t.Run("PresetConvertState", func(t *testing.T) {
t.Parallel()
customState := namesgenerator.GetRandomName(1)
customState := testutil.GetRandomName(t)
req := httptest.NewRequest("GET", "/?oidc_merge_state="+customState+"&redirect="+url.QueryEscape("/dashboard"), nil)
res := httptest.NewRecorder()
tp := newTestOAuth2Provider(t, oauth2.AccessTypeOffline)