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
+19 -15
View File
@@ -18,31 +18,35 @@ func TestProtoPortRangeParsing(t *testing.T) {
return PortRange{First: s, Last: e}
}
tests := []struct {
in string
out ProtoPortRange
err error
name string
in string
out ProtoPortRange
err error
}{
{in: "tcp:80", out: ProtoPortRange{Proto: int(ipproto.TCP), Ports: pr(80, 80)}},
{in: "80", out: ProtoPortRange{Ports: pr(80, 80)}},
{in: "*", out: ProtoPortRange{Ports: PortRangeAny}},
{in: "*:*", out: ProtoPortRange{Ports: PortRangeAny}},
{in: "tcp:*", out: ProtoPortRange{Proto: int(ipproto.TCP), Ports: PortRangeAny}},
{name: "tcp-80", in: "tcp:80", out: ProtoPortRange{Proto: int(ipproto.TCP), Ports: pr(80, 80)}},
{name: "80", in: "80", out: ProtoPortRange{Ports: pr(80, 80)}},
{name: "star", in: "*", out: ProtoPortRange{Ports: PortRangeAny}},
{name: "star-star", in: "*:*", out: ProtoPortRange{Ports: PortRangeAny}},
{name: "tcp-star", in: "tcp:*", out: ProtoPortRange{Proto: int(ipproto.TCP), Ports: PortRangeAny}},
{
in: "tcp:",
err: vizerror.Errorf("invalid port list: %#v", ""),
name: "tcp-empty-port",
in: "tcp:",
err: vizerror.Errorf("invalid port list: %#v", ""),
},
{
in: ":80",
err: errEmptyProtocol,
name: "empty-proto-80",
in: ":80",
err: errEmptyProtocol,
},
{
in: "",
err: errEmptyString,
name: "empty-string",
in: "",
err: errEmptyString,
},
}
for _, tc := range tests {
t.Run(tc.in, func(t *testing.T) {
t.Run(tc.name, func(t *testing.T) {
var ppr ProtoPortRange
err := ppr.UnmarshalText([]byte(tc.in))
if tc.err != err {
+2 -2
View File
@@ -841,12 +841,12 @@ func TestMarshalToRawMessageAndBack(t *testing.T) {
capType: PeerCapability("foo"),
},
{
name: "some values",
name: "some-values",
val: testRule{Ports: []int{80, 443}, Name: "foo"},
capType: PeerCapability("foo"),
},
{
name: "all values",
name: "all-values",
val: testRule{Ports: []int{80, 443}, Name: "foo", ToggleOn: true, Groups: inner{Groups: []string{"foo", "bar"}}, Addrs: []netip.AddrPort{testip}},
capType: PeerCapability("foo"),
},