Replace the external moby/moby/pkg/namesgenerator dependency with an
internal implementation using gofakeit/v7. The moby package has ~25k
unique name combinations, and with its retry parameter only adds a
random digit 0-9, giving ~250k possibilities. In parallel tests, this
has led to collisions (flakes).
The new internal API at coderd/util/namesgenerator eliminates the
external dependnecy and offers functions with explicit uniqueness
guarantees. This PR also consolidates fragmented name generation in a
few places to use the new package.
| Old (moby/moby) | New |
|-------------------------------------|------------------------|
| namesgenerator.GetRandomName(0) | NameWith("_") |
| namesgenerator.GetRandomName(>0) | NameDigitWith("_") |
| testutil.GetRandomName(t) | UniqueName() |
| testutil.GetRandomNameHyphenated(t) | UniqueNameWith("-") |
namesgenerator package API:
- NameWith(delim): random name, not unique
- NameDigitWith(delim): random name with 1-9 suffix, not unique
- UniqueName(): guaranteed unique via atomic counter
- UniqueNameWith(delim): unique with custom delimiter
Names continue to be docker style `[adjective][delim][surname]`. Unique
names are truncated to 32 characters (preserving the numeric suffix) to
fit common name length limits in Coder.
Related test flakes:
https://github.com/coder/internal/issues/1212https://github.com/coder/internal/issues/118https://github.com/coder/internal/issues/1068
Fixes flakes like the following:
```
workspaces_test.go:4938:
Error Trace: /home/runner/work/coder/coder/coderd/coderdtest/coderdtest.go:1279
/home/runner/work/coder/coder/coderd/workspaces_test.go:4938
/home/runner/work/coder/coder/coderd/workspaces_test.go:5044
Error: Received unexpected error:
POST http://127.0.0.1:42597/api/v2/users/me/workspaces: unexpected status code 409: Workspace "romantic-mcclintock" already exists.
name: This value is already in use and should be unique.
Test: TestWorkspaceCreateWithImplicitPreset/SinglePresetWithParameters
```
https://github.com/coder/coder/actions/runs/17142665868/job/48633017007?pr=19464
Which are caused by insufficient randomness when creating multiple
workspaces with random names. Two words is not enough to avoid flakes.
We have a `testutil.GetRandomName` function that appends a monotonically
increasing integer, but this alternative function that uses hyphens
doesn't add that integer. This PR fixes that by just
`testutil.GetRandomName`
Fixes#13910
Adds testutil.GetRandomName that replaces namesgenerator.GetRandomName but instead appends a monotonically increasing integer instead of a number between 1 and 10.