From 47146b9b87fad3ca66bc2771ccf4d1e443eeb2e4 Mon Sep 17 00:00:00 2001 From: Sean Chittenden Date: Wed, 11 May 2016 15:46:08 -0700 Subject: [PATCH] Fix the unit tests for TestPrettyPrintOff A different failing test masked that this wasn't even being run. Pointy Hat: sean- for testing first on Travis in a branch vs verifying locally --- command/agent/http.go | 6 ++++-- command/agent/http_test.go | 7 +++++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/command/agent/http.go b/command/agent/http.go index f6475c409..bf2f95b78 100644 --- a/command/agent/http.go +++ b/command/agent/http.go @@ -175,8 +175,10 @@ func (s *HTTPServer) wrap(handler func(resp http.ResponseWriter, req *http.Reque } prettyPrint := false - if _, ok := req.URL.Query()["pretty"]; ok { - prettyPrint = true + if v, ok := req.URL.Query()["pretty"]; ok { + if len(v) > 0 && (len(v[0]) == 0 || v[0] != "0") { + prettyPrint = true + } } // Write out the JSON object diff --git a/command/agent/http_test.go b/command/agent/http_test.go index 14fbd085f..634e7f689 100644 --- a/command/agent/http_test.go +++ b/command/agent/http_test.go @@ -171,9 +171,12 @@ func testPrettyPrint(pretty string, prettyFmt bool, t *testing.T) { req, _ := http.NewRequest("GET", urlStr, nil) s.Server.wrap(handler)(resp, req) - expected, _ := json.MarshalIndent(r, "", " ") + var expected []byte if prettyFmt { + expected, _ = json.MarshalIndent(r, "", " ") expected = append(expected, "\n"...) + } else { + expected, _ = json.Marshal(r) } actual, err := ioutil.ReadAll(resp.Body) if err != nil { @@ -181,7 +184,7 @@ func testPrettyPrint(pretty string, prettyFmt bool, t *testing.T) { } if !bytes.Equal(expected, actual) { - t.Fatalf("bad: %q", string(actual)) + t.Fatalf("bad:\nexpected:\t%q\nactual:\t\t%q", string(expected), string(actual)) } }