From b08f01695a107167946aa94b19b22c4968489078 Mon Sep 17 00:00:00 2001 From: Muhammad Faizan <130775084+MuhammadFaizan-prog@users.noreply.github.com> Date: Fri, 27 Nov 2026 19:21:49 +0500 Subject: [PATCH] feat(backend): add a public health endpoint Signed-off-by: Muhammad Faizan <130775084+MuhammadFaizan-prog@users.noreply.github.com> --- backend/cmd/server/main.go | 5 +++++ backend/cmd/server/main_test.go | 27 +++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 backend/cmd/server/main_test.go diff --git a/backend/cmd/server/main.go b/backend/cmd/server/main.go index c356ec24..10142461 100644 --- a/backend/cmd/server/main.go +++ b/backend/cmd/server/main.go @@ -2,6 +2,7 @@ package main import ( "log" + "net/http" "os" "strconv" "strings" @@ -105,6 +106,10 @@ func setupRouter(cfg *config.Config, configPath string) *gin.Engine { c.Status(204) }) + router.GET("/health", func(c *gin.Context) { + c.JSON(http.StatusOK, gin.H{"status": "ok"}) + }) + router.POST("/signup", routes.SignUpRouteHandler) router.POST("/verifyEmail", routes.VerifyEmailRouteHandler) router.POST("/login", routes.LoginRouteHandler) diff --git a/backend/cmd/server/main_test.go b/backend/cmd/server/main_test.go new file mode 100644 index 00000000..d4aff3aa --- /dev/null +++ b/backend/cmd/server/main_test.go @@ -0,0 +1,27 @@ +package main + +import ( + "encoding/json" + "net/http" + "net/http/httptest" + "testing" +) + +func TestHealthEndpoint(t *testing.T) { + router := setupRouter(nil, "") + response := httptest.NewRecorder() + router.ServeHTTP(response, httptest.NewRequest(http.MethodGet, "/health", nil)) + + if response.Code != http.StatusOK { + t.Fatalf("GET /health returned %d, want %d", response.Code, http.StatusOK) + } + var body struct { + Status string `json:"status"` + } + if err := json.Unmarshal(response.Body.Bytes(), &body); err != nil { + t.Fatalf("decode health response: %v", err) + } + if body.Status != "ok" { + t.Errorf("health status = %q, want %q", body.Status, "ok") + } +}