mirror of
https://github.com/ddworken/hishtory.git
synced 2025-02-17 02:50:49 +01:00
Add test for the healthcheck endpoint
This commit is contained in:
parent
22330f3ee1
commit
3985010a17
@ -503,6 +503,24 @@ func TestDeletionRequests(t *testing.T) {
|
|||||||
assertNoLeakedConnections(t, GLOBAL_DB)
|
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) {
|
func assertNoLeakedConnections(t *testing.T, db *gorm.DB) {
|
||||||
sqlDB, err := db.DB()
|
sqlDB, err := db.DB()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user