Skip to content

Commit 8724b63

Browse files
committed
added t.Helper() to show failing test instead of httpmocklib
1 parent 0350c5c commit 8724b63

4 files changed

Lines changed: 9 additions & 1 deletion

File tree

httpmockserver.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,15 @@ func New(t T) MockServer {
6969
}
7070

7171
type T interface {
72+
Helper()
7273
Fatal(args ...interface{})
7374
Fatalf(format string, args ...interface{})
7475
Errorf(format string, args ...interface{})
7576
}
7677

7778
// NewWithOpts can be used to create a mock server with custom options
7879
func NewWithOpts(t T, opts Opts) MockServer {
80+
t.Helper()
7981
err := opts.validate()
8082
if err != nil {
8183
t.Fatalf("invalid options: %v", err)
@@ -140,6 +142,7 @@ func (s *mockServer) BaseURL() string {
140142
}
141143

142144
func (s *mockServer) ServeHTTP(w http.ResponseWriter, r *http.Request) {
145+
s.t.Helper()
143146
s.handlerMutex.Lock()
144147
defer s.handlerMutex.Unlock()
145148

@@ -259,6 +262,7 @@ func (s *mockServer) DEFAULT() RequestExpectation {
259262
}
260263

261264
func (s *mockServer) AssertExpectations() {
265+
s.t.Helper()
262266
s.finisheCalled = true
263267
var buf bytes.Buffer
264268

httpmockserver_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -922,3 +922,6 @@ func (t *TMock) Fatalf(format string, args ...interface{}) {
922922
func (t *TMock) Errorf(format string, args ...interface{}) {
923923
t.Called(format, args)
924924
}
925+
926+
func (t *TMock) Helper() {
927+
}

request_expectation.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,7 @@ func (exp *requestExpectation) Custom(validation RequestValidationFunc, descript
422422
}
423423

424424
func (exp *requestExpectation) Response(code int) ResponseExpectation {
425-
425+
exp.t.Helper()
426426
if exp.every {
427427
exp.t.Fatalf("Every is used to check conditions on every request, therefore it cannot be used with Response()")
428428
return nil

response_expectation.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ func (exp *responseExpectation) StringBody(body string) ResponseExpectation {
4848
// JsonBody sets the body of the response to the given object (e.g. `{"foo":"bar"}` or map[string]string{"foo":"bar"})
4949
// you may provide a go object or a valid json string
5050
func (exp *responseExpectation) JsonBody(object interface{}) ResponseExpectation {
51+
exp.t.Helper()
5152
if object == nil {
5253
return exp.Body(nil)
5354
}

0 commit comments

Comments
 (0)