Skip to content

Commit

Permalink
log mismatched mock information when debug logging is enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
Stein Fletcher committed Feb 20, 2019
1 parent 53494b2 commit 437ed40
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
1 change: 1 addition & 0 deletions examples/mocks/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

func TestGetUser_Success(t *testing.T) {
apitest.New().
Debug().
Mocks(getPreferencesMock, getUserMock).
Handler(newApp().Router).
Get("/user").
Expand Down
8 changes: 7 additions & 1 deletion mocks.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,15 @@ func (r *Transport) RoundTrip(req *http.Request) (mockResponse *http.Response, m
}()
}

if matchedResponse, matchErrors := matches(req, r.mocks); matchErrors == nil {
matchedResponse, matchErrors := matches(req, r.mocks)
if matchErrors == nil {
return buildResponseFromMock(matchedResponse), nil
}

if r.debugEnabled {
fmt.Printf("failed to match mocks. Errors: %s\n", matchErrors)
}

return nil, matchErrors
}

Expand Down

0 comments on commit 437ed40

Please sign in to comment.