Skip to content

fix: align test naming with Go conventions #2230

Description

@pageton

Summary

Test naming violations across 3 categories totaling ~77 instances. While test naming doesn't affect the public API, it impacts readability and consistency for contributors.

1. Test functions with underscores (22 instances)

Go test functions must use Test + CamelCase. The Test_ prefix and mid-name underscores are non-idiomatic.

Worst offender: prefork/prefork_test.go (9 violations):

Test_IsChild                        → TestIsChild
Test_New                            → TestNew
Test_listen                         → TestListen
Test_setTCPListenerFiles            → TestSetTCPListenerFiles
Test_ListenAndServe                  → TestListenAndServe
Test_ListenAndServeTLS              → TestListenAndServeTLS
Test_ListenAndServeTLSEmbed         → TestListenAndServeTLSEmbed
Test_Prefork_Lifecycle              → TestPreforkLifecycle
Test_Prefork_RecoveredChildSpawnError → TestPreforkRecoveredChildSpawnError

Other files:

client_test.go:   Test_AddMissingPort, Test_getRedirectURL, TestClientNonIdempotentRetry_BodyStream, TestClient_RetryIfErrUpstream
header_test.go:   TestRequestHeader_PeekAll, TestResponseHeader_PeekAll, TestRequestHeader_Keys, TestResponseHeader_Keys
userdata_test.go: TestUserData_GC
server_test.go:   TestServerCRNLAfterPost_Pipeline
adaptor_test.go:  TestResourceRecyclingUnderLoad_OneEndpoint, TestResourceRecyclingUnderLoad_MultipleEndpoints
dialer_test.go:   TestDialer_GetDialFunc

2. Fuzz function with redundant Test infix (1 instance)

FuzzTestHeaderScanner → FuzzHeaderScanner  (fuzz_test.go:153)

3. t.Run() subtest names with uppercase (40 instances)

Subtest names should be fully lowercase descriptive phrases, not CamelCase or title case.

Examples from cookie_test.go:

"SetKey" → "set key"
"SetValueBytes" → "set value bytes"
"SetDomain" → "set domain"

Examples from header_test.go:

"ResponseHeader" → "response header"
"RequestHeader_"+tc.name → "request header/"+tc.name
"Safe_RequestHeader_"+header → "safe request header/"+header

Examples from client_test.go:

"Path normalizing enabled..." → "path normalizing enabled..."
"Client should fail after..." → "client should fail after..."

4. t.Run() subtest names with underscores (15 instances)

Subtests should use spaces, not underscores. The / separator is idiomatic for grouping.

"buffered_too_large" → "buffered too large"
"RequestHeader_"+tc.name → "request header/"+tc.name
"Safe_RequestHeader_"+header → "safe request header/"+header

5. Table-driven test fields using want instead of expected (13 instances)

File Current Suggested
client_test.go want bool, want string expected bool, expected string
header_test.go wantValue, wantFirstLine, wantNoHTTP11 expectedValue, expectedFirstLine, expectedNoHTTP11
fs_fs_test.go want bool expected bool
fasthttpproxy/dialer_test.go wantCounts expectedCounts
bytesconv_test.go hasError bool, roundTrip bool expectedError bool, expectedRoundTrip bool

Reference

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions