net/http/httptest
for HTTP Go TestingNo need to start up a full web server to test web client code in Go.
// setup mock web service
handler := http.HandlerFunc(
func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, `{"word":"hello","name":"Rob"}`)
})
svr := httptest.NewServer(handler)
defer svr.Close()
// then use svr.URL for everything
And to set the status
w.WriteHeader(http.StatusBadRequest)