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
7 changes: 4 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ COVERAGE_ARGS ?= -covermode=atomic -coverprofile=$(COVERAGE_PATH)
TEST_ARGS ?= -race

# 3rd party tools
LINT := go run github.com/mgechev/revive@v1.3.4
FMT := go run mvdan.cc/gofumpt@v0.7.0
LINT := go run github.com/mgechev/revive@v1.7.0
REFLEX := go run github.com/cespare/reflex@v0.3.1
STATICCHECK := go run honnef.co/go/tools/cmd/staticcheck@2023.1.3
STATICCHECK := go run honnef.co/go/tools/cmd/staticcheck@2025.1.1

# Host and port to use when running locally via `make run` or `make watch`
HOST ?= 127.0.0.1
Expand Down Expand Up @@ -66,7 +67,7 @@ testautobahn:
.PHONY: autobahntests

lint:
test -z "$$(gofmt -d -s -e .)" || (echo "Error: gofmt failed"; gofmt -d -s -e . ; exit 1)
test -z "$$($(FMT) -d -e .)" || (echo "Error: $(FMT) failed"; $(FMT) -d -e . ; exit 1)
go vet ./...
$(LINT) -set_exit_status ./...
$(STATICCHECK) ./...
Expand Down
2 changes: 1 addition & 1 deletion httpbin/handlers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3485,7 +3485,7 @@ func newTestServer(handler http.Handler) (*httptest.Server, *http.Client) {
srv := httptest.NewServer(handler)
client := srv.Client()
client.Timeout = 5 * time.Second
client.CheckRedirect = func(req *http.Request, via []*http.Request) error {
client.CheckRedirect = func(_ *http.Request, _ []*http.Request) error {
return http.ErrUseLastResponse
}
return srv, client
Expand Down
16 changes: 8 additions & 8 deletions httpbin/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,13 +248,13 @@ func parseStatusCode(input string) (int, error) {
return parseBoundedStatusCode(input, 100, 599)
}

func parseBoundedStatusCode(input string, min, max int) (int, error) {
func parseBoundedStatusCode(input string, minVal, maxVal int) (int, error) {
code, err := strconv.Atoi(input)
if err != nil {
return 0, fmt.Errorf("invalid status code: %q: %w", input, err)
}
if code < min || code > max {
return 0, fmt.Errorf("invalid status code: %d not in range [%d, %d]", code, min, max)
if code < minVal || code > maxVal {
return 0, fmt.Errorf("invalid status code: %d not in range [%d, %d]", code, minVal, maxVal)
}
return code, nil
}
Expand All @@ -276,16 +276,16 @@ func parseDuration(input string) (time.Duration, error) {

// parseBoundedDuration parses a time.Duration from user input and ensures that
// it is within a given maximum and minimum time
func parseBoundedDuration(input string, min, max time.Duration) (time.Duration, error) {
func parseBoundedDuration(input string, minVal, maxVal time.Duration) (time.Duration, error) {
d, err := parseDuration(input)
if err != nil {
return 0, err
}

if d > max {
err = fmt.Errorf("duration %s longer than %s", d, max)
} else if d < min {
err = fmt.Errorf("duration %s shorter than %s", d, min)
if d > maxVal {
err = fmt.Errorf("duration %s longer than %s", d, maxVal)
} else if d < minVal {
err = fmt.Errorf("duration %s shorter than %s", d, minVal)
}
return d, err
}
Expand Down
4 changes: 2 additions & 2 deletions httpbin/middleware_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ func TestTestMode(t *testing.T) {
// will cause a panic. This happens most often when we forget to return
// early after writing an error response, and has helped identify and fix
// some subtly broken error handling.
observer := func(r Result) {}
handler := observe(observer, http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
observer := func(_ Result) {}
handler := observe(observer, http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
w.WriteHeader(http.StatusBadRequest)
w.WriteHeader(http.StatusOK)
}))
Expand Down
2 changes: 1 addition & 1 deletion httpbin/websocket/websocket.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ type Handler func(ctx context.Context, msg *Message) (*Message, error)

// EchoHandler is a Handler that echoes each incoming message back to the
// client.
var EchoHandler Handler = func(ctx context.Context, msg *Message) (*Message, error) {
var EchoHandler Handler = func(_ context.Context, msg *Message) (*Message, error) {
return msg, nil
}

Expand Down
10 changes: 5 additions & 5 deletions internal/testing/assert/assert.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,19 +122,19 @@ func BodySize(t *testing.T, resp *http.Response, want int) {
}

// DurationRange asserts that a duration is within a specific range.
func DurationRange(t *testing.T, got, min, max time.Duration) {
func DurationRange(t *testing.T, got, minVal, maxVal time.Duration) {
t.Helper()
if got < min || got > max {
t.Fatalf("expected duration between %s and %s, got %s", min, max, got)
if got < minVal || got > maxVal {
t.Fatalf("expected duration between %s and %s, got %s", minVal, maxVal, got)
}
}

type Number interface {
type number interface {
~int64 | ~float64
}

// RoughlyEqual asserts that a numeric value is within a certain tolerance.
func RoughlyEqual[T Number](t *testing.T, got, want T, epsilon T) {
func RoughlyEqual[T number](t *testing.T, got, want T, epsilon T) {
t.Helper()
if got < want-epsilon || got > want+epsilon {
t.Fatalf("expected value between %v and %v, got %v", want-epsilon, want+epsilon, got)
Expand Down
Loading