From 3985010a171262becc9ca1b9d0395662cde9880c Mon Sep 17 00:00:00 2001 From: David Dworken Date: Sat, 26 Nov 2022 22:53:14 -0800 Subject: [PATCH] Add test for the healthcheck endpoint --- backend/server/server_test.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/backend/server/server_test.go b/backend/server/server_test.go index b08e0c3..59801d3 100644 --- a/backend/server/server_test.go +++ b/backend/server/server_test.go @@ -503,6 +503,24 @@ func TestDeletionRequests(t *testing.T) { assertNoLeakedConnections(t, GLOBAL_DB) } +func TestHealthcheck(t *testing.T) { + w := httptest.NewRecorder() + healthCheckHandler(context.Background(), w, httptest.NewRequest(http.MethodGet, "/", nil)) + if w.Code != 200 { + t.Fatalf("expected 200 resp code for healthCheckHandler") + } + res := w.Result() + defer res.Body.Close() + respBody, err := ioutil.ReadAll(res.Body) + testutils.Check(t, err) + if string(respBody) != "OK" { + t.Fatalf("expected healthcheckHandler to return OK") + } + + // Assert that we aren't leaking connections + assertNoLeakedConnections(t, GLOBAL_DB) +} + func assertNoLeakedConnections(t *testing.T, db *gorm.DB) { sqlDB, err := db.DB() if err != nil {