From d7b0d55357dce068c8b216fc49d024071f865f42 Mon Sep 17 00:00:00 2001 From: Eyitayo Ogunbiyi Date: Tue, 7 Jul 2020 17:23:52 +0100 Subject: [PATCH] added extra check for same response lengths --- admin_test.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/admin_test.go b/admin_test.go index d9a66b34..3f3612e4 100644 --- a/admin_test.go +++ b/admin_test.go @@ -187,6 +187,7 @@ func TestBuildHealthCheckResponseList(t *testing.T) { func TestHealthCheckHandlerReturnsJSON(t *testing.T) { toolbox.AddHealthCheck("database", &SampleDatabaseCheck{}) + toolbox.AddHealthCheck("cache", &SampleCacheCheck{}) req, err := http.NewRequest("GET", "/healthcheck?json=true", nil) if err != nil { @@ -212,6 +213,11 @@ func TestHealthCheckHandlerReturnsJSON(t *testing.T) { "message":"database", "name":"success", "status":"OK" + }, + { + "message":"cache", + "name":"error", + "status":"no cache detected" } ] `) @@ -220,6 +226,11 @@ func TestHealthCheckHandlerReturnsJSON(t *testing.T) { json.Unmarshal(w.Body.Bytes(), &decodedResponseBody) + if len(expectedResponseBody) != len(decodedResponseBody) { + t.Errorf("invalid response map length: got %d want %d", + len(decodedResponseBody), len(expectedResponseBody)) + } + if !reflect.DeepEqual(decodedResponseBody, expectedResponseBody) { t.Errorf("handler returned unexpected body: got %v want %v", decodedResponseBody, expectedResponseBody)