Commit 4010d9fa authored by Will Cory's avatar Will Cory

feat(api): Add healthz endpoint

parent 684bd2d6
...@@ -70,6 +70,10 @@ func (a *Api) WithdrawalsHandler(w http.ResponseWriter, r *http.Request) { ...@@ -70,6 +70,10 @@ func (a *Api) WithdrawalsHandler(w http.ResponseWriter, r *http.Request) {
jsonResponse(w, response, http.StatusOK) jsonResponse(w, response, http.StatusOK)
} }
func (a *Api) HealthzHandler(w http.ResponseWriter, r *http.Request) {
jsonResponse(w, "ok", http.StatusOK)
}
func jsonResponse(w http.ResponseWriter, data interface{}, statusCode int) { func jsonResponse(w http.ResponseWriter, data interface{}, statusCode int) {
w.Header().Set("Content-Type", "application/json") w.Header().Set("Content-Type", "application/json")
w.WriteHeader(statusCode) w.WriteHeader(statusCode)
...@@ -95,6 +99,7 @@ func NewApi(bv database.BridgeView) *Api { ...@@ -95,6 +99,7 @@ func NewApi(bv database.BridgeView) *Api {
// with go-ethereum and throw a friendly error message // with go-ethereum and throw a friendly error message
r.Get("/api/v0/deposits/{address:.+}", api.DepositsHandler) r.Get("/api/v0/deposits/{address:.+}", api.DepositsHandler)
r.Get("/api/v0/withdrawals/{address:.+}", api.WithdrawalsHandler) r.Get("/api/v0/withdrawals/{address:.+}", api.WithdrawalsHandler)
r.Get("/healthz", api.HealthzHandler)
return api return api
......
...@@ -44,6 +44,17 @@ func (mbv *MockBridgeView) WithdrawalsByAddress(address common.Address) ([]*data ...@@ -44,6 +44,17 @@ func (mbv *MockBridgeView) WithdrawalsByAddress(address common.Address) ([]*data
}, nil }, nil
} }
func TestHealthz(t *testing.T) {
api := NewApi(&MockBridgeView{})
request, err := http.NewRequest("GET", "/healthz", nil)
assert.Nil(t, err)
responseRecorder := httptest.NewRecorder()
api.Router.ServeHTTP(responseRecorder, request)
assert.Equal(t, http.StatusOK, responseRecorder.Code)
}
func TestDepositsHandler(t *testing.T) { func TestDepositsHandler(t *testing.T) {
api := NewApi(&MockBridgeView{}) api := NewApi(&MockBridgeView{})
request, err := http.NewRequest("GET", "/api/v0/deposits/0x123", nil) request, err := http.NewRequest("GET", "/api/v0/deposits/0x123", nil)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment