testbackend: add catch-all handler with ResponseStatus 404
@@ -22,7 +22,8 @@ func NewBackend() *Backend {
b.srv = httptest.NewServer(b)
// test handler
- b.mux.HandleFunc("/anything", anything)
+ b.mux.HandleFunc("/anything", createAnythingHandler(http.StatusOK))
+ b.mux.HandleFunc("/", createAnythingHandler(http.StatusNotFound))
return b
}
@@ -39,13 +40,15 @@ func (b *Backend) Addr() string {
return b.srv.URL
}
-func anything(rw http.ResponseWriter, req *http.Request) {
+func createAnythingHandler(status int) func(rw http.ResponseWriter, req *http.Request) {
+ return func(rw http.ResponseWriter, req *http.Request) {
type anything struct {
Args url.Values
Headers http.Header
Host string
Path string
Method, RemoteAddr, Url, UserAgent string
+ ResponseStatus int
}
_ = req.ParseForm()
@@ -59,6 +62,7 @@ func anything(rw http.ResponseWriter, req *http.Request) {
RemoteAddr: req.RemoteAddr,
Url: req.URL.String(),
UserAgent: req.UserAgent(),
+ ResponseStatus: status,
}
respContent, _ := json.Marshal(resp)
@@ -68,5 +72,7 @@ func anything(rw http.ResponseWriter, req *http.Request) {
rw.Header().Set("Content-Length", strconv.Itoa(len(respContent)))
rw.Header().Set("Content-Type", "application/json")
+ rw.WriteHeader(status)
_, _ = rw.Write(respContent)
}
+}
