Skip to the content.

Gock HTTP traffic mocking

Gock is HTTP traffic mocking and testing made easy in Go ༼ʘ̚ل͜ʘ̚༽

// The way gock handles (intercepts) the HTTP queries is by first defining a "pattern" to match,
// which can include various things like the URL, the parameters, the method, the authentication data provided,
// and so on, and then by Reply()-ing with the mock up response data suitable for the matched request.
//
// Example:
//
// gock.New(ADDRESS).
// ... describe what the incoming request should look like ...
// ... this may include .Body(READER) which means the request body (!!!) ...
// ... all these "matchers" operate on receiver type *gock.Request (note: Request) ...
// ... once all desired "matchers" have been added to the request, call .Reply(http.STATUSCODE) on it ...
// Reply(http.StatusOK).
// ... this method returns *gock.Response (note: Response is not a Request) ...
// ... now we can't add "matchers", but instead we link (add) what fields/headers/body the response has ...
// ... so this is the mock up API server replies to the real client being tested ...
// .Body(strins.NewReader("mamka tvoya"))
// ... the final type returned by all these methods is *gock.Response ...
// ... so invoking it be like ...
// gr := gock.New(ADDRESS).
//         <METHODS TO NOTE ALL THINGS TO MATCH, LINKED>.
//         Reply(STATUS).
//         <METHODS TO NOTE ALL THINGS TO GO INTO RESPONSE>