Log expansion and write accept headers for tests.

pull/272/head
jackgr 9 years ago
parent 46984eb02a
commit 808641c7f7

@ -86,6 +86,8 @@ func NewExpansionHandler(backend expander.Expander) restful.RouteFunction {
}
util.LogHandlerExit("expandybird", http.StatusOK, "OK", resp.ResponseWriter)
message := fmt.Sprintf("\nConfig:\n%s\nLayout:\n%s\n", response.Config, response.Layout)
util.LogHandlerText("expandybird", message)
resp.WriteEntity(response)
}
}

@ -192,7 +192,7 @@ func (e *expander) expandTemplate(t *common.Template) (*ExpandedTemplate, error)
response, err := http.Post(e.getBaseURL(), "application/json", ioutil.NopCloser(bytes.NewReader(j)))
if err != nil {
e := fmt.Errorf("http POST failed: %s", err)
e := fmt.Errorf("call failed (%s) with payload:\n%s\n", e.getBaseURL(), err, string(j))
return nil, e
}

@ -64,6 +64,7 @@ func NewHandlerTester(handler http.Handler) HandlerTester {
}
r.Header.Set("Content-Type", ctype)
r.Header.Set("Accept", "*/*")
w := httptest.NewRecorder()
handler.ServeHTTP(w, r)
return w, nil
@ -87,6 +88,7 @@ func NewServerTester(handler http.Handler) ServerTester {
}
r.Header.Set("Content-Type", ctype)
r.Header.Set("Accept", "*/*")
return http.DefaultClient.Do(r)
}
}
@ -112,6 +114,10 @@ func TestHandlerWithURL(handler http.Handler, method, urlString string) (*httpte
return NewHandlerTester(handler).TestWithURL(method, urlString)
}
func LogHandlerText(handler string, v string) {
log.Printf("%s: %s\n", handler, v)
}
// LogHandlerEntry logs the start of the given handler handling the given request.
func LogHandlerEntry(handler string, r *http.Request) {
log.Printf("%s: handling request:%s %s\n", handler, r.Method, r.URL.RequestURI())

Loading…
Cancel
Save