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
+12 -12
View File
@@ -13,12 +13,12 @@ func TestEscape(t *testing.T) {
name, input, want string
}{
{
name: "no illegal chars",
name: "no-illegal-chars",
input: "/home/user",
want: "/home/user",
},
{
name: "empty string",
name: "empty-string",
input: "",
want: "\"\"",
},
@@ -38,12 +38,12 @@ func TestEscape(t *testing.T) {
want: "\"\n\"",
},
{
name: "double quote",
name: "double-quote",
input: "\"",
want: "\"\\\"\"",
},
{
name: "single quote",
name: "single-quote",
input: "'",
want: "\"'\"",
},
@@ -53,12 +53,12 @@ func TestEscape(t *testing.T) {
want: "\"\\\\\"",
},
{
name: "greater than",
name: "greater-than",
input: ">",
want: "\">\"",
},
{
name: "less than",
name: "less-than",
input: "<",
want: "\"<\"",
},
@@ -93,7 +93,7 @@ func TestEscape(t *testing.T) {
want: "\"*\"",
},
{
name: "question mark",
name: "question-mark",
input: "?",
want: "\"?\"",
},
@@ -103,12 +103,12 @@ func TestEscape(t *testing.T) {
want: "\"#\"",
},
{
name: "open paren",
name: "open-paren",
input: "(",
want: "\"(\"",
},
{
name: "close paren",
name: "close-paren",
input: ")",
want: "\")\"",
},
@@ -118,17 +118,17 @@ func TestEscape(t *testing.T) {
want: "\"\\`\"",
},
{
name: "char without escape",
name: "char-without-escape",
input: "/home/user\t",
want: "\"/home/user\t\"",
},
{
name: "char with escape",
name: "char-with-escape",
input: "/home/user\\",
want: "\"/home/user\\\\\"",
},
{
name: "all illegal chars",
name: "all-illegal-chars",
input: "/home/user" + needsEscape,
want: "\"/home/user \t\n\\\"'\\\\><~|&;\\$*?#()\\`\"",
},
+2 -2
View File
@@ -31,7 +31,7 @@ func TestClientBuildURL(t *testing.T) {
want: `http://127.0.0.1:1234/api/v2/tailnet/example%20dot%20com%3Ffoo=bar`,
},
{
desc: "url.Values",
desc: "url-Values",
elements: []any{"tailnet", "example.com", "acl", url.Values{"details": {"1"}}},
want: `http://127.0.0.1:1234/api/v2/tailnet/example.com/acl?details=1`,
},
@@ -71,7 +71,7 @@ func TestClientBuildTailnetURL(t *testing.T) {
want: `http://127.0.0.1:1234/api/v2/tailnet/example.com/foo%20bar%3Fbaz=qux`,
},
{
desc: "url.Values",
desc: "url-Values",
elements: []any{"acl", url.Values{"details": {"1"}}},
want: `http://127.0.0.1:1234/api/v2/tailnet/example.com/acl?details=1`,
},
+15 -15
View File
@@ -41,37 +41,37 @@ func TestQnapAuthnURL(t *testing.T) {
want string
}{
{
name: "localhost http",
name: "localhost-http",
in: "http://localhost:8088/",
want: "http://localhost:8088/cgi-bin/authLogin.cgi?qtoken=token",
},
{
name: "localhost https",
name: "localhost-https",
in: "https://localhost:5000/",
want: "https://localhost:5000/cgi-bin/authLogin.cgi?qtoken=token",
},
{
name: "IP http",
name: "IP-http",
in: "http://10.1.20.4:80/",
want: "http://10.1.20.4:80/cgi-bin/authLogin.cgi?qtoken=token",
},
{
name: "IP6 https",
name: "IP6-https",
in: "https://[ff7d:0:1:2::1]/",
want: "https://[ff7d:0:1:2::1]/cgi-bin/authLogin.cgi?qtoken=token",
},
{
name: "hostname https",
name: "hostname-https",
in: "https://qnap.example.com/",
want: "https://qnap.example.com/cgi-bin/authLogin.cgi?qtoken=token",
},
{
name: "invalid URL",
name: "invalid-URL",
in: "This is not a URL, it is a really really really really really really really really really really really really long string to exercise the URL truncation code in the error path.",
want: "http://localhost/cgi-bin/authLogin.cgi?qtoken=token",
},
{
name: "err != nil",
name: "err-not-nil",
in: "http://192.168.0.%31/",
want: "http://localhost/cgi-bin/authLogin.cgi?qtoken=token",
},
@@ -1516,47 +1516,47 @@ func TestCSRFProtect(t *testing.T) {
wantError bool
}{
{
name: "GET requests with no header are allowed",
name: "GET-no-header-allowed", // GET requests with no header are allowed
method: "GET",
},
{
name: "POST requests with same-origin are allowed",
name: "POST-same-origin-allowed",
method: "POST",
secFetchSite: "same-origin",
},
{
name: "POST requests with cross-site are not allowed",
name: "POST-cross-site-rejected",
method: "POST",
secFetchSite: "cross-site",
wantError: true,
},
{
name: "POST requests with unknown sec-fetch-site values are not allowed",
name: "POST-unknown-sec-fetch-site-rejected",
method: "POST",
secFetchSite: "new-unknown-value",
wantError: true,
},
{
name: "POST requests with none are not allowed",
name: "POST-sec-fetch-none-rejected",
method: "POST",
secFetchSite: "none",
wantError: true,
},
{
name: "POST requests with no sec-fetch-site header but matching host and origin are allowed",
name: "POST-no-sec-fetch-site-matching-host-origin", // no sec-fetch-site header but matching host and origin are allowed
method: "POST",
host: "example.com",
origin: "https://example.com",
},
{
name: "POST requests with no sec-fetch-site and non-matching host and origin are not allowed",
name: "POST-no-sec-fetch-site-mismatched-host-origin-rejected",
method: "POST",
host: "example.com",
origin: "https://example.net",
wantError: true,
},
{
name: "POST requests with no sec-fetch-site and and origin that matches the override are allowed",
name: "POST-no-sec-fetch-site-origin-override-allowed",
method: "POST",
originOverride: "example.net",
host: "internal.example.foo", // Host can be changed by reverse proxies