From e9615c50e67ddacf392f1340939c2722731990d3 Mon Sep 17 00:00:00 2001 From: Ryan Uber Date: Thu, 1 Jan 2015 14:27:10 -0800 Subject: [PATCH] agent: test pretty printed json --- command/agent/http_test.go | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/command/agent/http_test.go b/command/agent/http_test.go index a1570a9db0..2308321287 100644 --- a/command/agent/http_test.go +++ b/command/agent/http_test.go @@ -126,6 +126,33 @@ func TestContentTypeIsJSON(t *testing.T) { } } +func TestPrettyPrint(t *testing.T) { + dir, srv := makeHTTPServer(t) + defer os.RemoveAll(dir) + defer srv.Shutdown() + defer srv.agent.Shutdown() + + r := &structs.DirEntry{Key: "key"} + + resp := httptest.NewRecorder() + handler := func(resp http.ResponseWriter, req *http.Request) (interface{}, error) { + return r, nil + } + + req, _ := http.NewRequest("GET", "/v1/kv/key?pretty=1", nil) + srv.wrap(handler)(resp, req) + + expected, _ := json.MarshalIndent(r, "", " ") + actual, err := ioutil.ReadAll(resp.Body) + if err != nil { + t.Fatalf("err: %s", err) + } + + if !bytes.Equal(expected, actual) { + t.Fatalf("bad: %q", string(actual)) + } +} + func TestParseWait(t *testing.T) { resp := httptest.NewRecorder() var b structs.QueryOptions