mirror of
https://github.com/astaxie/beego.git
synced 2025-07-07 06:40:19 +00:00
added test for buildingHealthCheckResponse
This commit is contained in:
@ -149,6 +149,41 @@ func TestHealthCheckHandlerDefault(t *testing.T) {
|
||||
|
||||
}
|
||||
|
||||
func TestBuildHealthCheckResponseList(t *testing.T) {
|
||||
healthCheckResults := [][]string{
|
||||
[]string{
|
||||
"error",
|
||||
"Database",
|
||||
"Error occured whie starting the db",
|
||||
},
|
||||
[]string{
|
||||
"success",
|
||||
"Cache",
|
||||
"Cache started successfully",
|
||||
},
|
||||
}
|
||||
|
||||
responseList := buildHealthCheckResponseList(&healthCheckResults)
|
||||
|
||||
if len(responseList) != len(healthCheckResults) {
|
||||
t.Errorf("invalid response map length: got %d want %d",
|
||||
len(responseList), len(healthCheckResults))
|
||||
}
|
||||
|
||||
responseFields := []string{"name", "message", "status"}
|
||||
|
||||
for _, response := range responseList {
|
||||
for _, field := range responseFields {
|
||||
_, ok := response[field]
|
||||
if !ok {
|
||||
t.Errorf("expected %s to be in the response %v", field, response)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func TestHealthCheckHandlerReturnsJSON(t *testing.T) {
|
||||
|
||||
toolbox.AddHealthCheck("database", &SampleDatabaseCheck{})
|
||||
|
Reference in New Issue
Block a user