This is a series of networking utilities and test wrappers by entropy for building robust networked services in golang. See the godoc for details
# What can I do with this?
The godoc should cover most of it. I’ve highlighted a few things below and will add more examples as time goes on. Examples are also present in the godoc
Mocking:
One thing peculiarity of the httmock
library is you can’t actually pass it a handler. WrapHandler
let’s you do so:
Handler Mocking:
(see mock_test
for a more detailed example)
package main
import (
"github.com/jarcoal/httpmock"
)
func main(){
httpmock.Activate()
defer httpmock.Deactivate()
ctx := context.Background()
requestCount := 0
testServer := http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {
rw.WriteHeader(200)
})
httpmock.RegisterResponder("POST", "https://api.github.com/graphql", testutils.WrapHandler(testServer))
}
There’s also a fasthttp module for mocking fasthttp servers/clients with http mock (see tests)