Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ jobs:
- name: golangci-lint
uses: golangci/golangci-lint-action@v8
with:
version: v2.1
version: v2.8.0
2 changes: 1 addition & 1 deletion .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: "1.24.x"
go-version: "1.25.x"
- run: go version

- name: Install dependencies
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: "1.24.x"
go-version: "1.25.x"
- run: go version

- name: Install dependencies
Expand Down
17 changes: 10 additions & 7 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ linters:
- unconvert
- unparam
- unused
- wsl
- wsl_v5
settings:
errcheck:
check-type-assertions: false
Expand All @@ -38,12 +38,15 @@ linters:
ignored-numbers:
- "2"
- "0644"

wsl:
strict-append: false
allow-separated-leading-comment: true
allow-cuddle-declarations: true
force-short-decl-cuddling: true
wsl_v5:
allow-first-in-block: true
allow-whole-block: false
branch-max-lines: 2
enable:
- assign-exclusive
disable:
- append
- decl
exclusions:
generated: lax
presets:
Expand Down
2 changes: 0 additions & 2 deletions functions/post_form_url_encoded.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,11 @@ func PostFormURLEncoded(existingHeaders map[string]string, args []string) (strin
client.Timeout = time.Second * timeoutSeconds

response, err := client.PostForm(endpoint, requestBody)

if err != nil {
return "", err
}

responseBody, err := io.ReadAll(response.Body)

if err != nil {
return "", err
}
Expand Down
4 changes: 0 additions & 4 deletions functions/sign_string_rs256_pkcs8.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ func SignStringRS256PKCS8(existingHeaders map[string]string, args []string) (str
}

key, passphrase, err := argsToKeyPassphrase(args)

if err != nil {
return "", fmt.Errorf("error calling SignStringRS256PKCS8; %w", err)
}
Expand All @@ -36,7 +35,6 @@ func SignStringRS256PKCS8(existingHeaders map[string]string, args []string) (str

// Parse the key, decrypting it if necessary
decryptedKey, err := pkcs8.ParsePKCS8PrivateKey(pemBlock.Bytes, []byte(passphrase))

if err != nil {
return "", fmt.Errorf("error calling SignStringRS256PKCS8; unable to parse private key: %w", err)
}
Expand All @@ -55,7 +53,6 @@ func SignStringRS256PKCS8(existingHeaders map[string]string, args []string) (str

// Sign the hashed header with the RSA key
signature, err := rsa.SignPKCS1v15(nil, rsaKey, crypto.SHA256, hash[:])

if err != nil {
return "", fmt.Errorf("error calling SignStringRS256PKCS8; could not sign header: %w", err)
}
Expand Down Expand Up @@ -90,7 +87,6 @@ func argsToKeyPassphrase(args []string) (string, string, error) {
passphrase := args[1]

key, err := formatKey(args[0], passphrase != "")

if err != nil {
return "", "", err
}
Expand Down
10 changes: 5 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/nytimes/httptest

go 1.24.4
go 1.25.6

require (
github.com/drone/envsubst v1.0.3
Expand All @@ -9,16 +9,16 @@ require (
github.com/tidwall/gjson v1.18.0
github.com/tidwall/pretty v1.2.1
github.com/youmark/pkcs8 v0.0.0-20240726163527-a2c0da244d78
go.uber.org/zap v1.27.0
go.uber.org/zap v1.27.1
gopkg.in/yaml.v2 v2.4.0
)

require (
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
github.com/mattn/go-colorable v0.1.14 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/tidwall/match v1.1.1 // indirect
github.com/tidwall/match v1.2.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/crypto v0.39.0 // indirect
golang.org/x/sys v0.33.0 // indirect
golang.org/x/crypto v0.47.0 // indirect
golang.org/x/sys v0.40.0 // indirect
)
15 changes: 8 additions & 7 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKs
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/tidwall/gjson v1.18.0 h1:FIDeeyB800efLX89e5a8Y0BNH+LOngJyGrIWxG2FKQY=
github.com/tidwall/gjson v1.18.0/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk=
github.com/tidwall/match v1.1.1 h1:+Ho715JplO36QYgwN9PGYNhgZvoUSc9X2c80KVTi+GA=
github.com/tidwall/match v1.1.1/go.mod h1:eRSPERbgtNPcGhD8UCthc6PmLEQXEWd3PRB5JTxsfmM=
github.com/tidwall/match v1.2.0 h1:0pt8FlkOwjN2fPt4bIl4BoNxb98gGHN2ObFEDkrfZnM=
github.com/tidwall/match v1.2.0/go.mod h1:eRSPERbgtNPcGhD8UCthc6PmLEQXEWd3PRB5JTxsfmM=
github.com/tidwall/pretty v1.2.0/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU=
github.com/tidwall/pretty v1.2.1 h1:qjsOFOWWQl+N3RsoF5/ssm1pHmJJwhjlSbZ51I6wMl4=
github.com/tidwall/pretty v1.2.1/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU=
Expand All @@ -33,13 +34,13 @@ go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=
go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE=
go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0=
go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y=
go.uber.org/zap v1.27.0 h1:aJMhYGrd5QSmlpLMr2MftRKl7t8J8PTZPA732ud/XR8=
go.uber.org/zap v1.27.0/go.mod h1:GB2qFLM7cTU87MWRP2mPIjqfIDnGu+VIO4V/SdhGo2E=
golang.org/x/crypto v0.39.0 h1:SHs+kF4LP+f+p14esP5jAoDpHU8Gu/v9lFRK6IT5imM=
golang.org/x/crypto v0.39.0/go.mod h1:L+Xg3Wf6HoL4Bn4238Z6ft6KfEpN0tJGo53AAPC632U=
go.uber.org/zap v1.27.1 h1:08RqriUEv8+ArZRYSTXy1LeBScaMpVSTBhCeaZYfMYc=
go.uber.org/zap v1.27.1/go.mod h1:GB2qFLM7cTU87MWRP2mPIjqfIDnGu+VIO4V/SdhGo2E=
golang.org/x/crypto v0.47.0 h1:V6e3FRj+n4dbpw86FJ8Fv7XVOql7TEwpHapKoMJ/GO8=
golang.org/x/crypto v0.47.0/go.mod h1:ff3Y9VzzKbwSSEzWqJsJVBnWmRwRSHt/6Op5n9bQc4A=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.33.0 h1:q3i8TbbEz+JRD9ywIRlyRAQbM0qF7hu24q3teo2hbuw=
golang.org/x/sys v0.33.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
golang.org/x/sys v0.40.0 h1:DBZZqJ2Rkml6QMQsZywtnjnnGvHza6BTfYFWY9kjEWQ=
golang.org/x/sys v0.40.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
Expand Down
3 changes: 0 additions & 3 deletions internal/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ type Config struct {
func FromEnv() (*Config, error) {
// Parse non-string values
concurrency, err := strconv.Atoi(getEnv("TEST_CONCURRENCY", "2"))

if err != nil {
return nil, fmt.Errorf("invalid concurrency value: %s", err)
}
Expand All @@ -46,7 +45,6 @@ func FromEnv() (*Config, error) {
}

verbosity, err := strconv.Atoi(getEnv("TEST_VERBOSITY", "0"))

if err != nil {
return nil, fmt.Errorf("invalid verbosity value: %s", err)
}
Expand All @@ -60,7 +58,6 @@ func FromEnv() (*Config, error) {
enableRetries := getEnv("ENABLE_RETRIES", "false") == "true"

retryCount, err := strconv.Atoi(getEnv("DEFAULT_RETRY_COUNT", "2"))

if err != nil {
return nil, fmt.Errorf("invalid default retry count value: %s", err)
}
Expand Down
1 change: 1 addition & 0 deletions internal/coordinator.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ func RunTests(tests []*Test, config *Config) bool {
PrintTestResult(t, result)
}
}

mux.Unlock()
}(test)
}
Expand Down
1 change: 0 additions & 1 deletion internal/dynamic.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ func ProcessDynamicHeaders(dynamicHeaders []DynamicHeader, allHeaders map[string
}

value, err := dhfn(allHeaders, dynamicHeader.Args)

if err != nil {
return err
}
Expand Down
2 changes: 0 additions & 2 deletions internal/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ func SendHTTPRequest(config *HTTPRequestConfig) (*http.Response, []byte, error)
config.URL,
config.Body,
)

if err != nil {
return nil, nil, err
}
Expand Down Expand Up @@ -123,7 +122,6 @@ func SendHTTPRequest(config *HTTPRequestConfig) (*http.Response, []byte, error)

// Start sending request
resp, err := client.Do(req)

if err != nil {
return nil, nil, err
}
Expand Down
4 changes: 1 addition & 3 deletions internal/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,10 @@ func ParseAllTestsInDirectory(root string) ([]*Test, error) {

for _, p := range files {
tests, err := parseTestFile(p)

if err != nil {
return nil, err
}

allTests = append(allTests, tests...)
}

Expand All @@ -121,14 +121,12 @@ func ParseAllTestsInDirectory(root string) ([]*Test, error) {
func parseTestFile(filePath string) ([]*Test, error) {
// Read file into buffer
data, err := os.ReadFile(filePath)

if err != nil {
return nil, fmt.Errorf("ioutil: %v", err)
}

// Environment variable substitution
yamlString, err := envsubst.EvalEnv(string(data))

if err != nil {
return nil, fmt.Errorf("unable to parse file %s: %v", filePath, err)
}
Expand Down
5 changes: 0 additions & 5 deletions internal/tester.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ func RunTest(test *Test, defaultHost string, maxRetries int) *TestResult {

// Check test conditions and skip if not met
conditionsMet, err := validateConditions(test)

if err != nil {
result.Errors = append(result.Errors, err)
return result
Expand Down Expand Up @@ -101,7 +100,6 @@ func RunTest(test *Test, defaultHost string, maxRetries int) *TestResult {
result.Retries = i

resp, respBody, err := SendHTTPRequest(reqConfig)

if err != nil {
result.Errors = append(result.Errors, err)
continue
Expand Down Expand Up @@ -192,7 +190,6 @@ func validateConditions(test *Test) (bool, error) {
// Environment variable
for key, pattern := range test.Conditions.Env {
re, err := regexp.Compile("(?i)" + pattern)

if err != nil {
return false, fmt.Errorf("%s", err.Error())
}
Expand Down Expand Up @@ -274,7 +271,6 @@ func validateResponseHeaderPatterns(response *http.Response, patterns map[string
// Patterns
for header, pattern := range patterns {
re, err := regexp.Compile("(?i)" + pattern)

if err != nil {
errors = append(errors, fmt.Errorf("invalid test pattern `%s`: %s", pattern, err.Error()))
continue
Expand Down Expand Up @@ -322,7 +318,6 @@ func validateResponseBody(test *Test, _ *http.Response, body []byte) []error {

for _, pattern := range patterns {
re, err := regexp.Compile("(?i)" + pattern)

if err != nil {
errors = append(errors, fmt.Errorf("%s", err.Error()))
continue
Expand Down
1 change: 0 additions & 1 deletion internal/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
// AppendHostsFile appends a string to /etc/hosts as a new line
func AppendHostsFile(content string) error {
f, err := os.OpenFile("/etc/hosts", os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)

if err != nil {
return err
}
Expand Down
3 changes: 1 addition & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ func main() {

// Get and apply config
config, err := ht.FromEnv()

if err != nil {
log.Fatalf("error: failed to parse config: %s", err)
}
Expand All @@ -95,11 +94,11 @@ func main() {
logger := buildLogger(config.Verbosity)
//nolint:errcheck
defer logger.Sync()

zap.ReplaceGlobals(logger)

// Parse and run tests
tests, err := ht.ParseAllTestsInDirectory(config.TestDirectory)

if err != nil {
log.Fatalf("error: failed to parse tests: %s", err)
}
Expand Down