first commit
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"testing"
|
||||
|
||||
"browser.local/platform/dto"
|
||||
)
|
||||
|
||||
func TestHealthHandler(t *testing.T) {
|
||||
req := httptest.NewRequest(http.MethodGet, "/healthz", nil)
|
||||
rec := httptest.NewRecorder()
|
||||
|
||||
HealthHandler(rec, req)
|
||||
|
||||
if rec.Code != http.StatusOK {
|
||||
t.Fatalf("expected status %d, got %d", http.StatusOK, rec.Code)
|
||||
}
|
||||
|
||||
var body dto.HealthResponse
|
||||
if err := json.NewDecoder(rec.Body).Decode(&body); err != nil {
|
||||
t.Fatalf("decode response: %v", err)
|
||||
}
|
||||
|
||||
if body.Service != "platform" || body.Status != "ok" || body.Version == "" || body.Time == "" {
|
||||
t.Fatalf("unexpected health body: %+v", body)
|
||||
}
|
||||
}
|
||||
|
||||
func TestHealthHandlerRejectsUnsupportedMethods(t *testing.T) {
|
||||
req := httptest.NewRequest(http.MethodPost, "/healthz", nil)
|
||||
rec := httptest.NewRecorder()
|
||||
|
||||
HealthHandler(rec, req)
|
||||
|
||||
if rec.Code != http.StatusMethodNotAllowed {
|
||||
t.Fatalf("expected status %d, got %d", http.StatusMethodNotAllowed, rec.Code)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user