Commit 808641c7 authored by jackgr's avatar jackgr

Log expansion and write accept headers for tests.

parent 46984eb0
...@@ -86,6 +86,8 @@ func NewExpansionHandler(backend expander.Expander) restful.RouteFunction { ...@@ -86,6 +86,8 @@ func NewExpansionHandler(backend expander.Expander) restful.RouteFunction {
} }
util.LogHandlerExit("expandybird", http.StatusOK, "OK", resp.ResponseWriter) 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) resp.WriteEntity(response)
} }
} }
......
...@@ -192,7 +192,7 @@ func (e *expander) expandTemplate(t *common.Template) (*ExpandedTemplate, error) ...@@ -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))) response, err := http.Post(e.getBaseURL(), "application/json", ioutil.NopCloser(bytes.NewReader(j)))
if err != nil { 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 return nil, e
} }
......
...@@ -64,6 +64,7 @@ func NewHandlerTester(handler http.Handler) HandlerTester { ...@@ -64,6 +64,7 @@ func NewHandlerTester(handler http.Handler) HandlerTester {
} }
r.Header.Set("Content-Type", ctype) r.Header.Set("Content-Type", ctype)
r.Header.Set("Accept", "*/*")
w := httptest.NewRecorder() w := httptest.NewRecorder()
handler.ServeHTTP(w, r) handler.ServeHTTP(w, r)
return w, nil return w, nil
...@@ -87,6 +88,7 @@ func NewServerTester(handler http.Handler) ServerTester { ...@@ -87,6 +88,7 @@ func NewServerTester(handler http.Handler) ServerTester {
} }
r.Header.Set("Content-Type", ctype) r.Header.Set("Content-Type", ctype)
r.Header.Set("Accept", "*/*")
return http.DefaultClient.Do(r) return http.DefaultClient.Do(r)
} }
} }
...@@ -112,6 +114,10 @@ func TestHandlerWithURL(handler http.Handler, method, urlString string) (*httpte ...@@ -112,6 +114,10 @@ func TestHandlerWithURL(handler http.Handler, method, urlString string) (*httpte
return NewHandlerTester(handler).TestWithURL(method, urlString) 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. // LogHandlerEntry logs the start of the given handler handling the given request.
func LogHandlerEntry(handler string, r *http.Request) { func LogHandlerEntry(handler string, r *http.Request) {
log.Printf("%s: handling request:%s %s\n", handler, r.Method, r.URL.RequestURI()) log.Printf("%s: handling request:%s %s\n", handler, r.Method, r.URL.RequestURI())
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment