package http import ( "io" "net/http" "net/http/httptest" "testing" ) func TestHealthHandler(t *testing.T) { req := httptest.NewRequest(http.MethodGet, "/healthcheck", nil) w := httptest.NewRecorder() HealthHandler(w, req) res := w.Result() defer res.Body.Close() data, err := io.ReadAll(res.Body) if err != nil { t.Errorf("Expected error to be nil, got %v", err) } if res.StatusCode != http.StatusOK { t.Errorf("Expected status code 200, got %v", res.StatusCode) } if string(data) != "OK" { t.Errorf("Expected 'OK', got %v", string(data)) } } func TestRequestHandler(t *testing.T) { req := httptest.NewRequest(http.MethodGet, "/", nil) w := httptest.NewRecorder() RequestHandler(w, req) res := w.Result() defer res.Body.Close() _, err := io.ReadAll(res.Body) if err != nil { t.Errorf("Expected error to be nil, got %v", err) } if res.StatusCode != http.StatusTeapot { t.Errorf("Expected status code 418, got %v", res.StatusCode) } } func TestNotFound(t *testing.T) { req := httptest.NewRequest(http.MethodGet, "/metrics", nil) w := httptest.NewRecorder() NotFound(w, req) res := w.Result() defer res.Body.Close() _, err := io.ReadAll(res.Body) if err != nil { t.Errorf("Expected error to be nil, got %v", err) } if res.StatusCode != http.StatusNotFound { t.Errorf("Expected status code 404, got %v", res.StatusCode) } }