1
0
mirror of https://github.com/astaxie/beego.git synced 2024-11-22 07:10:55 +00:00

added extra check for same response lengths

This commit is contained in:
Eyitayo Ogunbiyi 2020-07-07 17:23:52 +01:00
parent 728bf34006
commit d7b0d55357

View File

@ -187,6 +187,7 @@ func TestBuildHealthCheckResponseList(t *testing.T) {
func TestHealthCheckHandlerReturnsJSON(t *testing.T) { func TestHealthCheckHandlerReturnsJSON(t *testing.T) {
toolbox.AddHealthCheck("database", &SampleDatabaseCheck{}) toolbox.AddHealthCheck("database", &SampleDatabaseCheck{})
toolbox.AddHealthCheck("cache", &SampleCacheCheck{})
req, err := http.NewRequest("GET", "/healthcheck?json=true", nil) req, err := http.NewRequest("GET", "/healthcheck?json=true", nil)
if err != nil { if err != nil {
@ -212,6 +213,11 @@ func TestHealthCheckHandlerReturnsJSON(t *testing.T) {
"message":"database", "message":"database",
"name":"success", "name":"success",
"status":"OK" "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) 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) { if !reflect.DeepEqual(decodedResponseBody, expectedResponseBody) {
t.Errorf("handler returned unexpected body: got %v want %v", t.Errorf("handler returned unexpected body: got %v want %v",
decodedResponseBody, expectedResponseBody) decodedResponseBody, expectedResponseBody)