cmd/vet: add subtestnames analyzer; fix all existing violations

Add a new vet analyzer that checks t.Run subtest names don't contain
characters requiring quoting when re-running via "go test -run". This
enforces the style guide rule: don't use spaces or punctuation in
subtest names.

The analyzer flags:
- Direct t.Run calls with string literal names containing spaces,
  regex metacharacters, quotes, or other problematic characters
- Table-driven t.Run(tt.name, ...) calls where tt ranges over a
  slice/map literal with bad name field values

Also fix all 978 existing violations across 81 test files, replacing
spaces with hyphens and shortening long sentence-like names to concise
hyphenated forms.

Updates #19242

Change-Id: Ib0ad96a111bd8e764582d1d4902fe2599454ab65
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
This commit is contained in:
Brad Fitzpatrick
2026-04-04 21:32:14 +00:00
committed by Brad Fitzpatrick
parent 0f02c20c5e
commit 5ef3713c9f
87 changed files with 1405 additions and 982 deletions
+65 -65
View File
@@ -22,7 +22,7 @@ func TestClockWithDefinedStartTime(t *testing.T) {
wants []time.Time // The return values of sequential calls to Now().
}{
{
name: "increment ms",
name: "increment-ms",
start: time.Unix(12345, 1000),
step: 1000,
wants: []time.Time{
@@ -33,7 +33,7 @@ func TestClockWithDefinedStartTime(t *testing.T) {
},
},
{
name: "increment second",
name: "increment-second",
start: time.Unix(12345, 1000),
step: time.Second,
wants: []time.Time{
@@ -44,7 +44,7 @@ func TestClockWithDefinedStartTime(t *testing.T) {
},
},
{
name: "no increment",
name: "no-increment",
start: time.Unix(12345, 1000),
wants: []time.Time{
time.Unix(12345, 1000),
@@ -91,7 +91,7 @@ func TestClockWithDefaultStartTime(t *testing.T) {
wants []time.Duration // The return values of sequential calls to Now() after added to Start()
}{
{
name: "increment ms",
name: "increment-ms",
step: 1000,
wants: []time.Duration{
0,
@@ -101,7 +101,7 @@ func TestClockWithDefaultStartTime(t *testing.T) {
},
},
{
name: "increment second",
name: "increment-second",
step: time.Second,
wants: []time.Duration{
0 * time.Second,
@@ -111,7 +111,7 @@ func TestClockWithDefaultStartTime(t *testing.T) {
},
},
{
name: "no increment",
name: "no-increment",
wants: []time.Duration{0, 0, 0, 0},
},
}
@@ -177,7 +177,7 @@ func TestClockSetStep(t *testing.T) {
wants []time.Time // The return values of sequential calls to Now().
}{
{
name: "increment ms then s",
name: "increment-ms-then-s",
start: time.Unix(12345, 1000),
step: 1000,
stepChanges: []stepInfo{
@@ -198,7 +198,7 @@ func TestClockSetStep(t *testing.T) {
},
},
{
name: "multiple changes over time",
name: "multiple-changes-over-time",
start: time.Unix(12345, 1000),
step: 1,
stepChanges: []stepInfo{
@@ -227,7 +227,7 @@ func TestClockSetStep(t *testing.T) {
},
},
{
name: "multiple changes at once",
name: "multiple-changes-at-once",
start: time.Unix(12345, 1000),
step: 1,
stepChanges: []stepInfo{
@@ -252,7 +252,7 @@ func TestClockSetStep(t *testing.T) {
},
},
{
name: "changes at start",
name: "changes-at-start",
start: time.Unix(12345, 1000),
step: 0,
stepChanges: []stepInfo{
@@ -325,7 +325,7 @@ func TestClockAdvance(t *testing.T) {
wants []time.Time // The return values of sequential calls to Now().
}{
{
name: "increment ms then advance 1s",
name: "increment-ms-then-advance-1s",
start: time.Unix(12345, 1000),
step: 1000,
advances: []advanceInfo{
@@ -346,7 +346,7 @@ func TestClockAdvance(t *testing.T) {
},
},
{
name: "multiple advances over time",
name: "multiple-advances-over-time",
start: time.Unix(12345, 1000),
step: 1,
advances: []advanceInfo{
@@ -375,7 +375,7 @@ func TestClockAdvance(t *testing.T) {
},
},
{
name: "multiple advances at once",
name: "multiple-advances-at-once",
start: time.Unix(12345, 1000),
step: 1,
advances: []advanceInfo{
@@ -400,7 +400,7 @@ func TestClockAdvance(t *testing.T) {
},
},
{
name: "changes at start",
name: "changes-at-start",
start: time.Unix(12345, 1000),
step: 5,
advances: []advanceInfo{
@@ -489,7 +489,7 @@ func TestSingleTicker(t *testing.T) {
steps []testStep
}{
{
name: "no tick advance",
name: "no-tick-advance",
start: time.Unix(12345, 0),
period: time.Second,
steps: []testStep{
@@ -500,7 +500,7 @@ func TestSingleTicker(t *testing.T) {
},
},
{
name: "no tick step",
name: "no-tick-step",
start: time.Unix(12345, 0),
step: time.Second - 1,
period: time.Second,
@@ -514,7 +514,7 @@ func TestSingleTicker(t *testing.T) {
},
},
{
name: "single tick advance exact",
name: "single-tick-advance-exact",
start: time.Unix(12345, 0),
period: time.Second,
steps: []testStep{
@@ -526,7 +526,7 @@ func TestSingleTicker(t *testing.T) {
},
},
{
name: "single tick advance extra",
name: "single-tick-advance-extra",
start: time.Unix(12345, 0),
period: time.Second,
steps: []testStep{
@@ -538,7 +538,7 @@ func TestSingleTicker(t *testing.T) {
},
},
{
name: "single tick step exact",
name: "single-tick-step-exact",
start: time.Unix(12345, 0),
step: time.Second,
period: time.Second,
@@ -553,7 +553,7 @@ func TestSingleTicker(t *testing.T) {
},
},
{
name: "single tick step extra",
name: "single-tick-step-extra",
start: time.Unix(12345, 0),
step: time.Second + 1,
period: time.Second,
@@ -568,7 +568,7 @@ func TestSingleTicker(t *testing.T) {
},
},
{
name: "single tick per advance",
name: "single-tick-per-advance",
start: time.Unix(12345, 0),
period: 3 * time.Second,
steps: []testStep{
@@ -597,7 +597,7 @@ func TestSingleTicker(t *testing.T) {
},
},
{
name: "single tick per step",
name: "single-tick-per-step",
start: time.Unix(12345, 0),
step: 2 * time.Second,
period: 3 * time.Second,
@@ -626,7 +626,7 @@ func TestSingleTicker(t *testing.T) {
},
},
{
name: "multiple tick per advance",
name: "multiple-tick-per-advance",
start: time.Unix(12345, 0),
period: time.Second,
channelSize: 3,
@@ -655,7 +655,7 @@ func TestSingleTicker(t *testing.T) {
},
},
{
name: "multiple tick per step",
name: "multiple-tick-per-step",
start: time.Unix(12345, 0),
step: 3 * time.Second,
period: 2 * time.Second,
@@ -723,7 +723,7 @@ func TestSingleTicker(t *testing.T) {
},
},
{
name: "reset while running",
name: "reset-while-running",
start: time.Unix(12345, 0),
period: 2 * time.Second,
steps: []testStep{
@@ -763,7 +763,7 @@ func TestSingleTicker(t *testing.T) {
},
},
{
name: "reset while stopped",
name: "reset-while-stopped",
start: time.Unix(12345, 0),
step: time.Second,
period: 2 * time.Second,
@@ -803,7 +803,7 @@ func TestSingleTicker(t *testing.T) {
},
},
{
name: "reset absolute",
name: "reset-absolute",
start: time.Unix(12345, 0),
step: time.Second,
period: 2 * time.Second,
@@ -841,7 +841,7 @@ func TestSingleTicker(t *testing.T) {
},
},
{
name: "follow real time",
name: "follow-real-time",
realTimeOpts: new(ClockOpts),
start: time.Unix(12345, 0),
period: 2 * time.Second,
@@ -965,7 +965,7 @@ func TestSingleTimer(t *testing.T) {
steps []testStep
}{
{
name: "no tick advance",
name: "no-tick-advance",
start: time.Unix(12345, 0),
delay: time.Second,
steps: []testStep{
@@ -976,7 +976,7 @@ func TestSingleTimer(t *testing.T) {
},
},
{
name: "no tick step",
name: "no-tick-step",
start: time.Unix(12345, 0),
step: time.Second - 1,
delay: time.Second,
@@ -990,7 +990,7 @@ func TestSingleTimer(t *testing.T) {
},
},
{
name: "single tick advance exact",
name: "single-tick-advance-exact",
start: time.Unix(12345, 0),
delay: time.Second,
steps: []testStep{
@@ -1006,7 +1006,7 @@ func TestSingleTimer(t *testing.T) {
},
},
{
name: "single tick advance extra",
name: "single-tick-advance-extra",
start: time.Unix(12345, 0),
delay: time.Second,
steps: []testStep{
@@ -1022,7 +1022,7 @@ func TestSingleTimer(t *testing.T) {
},
},
{
name: "single tick step exact",
name: "single-tick-step-exact",
start: time.Unix(12345, 0),
step: time.Second,
delay: time.Second,
@@ -1040,7 +1040,7 @@ func TestSingleTimer(t *testing.T) {
},
},
{
name: "single tick step extra",
name: "single-tick-step-extra",
start: time.Unix(12345, 0),
step: time.Second + 1,
delay: time.Second,
@@ -1058,7 +1058,7 @@ func TestSingleTimer(t *testing.T) {
},
},
{
name: "reset for single tick per advance",
name: "reset-for-single-tick-per-advance",
start: time.Unix(12345, 0),
delay: 3 * time.Second,
steps: []testStep{
@@ -1093,7 +1093,7 @@ func TestSingleTimer(t *testing.T) {
},
},
{
name: "reset for single tick per step",
name: "reset-for-single-tick-per-step",
start: time.Unix(12345, 0),
step: 2 * time.Second,
delay: 3 * time.Second,
@@ -1124,7 +1124,7 @@ func TestSingleTimer(t *testing.T) {
},
},
{
name: "reset while active",
name: "reset-while-active",
start: time.Unix(12345, 0),
step: 2 * time.Second,
delay: 3 * time.Second,
@@ -1155,7 +1155,7 @@ func TestSingleTimer(t *testing.T) {
},
},
{
name: "stop after fire",
name: "stop-after-fire",
start: time.Unix(12345, 0),
step: 2 * time.Second,
delay: time.Second,
@@ -1181,7 +1181,7 @@ func TestSingleTimer(t *testing.T) {
},
},
{
name: "stop before fire",
name: "stop-before-fire",
start: time.Unix(12345, 0),
step: 2 * time.Second,
delay: time.Second,
@@ -1207,7 +1207,7 @@ func TestSingleTimer(t *testing.T) {
},
},
{
name: "stop after reset",
name: "stop-after-reset",
start: time.Unix(12345, 0),
step: 2 * time.Second,
delay: time.Second,
@@ -1235,7 +1235,7 @@ func TestSingleTimer(t *testing.T) {
},
},
{
name: "reset while running",
name: "reset-while-running",
start: time.Unix(12345, 0),
delay: 2 * time.Second,
steps: []testStep{
@@ -1275,7 +1275,7 @@ func TestSingleTimer(t *testing.T) {
},
},
{
name: "reset while stopped",
name: "reset-while-stopped",
start: time.Unix(12345, 0),
step: time.Second,
delay: 2 * time.Second,
@@ -1310,7 +1310,7 @@ func TestSingleTimer(t *testing.T) {
},
},
{
name: "reset absolute",
name: "reset-absolute",
start: time.Unix(12345, 0),
step: time.Second,
delay: 2 * time.Second,
@@ -1344,7 +1344,7 @@ func TestSingleTimer(t *testing.T) {
},
},
{
name: "follow real time",
name: "follow-real-time",
realTimeOpts: new(ClockOpts),
start: time.Unix(12345, 0),
delay: 2 * time.Second,
@@ -1705,7 +1705,7 @@ func TestClockFollowRealTime(t *testing.T) {
wants []time.Time // The return values of sequential calls to Now().
}{
{
name: "increment ms then advance 1s",
name: "increment-ms-then-advance-1s",
start: time.Unix(12345, 1000),
wantStart: time.Unix(12345, 1000),
advances: []advanceInfo{
@@ -1750,7 +1750,7 @@ func TestClockFollowRealTime(t *testing.T) {
},
},
{
name: "multiple advances over time",
name: "multiple-advances-over-time",
start: time.Unix(12345, 1000),
wantStart: time.Unix(12345, 1000),
advances: []advanceInfo{
@@ -1795,7 +1795,7 @@ func TestClockFollowRealTime(t *testing.T) {
},
},
{
name: "multiple advances at once",
name: "multiple-advances-at-once",
start: time.Unix(12345, 1000),
wantStart: time.Unix(12345, 1000),
advances: []advanceInfo{
@@ -1828,7 +1828,7 @@ func TestClockFollowRealTime(t *testing.T) {
},
},
{
name: "changes at start",
name: "changes-at-start",
start: time.Unix(12345, 1000),
wantStart: time.Unix(12345, 1000),
advances: []advanceInfo{
@@ -1861,7 +1861,7 @@ func TestClockFollowRealTime(t *testing.T) {
},
},
{
name: "start from current time",
name: "start-from-current-time",
realTimeClockOpts: ClockOpts{
Start: time.Unix(12345, 0),
},
@@ -1966,7 +1966,7 @@ func TestAfterFunc(t *testing.T) {
steps []testStep
}{
{
name: "no tick advance",
name: "no-tick-advance",
start: time.Unix(12345, 0),
delay: time.Second,
steps: []testStep{
@@ -1977,7 +1977,7 @@ func TestAfterFunc(t *testing.T) {
},
},
{
name: "no tick step",
name: "no-tick-step",
start: time.Unix(12345, 0),
step: time.Second - 1,
delay: time.Second,
@@ -1991,7 +1991,7 @@ func TestAfterFunc(t *testing.T) {
},
},
{
name: "single tick advance exact",
name: "single-tick-advance-exact",
start: time.Unix(12345, 0),
delay: time.Second,
steps: []testStep{
@@ -2007,7 +2007,7 @@ func TestAfterFunc(t *testing.T) {
},
},
{
name: "single tick advance extra",
name: "single-tick-advance-extra",
start: time.Unix(12345, 0),
delay: time.Second,
steps: []testStep{
@@ -2023,7 +2023,7 @@ func TestAfterFunc(t *testing.T) {
},
},
{
name: "single tick step exact",
name: "single-tick-step-exact",
start: time.Unix(12345, 0),
step: time.Second,
delay: time.Second,
@@ -2041,7 +2041,7 @@ func TestAfterFunc(t *testing.T) {
},
},
{
name: "single tick step extra",
name: "single-tick-step-extra",
start: time.Unix(12345, 0),
step: time.Second + 1,
delay: time.Second,
@@ -2059,7 +2059,7 @@ func TestAfterFunc(t *testing.T) {
},
},
{
name: "reset for single tick per advance",
name: "reset-for-single-tick-per-advance",
start: time.Unix(12345, 0),
delay: 3 * time.Second,
steps: []testStep{
@@ -2094,7 +2094,7 @@ func TestAfterFunc(t *testing.T) {
},
},
{
name: "reset for single tick per step",
name: "reset-for-single-tick-per-step",
start: time.Unix(12345, 0),
step: 2 * time.Second,
delay: 3 * time.Second,
@@ -2125,7 +2125,7 @@ func TestAfterFunc(t *testing.T) {
},
},
{
name: "reset while active",
name: "reset-while-active",
start: time.Unix(12345, 0),
step: 2 * time.Second,
delay: 3 * time.Second,
@@ -2156,7 +2156,7 @@ func TestAfterFunc(t *testing.T) {
},
},
{
name: "stop after fire",
name: "stop-after-fire",
start: time.Unix(12345, 0),
step: 2 * time.Second,
delay: time.Second,
@@ -2182,7 +2182,7 @@ func TestAfterFunc(t *testing.T) {
},
},
{
name: "stop before fire",
name: "stop-before-fire",
start: time.Unix(12345, 0),
step: 2 * time.Second,
delay: time.Second,
@@ -2208,7 +2208,7 @@ func TestAfterFunc(t *testing.T) {
},
},
{
name: "stop after reset",
name: "stop-after-reset",
start: time.Unix(12345, 0),
step: 2 * time.Second,
delay: time.Second,
@@ -2236,7 +2236,7 @@ func TestAfterFunc(t *testing.T) {
},
},
{
name: "reset while running",
name: "reset-while-running",
start: time.Unix(12345, 0),
delay: 2 * time.Second,
steps: []testStep{
@@ -2270,7 +2270,7 @@ func TestAfterFunc(t *testing.T) {
},
},
{
name: "reset while stopped",
name: "reset-while-stopped",
start: time.Unix(12345, 0),
step: time.Second,
delay: 2 * time.Second,
@@ -2303,7 +2303,7 @@ func TestAfterFunc(t *testing.T) {
},
},
{
name: "reset absolute",
name: "reset-absolute",
start: time.Unix(12345, 0),
step: time.Second,
delay: 2 * time.Second,
@@ -2333,7 +2333,7 @@ func TestAfterFunc(t *testing.T) {
},
},
{
name: "follow real time",
name: "follow-real-time",
realTimeOpts: new(ClockOpts),
start: time.Unix(12345, 0),
delay: 2 * time.Second,
+2 -2
View File
@@ -355,7 +355,7 @@ func (h *Harness) testDistro(t *testing.T, d Distro, ipm ipMapping) {
})
})
t.Run("tailscale status", func(t *testing.T) {
t.Run("tailscale-status", func(t *testing.T) {
dur := 100 * time.Millisecond
var outp []byte
var err error
@@ -383,7 +383,7 @@ func (h *Harness) testDistro(t *testing.T, d Distro, ipm ipMapping) {
t.Fatalf("error: %v", err)
})
t.Run("dump routes", func(t *testing.T) {
t.Run("dump-routes", func(t *testing.T) {
sess, err := cli.NewSession()
if err != nil {
t.Fatal(err)
+13 -13
View File
@@ -22,7 +22,7 @@ func TestPrintGoroutines(t *testing.T) {
want: "goroutine profile: total 0",
},
{
name: "single goroutine",
name: "single-goroutine",
in: `goroutine profile: total 1
1 @ 0x47bc0e 0x458e57 0x847587 0x483da1
# 0x847586 database/sql.(*DB).connectionOpener+0x86 database/sql/sql.go:1261
@@ -34,7 +34,7 @@ func TestPrintGoroutines(t *testing.T) {
`,
},
{
name: "multiple goroutines sorted",
name: "multiple-goroutines-sorted",
in: `goroutine profile: total 14
7 @ 0x47bc0e 0x413705 0x4132b2 0x10fda4d 0x483da1
# 0x10fda4c github.com/user/pkg.RoutineA+0x16c pkg/a.go:443
@@ -70,7 +70,7 @@ func TestDiffPprofGoroutines(t *testing.T) {
want string
}{
{
name: "no difference",
name: "no-difference",
x: `goroutine profile: total 1
1 @ 0x47bc0e 0x458e57 0x847587 0x483da1
# 0x847586 database/sql.(*DB).connectionOpener+0x86 database/sql/sql.go:1261`,
@@ -81,7 +81,7 @@ func TestDiffPprofGoroutines(t *testing.T) {
want: "",
},
{
name: "different counts",
name: "different-counts",
x: `goroutine profile: total 1
1 @ 0x47bc0e 0x458e57 0x847587 0x483da1
# 0x847586 database/sql.(*DB).connectionOpener+0x86 database/sql/sql.go:1261
@@ -99,7 +99,7 @@ func TestDiffPprofGoroutines(t *testing.T) {
`,
},
{
name: "new goroutine",
name: "new-goroutine",
x: `goroutine profile: total 1
1 @ 0x47bc0e 0x458e57 0x847587 0x483da1
# 0x847586 database/sql.(*DB).connectionOpener+0x86 database/sql/sql.go:1261
@@ -119,7 +119,7 @@ func TestDiffPprofGoroutines(t *testing.T) {
`,
},
{
name: "removed goroutine",
name: "removed-goroutine",
x: `goroutine profile: total 2
1 @ 0x47bc0e 0x458e57 0x847587 0x483da1
# 0x847586 database/sql.(*DB).connectionOpener+0x86 database/sql/sql.go:1261
@@ -139,7 +139,7 @@ func TestDiffPprofGoroutines(t *testing.T) {
`,
},
{
name: "removed many goroutine",
name: "removed-many-goroutine",
x: `goroutine profile: total 2
1 @ 0x47bc0e 0x458e57 0x847587 0x483da1
# 0x847586 database/sql.(*DB).connectionOpener+0x86 database/sql/sql.go:1261
@@ -159,13 +159,13 @@ func TestDiffPprofGoroutines(t *testing.T) {
`,
},
{
name: "invalid input x",
name: "invalid-input-x",
x: "invalid",
y: "goroutine profile: total 0\n",
want: "- invalid\n+ goroutine profile: total 0\n",
},
{
name: "invalid input y",
name: "invalid-input-y",
x: "goroutine profile: total 0\n",
y: "invalid",
want: "- goroutine profile: total 0\n+ invalid\n",
@@ -193,13 +193,13 @@ func TestParseGoroutines(t *testing.T) {
wantCount int
}{
{
name: "empty profile",
name: "empty-profile",
in: "goroutine profile: total 0\n",
wantHeader: "goroutine profile: total 0",
wantCount: 0,
},
{
name: "single goroutine",
name: "single-goroutine",
in: `goroutine profile: total 1
1 @ 0x47bc0e 0x458e57 0x847587 0x483da1
# 0x847586 database/sql.(*DB).connectionOpener+0x86 database/sql/sql.go:1261
@@ -208,7 +208,7 @@ func TestParseGoroutines(t *testing.T) {
wantCount: 1,
},
{
name: "multiple goroutines",
name: "multiple-goroutines",
in: `goroutine profile: total 14
7 @ 0x47bc0e 0x413705 0x4132b2 0x10fda4d 0x483da1
# 0x10fda4c github.com/user/pkg.RoutineA+0x16c pkg/a.go:443
@@ -220,7 +220,7 @@ func TestParseGoroutines(t *testing.T) {
wantCount: 2,
},
{
name: "invalid format",
name: "invalid-format",
in: "invalid",
wantHeader: "invalid",
},