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

@ -10,7 +10,6 @@ import (
"time"
"github.com/google/uuid"
"github.com/moby/moby/pkg/namesgenerator"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
@ -204,7 +203,7 @@ func TestWorkspaceProxyCRUD(t *testing.T) {
})
ctx := testutil.Context(t, testutil.WaitLong)
proxyRes, err := client.CreateWorkspaceProxy(ctx, codersdk.CreateWorkspaceProxyRequest{
Name: namesgenerator.GetRandomName(1),
Name: testutil.GetRandomName(t),
Icon: "/emojis/flag.png",
})
require.NoError(t, err)
@ -217,9 +216,9 @@ func TestWorkspaceProxyCRUD(t *testing.T) {
require.NotEmpty(t, proxyRes.ProxyToken)
// Update the proxy
expName := namesgenerator.GetRandomName(1)
expDisplayName := namesgenerator.GetRandomName(1)
expIcon := namesgenerator.GetRandomName(1)
expName := testutil.GetRandomName(t)
expDisplayName := testutil.GetRandomName(t)
expIcon := testutil.GetRandomName(t)
_, err = client.PatchWorkspaceProxy(ctx, codersdk.PatchWorkspaceProxy{
ID: proxyRes.Proxy.ID,
Name: expName,
@ -247,7 +246,7 @@ func TestWorkspaceProxyCRUD(t *testing.T) {
})
ctx := testutil.Context(t, testutil.WaitLong)
proxyRes, err := client.CreateWorkspaceProxy(ctx, codersdk.CreateWorkspaceProxyRequest{
Name: namesgenerator.GetRandomName(1),
Name: testutil.GetRandomName(t),
Icon: "/emojis/flag.png",
})
require.NoError(t, err)
@ -639,7 +638,7 @@ func TestIssueSignedAppToken(t *testing.T) {
createProxyCtx := testutil.Context(t, testutil.WaitLong)
proxyRes, err := client.CreateWorkspaceProxy(createProxyCtx, codersdk.CreateWorkspaceProxyRequest{
Name: namesgenerator.GetRandomName(1),
Name: testutil.GetRandomName(t),
Icon: "/emojis/flag.png",
})
require.NoError(t, err)
@ -731,11 +730,11 @@ func TestReconnectingPTYSignedToken(t *testing.T) {
_ = agenttest.New(t, client.URL, authToken)
_ = coderdtest.AwaitWorkspaceAgents(t, client, workspace.ID)
proxyURL, err := url.Parse(fmt.Sprintf("https://%s.com", namesgenerator.GetRandomName(1)))
proxyURL, err := url.Parse(fmt.Sprintf("https://%s.com", testutil.GetRandomName(t)))
require.NoError(t, err)
_ = coderdenttest.NewWorkspaceProxyReplica(t, api, client, &coderdenttest.ProxyOptions{
Name: namesgenerator.GetRandomName(1),
Name: testutil.GetRandomName(t),
ProxyURL: proxyURL,
AppHostname: "*.sub.example.com",
})