Skip to content

Commit

Permalink
added extra check for same response lengths
Browse files Browse the repository at this point in the history
  • Loading branch information
tayoogunbiyi committed Jul 7, 2020
1 parent 728bf34 commit d7b0d55
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions admin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -212,6 +213,11 @@ func TestHealthCheckHandlerReturnsJSON(t *testing.T) {
"message":"database",
"name":"success",
"status":"OK"
},
{
"message":"cache",
"name":"error",
"status":"no cache detected"
}
]
`)
Expand All @@ -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)
Expand Down

0 comments on commit d7b0d55

Please sign in to comment.