NewErrorServer returns a new httptest.Server, which responds with the given error message and code, and a client which proxies requests to the server using a custom transport. The caller must close the server.
(message string, code int)
| 25 | // error message and code, and a client which proxies requests to the server |
| 26 | // using a custom transport. The caller must close the server. |
| 27 | func NewErrorServer(message string, code int) (*http.Client, *httptest.Server) { |
| 28 | client, mux, server := TestServer() |
| 29 | mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { |
| 30 | http.Error(w, message, code) |
| 31 | }) |
| 32 | return client, server |
| 33 | } |
| 34 | |
| 35 | // NewTestServerFunc is an adapter to allow the use of ordinary functions as |
| 36 | // httptest.Server's for testing. Caller must close the server. |