Skip to content

Commit d1b2862

Browse files
authored
doc: enhance comment
1 parent 2220adb commit d1b2862

1 file changed

Lines changed: 23 additions & 0 deletions

File tree

response.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,29 @@ func ResponderFromResponse(resp *http.Response) Responder {
141141
// For home-made responses, NewRespBodyFromString and
142142
// NewRespBodyFromBytes functions can be used to produce response
143143
// bodies that can be read several times and concurrently.
144+
//
145+
// If all responses have been returned and fn is passed
146+
// and non-nil, it acts as the fn parameter of NewNotFoundResponder,
147+
// allowing to dump the stack trace to localize the origin of the
148+
// call.
149+
// import (
150+
// "github.com/jarcoal/httpmock"
151+
// "testing"
152+
// )
153+
// ...
154+
// func TestMyApp(t *testing.T) {
155+
// ...
156+
// // This responder is callable only once, then an error is returned and
157+
// // the stacktrace of the call logged using t.Log()
158+
// httpmock.RegisterResponder("GET", "/foo/bar",
159+
// httpmock.ResponderFromMultipleResponses(
160+
// []*http.Response{
161+
// httpmock.NewStringResponse(200, `{"name":"bar"}`),
162+
// httpmock.NewStringResponse(404, `{"mesg":"Not found"}`),
163+
// },
164+
// t.Log),
165+
// )
166+
// }
144167
func ResponderFromMultipleResponses(responses []*http.Response, fn ...func(...interface{})) Responder {
145168
responseIndex := 0
146169
mutex := sync.Mutex{}

0 commit comments

Comments
 (0)