aboutsummaryrefslogtreecommitdiffstats
path: root/src/k8splugin/api
diff options
context:
space:
mode:
Diffstat (limited to 'src/k8splugin/api')
-rw-r--r--src/k8splugin/api/healthcheckhandler.go5
-rw-r--r--src/k8splugin/api/healthcheckhandler_test.go24
2 files changed, 28 insertions, 1 deletions
diff --git a/src/k8splugin/api/healthcheckhandler.go b/src/k8splugin/api/healthcheckhandler.go
index 896c6df0..2b338b94 100644
--- a/src/k8splugin/api/healthcheckhandler.go
+++ b/src/k8splugin/api/healthcheckhandler.go
@@ -31,5 +31,10 @@ func healthCheckHandler(w http.ResponseWriter, r *http.Request) {
return
}
+ err = db.Etcd.HealthCheck()
+ if err != nil {
+ http.Error(w, err.Error(), http.StatusInternalServerError)
+ return
+ }
w.WriteHeader(http.StatusOK)
}
diff --git a/src/k8splugin/api/healthcheckhandler_test.go b/src/k8splugin/api/healthcheckhandler_test.go
index c6c07c16..cadcf766 100644
--- a/src/k8splugin/api/healthcheckhandler_test.go
+++ b/src/k8splugin/api/healthcheckhandler_test.go
@@ -34,6 +34,9 @@ func TestHealthCheckHandler(t *testing.T) {
db.DBconn = &db.MockDB{
Err: nil,
}
+ db.Etcd = &db.MockEtcdClient{
+ Err: nil,
+ }
request := httptest.NewRequest("GET", "/v1/healthcheck", nil)
resp := executeRequest(request, NewRouter(nil, nil, nil, nil, nil, nil, nil, nil, nil))
@@ -43,10 +46,29 @@ func TestHealthCheckHandler(t *testing.T) {
}
})
- t.Run("FAILED HealthCheck", func(t *testing.T) {
+ t.Run("FAILED HealthCheck DB", func(t *testing.T) {
db.DBconn = &db.MockDB{
Err: pkgerrors.New("Runtime Error in DB"),
}
+ db.Etcd = &db.MockEtcdClient{
+ Err: nil,
+ }
+ request := httptest.NewRequest("GET", "/v1/healthcheck", nil)
+ resp := executeRequest(request, NewRouter(nil, nil, nil, nil, nil, nil, nil, nil, nil))
+
+ //Check returned code
+ if resp.StatusCode != http.StatusInternalServerError {
+ t.Fatalf("Expected %d; Got: %d", http.StatusInternalServerError, resp.StatusCode)
+ }
+ })
+
+ t.Run("FAILED HealthCheck Etcd", func(t *testing.T) {
+ db.DBconn = &db.MockDB{
+ Err: nil,
+ }
+ db.Etcd = &db.MockEtcdClient{
+ Err: pkgerrors.New("Runtime Error in Etcd"),
+ }
request := httptest.NewRequest("GET", "/v1/healthcheck", nil)
resp := executeRequest(request, NewRouter(nil, nil, nil, nil, nil, nil, nil, nil, nil))