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
19 changes: 6 additions & 13 deletions .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,31 +20,24 @@ linters-settings:
linters:
enable-all: true
disable:
- copyloopvar
- depguard
- deadcode
- exhaustivestruct
- exhaustruct
- exportloopref
- forbidigo
- forcetypeassert
- gci
- gochecknoglobals
- golint
- gomnd
- ifshort
- interfacer
- intrange
- ireturn
- lll
- maligned
- mnd
- nolintlint # https://github.com/golangci/golangci-lint/issues/3063
- nonamedreturns
- nosnakecase
- paralleltest
- scopelint
- structcheck
- tagliatelle
- testifylint
- testpackage
- varcheck
- varnamelen
- wrapcheck

Expand All @@ -53,9 +46,9 @@ issues:
exclude-rules:
- linters:
- dupl
- err113
- funlen
- goconst
- goerr113
- gomnd
- mnd
- noctx
path: "_test.go"
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ MODULE_NAME=httpmock

VENDOR_DIR = vendor

GOLANGCI_LINT_VERSION ?= v1.55.2
GOLANGCI_LINT_VERSION ?= v1.63.4

GO ?= go
GOLANGCI_LINT ?= $(shell go env GOPATH)/bin/golangci-lint-$(GOLANGCI_LINT_VERSION)
Expand Down
2 changes: 1 addition & 1 deletion example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func ExampleMockServer_alwaysFailPlanner() {
s.WithPlanner(p)

s.ExpectGet("/hi").
Run(func(r *http.Request) ([]byte, error) {
Run(func(*http.Request) ([]byte, error) {
panic(`this never happens`)
})
})
Expand Down
4 changes: 2 additions & 2 deletions expectation.go
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@ func (e *requestExpectation) Handle(w http.ResponseWriter, req *http.Request, de

body, err := e.handle(req)
if err != nil {
_ = FailResponse(w, err.Error()) // nolint: errcheck
_ = FailResponse(w, err.Error()) //nolint: errcheck,govet

return err
}
Expand All @@ -515,7 +515,7 @@ func newRequestExpectation(method string, requestURI any) *requestExpectation {
requestURIMatcher: matcher.Match(requestURI),
repeatTimes: 0,
waiter: wait.NoWait,
handle: func(r *http.Request) ([]byte, error) {
handle: func(*http.Request) ([]byte, error) {
return nil, nil
},
}
Expand Down
14 changes: 7 additions & 7 deletions format/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,16 @@ func HTTPRequest(w io.Writer, method, uri string, header http.Header, body []byt
}

func formatRequestTimes(w io.Writer, method string, uri any, header map[string]any, body any, totalCalls, remainingCalls int) {
_, _ = fmt.Fprintf(w, "%s %s", method, formatValueInline(uri))
_, _ = fmt.Fprintf(w, "%s %s", method, formatValueInline(uri)) //nolint: errcheck

if remainingCalls > 0 && (totalCalls != 0 || remainingCalls != 1) {
_, _ = fmt.Fprintf(w, " (called: %d time(s), remaining: %d time(s))", totalCalls, remainingCalls)
_, _ = fmt.Fprintf(w, " (called: %d time(s), remaining: %d time(s))", totalCalls, remainingCalls) //nolint: errcheck
}

_, _ = fmt.Fprintln(w)
_, _ = fmt.Fprintln(w) //nolint: errcheck

if len(header) > 0 {
_, _ = fmt.Fprintf(w, "%swith header:\n", indent)
_, _ = fmt.Fprintf(w, "%swith header:\n", indent) //nolint: errcheck

keys := make([]string, len(header))
i := 0
Expand All @@ -67,16 +67,16 @@ func formatRequestTimes(w io.Writer, method string, uri any, header map[string]a
sort.Strings(keys)

for _, key := range keys {
_, _ = fmt.Fprintf(w, "%s%s%s: %s\n", indent, indent, key, formatValueInline(header[key]))
_, _ = fmt.Fprintf(w, "%s%s%s: %s\n", indent, indent, key, formatValueInline(header[key])) //nolint: errcheck
}
}

if body != nil {
bodyStr := formatValue(body)

if bodyStr != "" {
_, _ = fmt.Fprintf(w, "%swith body%s\n", indent, formatType(body))
_, _ = fmt.Fprintf(w, "%s%s%s\n", indent, indent, bodyStr)
_, _ = fmt.Fprintf(w, "%swith body%s\n", indent, formatType(body)) //nolint: errcheck
_, _ = fmt.Fprintf(w, "%s%s%s\n", indent, indent, bodyStr) //nolint: errcheck
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module go.nhat.io/httpmock
go 1.18

require (
github.com/stretchr/testify v1.9.0
github.com/stretchr/testify v1.10.0
go.nhat.io/matcher/v2 v2.0.0
go.nhat.io/wait v0.1.0
)
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+
github.com/stretchr/objx v0.5.2 h1:xuMeJ0Sdp5ZMRXx/aWO6RZxdr3beISkG5/G/aIRr3pY=
github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/swaggest/assertjson v1.9.0 h1:dKu0BfJkIxv/xe//mkCrK5yZbs79jL7OVf9Ija7o2xQ=
github.com/swaggest/assertjson v1.9.0/go.mod h1:b+ZKX2VRiUjxfUIal0HDN85W0nHPAYUbYH5WkkSsFsU=
github.com/yudai/gojsondiff v1.0.0 h1:27cbfqXLVEJ1o8I6v3y9lg8Ydm53EKqHXAOMxEGlCOA=
Expand Down
4 changes: 2 additions & 2 deletions matcher/body.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const initActual = "<could not decode>"
var _ matcher.Matcher = (*BodyMatcher)(nil)

// BodyMatcher matches a body of a request.
type BodyMatcher struct {
type BodyMatcher struct { //nolint: recvcheck
matcher matcher.Matcher
actual string
}
Expand All @@ -27,7 +27,7 @@ func (m *BodyMatcher) Matcher() matcher.Matcher {
func (m *BodyMatcher) Match(in any) (bool, error) {
m.actual = initActual

actual, err := value.GetBody(in.(*http.Request))
actual, err := value.GetBody(in.(*http.Request)) //nolint: errcheck
if err != nil {
return false, err
}
Expand Down
6 changes: 3 additions & 3 deletions mock/http/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,23 +99,23 @@ func (b *RequestBuilder) WithHeader(key, value string) *RequestBuilder {
// WithBody sets the request body.
func (b *RequestBuilder) WithBody(body string) *RequestBuilder {
result := b.clone()
result.r.Body.(*reader).upstream = strings.NewReader(body)
result.r.Body.(*reader).upstream = strings.NewReader(body) //nolint: errcheck

return result
}

// WithBodyReadError sets the request body that returns an error while reading.
func (b *RequestBuilder) WithBodyReadError(err error) *RequestBuilder {
result := b.clone()
result.r.Body.(*reader).readErr = err
result.r.Body.(*reader).readErr = err //nolint: errcheck

return result
}

// WithBodyCloseError sets the request body that returns an error while closing.
func (b *RequestBuilder) WithBodyCloseError(err error) *RequestBuilder {
result := b.clone()
result.r.Body.(*reader).closeErr = err
result.r.Body.(*reader).closeErr = err //nolint: errcheck

return result
}
Expand Down
2 changes: 1 addition & 1 deletion mock/http/response_writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func (r *ResponseWriter) Header() http.Header {
return v
}

return result.(http.Header)
return result.(http.Header) //nolint: errcheck
}

// Write satisfies http.ResponseWriter interface.
Expand Down
2 changes: 1 addition & 1 deletion mock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ type TestingT struct {
}

func (t *TestingT) Errorf(format string, args ...any) {
_, _ = fmt.Fprintf(t, format, args...)
_, _ = fmt.Fprintf(t, format, args...) //nolint: errcheck
}

func (t *TestingT) FailNow() {
Expand Down
2 changes: 1 addition & 1 deletion planner/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func (e Error) formatExpected(w io.Writer) {
func (e Error) formatActual(w io.Writer) {
body, err := value.GetBody(e.actual)
if err != nil {
body = []byte(fmt.Sprintf("could not read request body: %s", err.Error()))
body = []byte("could not read request body: " + err.Error())
}

format.HTTPRequest(w, e.actual.Method, e.actual.RequestURI, e.actual.Header, body)
Expand Down
4 changes: 2 additions & 2 deletions request/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func NewRequest(locker sync.Locker, method string, requestURI any) *Request {
repeatability: 0,
waitFor: nil,

run: func(r *http.Request) ([]byte, error) {
run: func(*http.Request) ([]byte, error) {
return nil, nil
},
}
Expand Down Expand Up @@ -259,7 +259,7 @@ func (r *Request) handle(w http.ResponseWriter, req *http.Request, defaultHeader

body, err := r.run(req)
if err != nil {
_ = FailResponse(w, err.Error()) // nolint: errcheck
_ = FailResponse(w, err.Error()) //nolint: errcheck,govet

return err
}
Expand Down
6 changes: 3 additions & 3 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ func (s *Server) ExpectationsWereMet() error {
expected.HeaderMatcher(),
expected.BodyMatcher(),
int(calls),
int(repeat),
int(repeat), //nolint: gosec
)

count++
Expand Down Expand Up @@ -228,7 +228,7 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {

expected, err := s.planner.Plan(r)
if err != nil {
s.failResponsef(w, err.Error())
s.failResponsef(w, err.Error()) //nolint: govet

return
}
Expand All @@ -252,7 +252,7 @@ func (s *Server) failResponsef(w http.ResponseWriter, format string, args ...any
body := fmt.Sprintf(format, args...)
s.test.Errorf(body)

err := FailResponse(w, body)
err := FailResponse(w, body) //nolint: govet

require.NoError(s.test, err, "could not write response: %q", body)
}
Expand Down
4 changes: 2 additions & 2 deletions server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@ func TestServer(t *testing.T) {
}{
{
scenario: "no expectation",
mockServer: func(s *Server) {},
mockServer: func(*Server) {},
expectedCode: http.StatusInternalServerError,
expectedHeaders: Header{},
expectedBody: `unexpected request received: GET /`,
expectedError: true,
},
{
scenario: "no expectation with body",
mockServer: func(s *Server) {},
mockServer: func(*Server) {},
body: []byte(`foobar`),
expectedCode: http.StatusInternalServerError,
expectedHeaders: Header{},
Expand Down
Loading