mirror of
https://github.com/kemko/reproxy.git
synced 2026-01-01 15:55:49 +03:00
add total number of services to health error
This commit is contained in:
@@ -81,11 +81,12 @@ func (h *Http) healthHandler(w http.ResponseWriter, _ *http.Request) {
|
||||
w.WriteHeader(http.StatusExpectationFailed)
|
||||
|
||||
errResp := struct {
|
||||
Status string `json:"status,omitempty"`
|
||||
Passed int `json:"passed,omitempty"`
|
||||
Failed int `json:"failed,omitempty"`
|
||||
Errors []string `json:"errors,omitempty"`
|
||||
}{Status: "failed", Passed: valid, Failed: total - valid, Errors: errs}
|
||||
Status string `json:"status,omitempty"`
|
||||
Services int `json:"services,omitempty"`
|
||||
Passed int `json:"passed,omitempty"`
|
||||
Failed int `json:"failed,omitempty"`
|
||||
Errors []string `json:"errors,omitempty"`
|
||||
}{Status: "failed", Services: total, Passed: valid, Failed: total - valid, Errors: errs}
|
||||
|
||||
rest.RenderJSON(w, errResp)
|
||||
return
|
||||
|
||||
@@ -41,6 +41,7 @@ func TestHttp_healthHandler(t *testing.T) {
|
||||
svc := discovery.NewService([]discovery.Provider{
|
||||
&provider.Static{Rules: []string{
|
||||
"localhost,^/api/(.*)," + ds.URL + "/123/$1," + ps.URL + "/123/ping",
|
||||
"localhost,^/xyz/(.*)," + ds.URL + "/123/$1," + ps.URL + "/xxx/ping",
|
||||
"127.0.0.1,^/api/(.*)," + ds.URL + "/567/$1," + ps.URL + "/567/ping",
|
||||
},
|
||||
}}, time.Millisecond*10)
|
||||
@@ -67,7 +68,9 @@ func TestHttp_healthHandler(t *testing.T) {
|
||||
err = json.NewDecoder(resp.Body).Decode(&res)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, "failed", res["status"])
|
||||
assert.Equal(t, 3., res["services"])
|
||||
assert.Equal(t, 1., res["passed"])
|
||||
assert.Equal(t, 1., res["failed"])
|
||||
assert.Equal(t, 2., res["failed"])
|
||||
assert.Equal(t, 2, len(res["errors"].([]interface{})))
|
||||
assert.Contains(t, res["errors"].([]interface{})[0], "400 Bad Request")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user