From 808641c7f712d3560fb3433059a3e9062efb14af Mon Sep 17 00:00:00 2001 From: jackgr Date: Mon, 22 Feb 2016 16:08:06 -0800 Subject: [PATCH] Log expansion and write accept headers for tests. --- expandybird/service/service.go | 2 ++ manager/manager/expander.go | 2 +- util/httputil.go | 6 ++++++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/expandybird/service/service.go b/expandybird/service/service.go index 239170cb8..ac75d47e6 100644 --- a/expandybird/service/service.go +++ b/expandybird/service/service.go @@ -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) } } diff --git a/manager/manager/expander.go b/manager/manager/expander.go index 49557ac39..333804dab 100644 --- a/manager/manager/expander.go +++ b/manager/manager/expander.go @@ -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 } diff --git a/util/httputil.go b/util/httputil.go index 540bc86a2..cba3988a7 100644 --- a/util/httputil.go +++ b/util/httputil.go @@ -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())