MCPcopy Create free account
hub / github.com/chainreactors/EvilProxy / TestHealthz

Function TestHealthz

internal/api/server_test.go:59–94  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

57}
58
59func TestHealthz(t *testing.T) {
60 server := newTestServer(t)
61
62 t.Run("GET", func(t *testing.T) {
63 req := httptest.NewRequest(http.MethodGet, "/healthz", nil)
64 rr := httptest.NewRecorder()
65 server.engine.ServeHTTP(rr, req)
66
67 if rr.Code != http.StatusOK {
68 t.Fatalf("unexpected status code: got %d want %d; body=%s", rr.Code, http.StatusOK, rr.Body.String())
69 }
70
71 var resp struct {
72 Status string `json:"status"`
73 }
74 if err := json.Unmarshal(rr.Body.Bytes(), &resp); err != nil {
75 t.Fatalf("failed to parse response JSON: %v; body=%s", err, rr.Body.String())
76 }
77 if resp.Status != "ok" {
78 t.Fatalf("unexpected response status: got %q want %q", resp.Status, "ok")
79 }
80 })
81
82 t.Run("HEAD", func(t *testing.T) {
83 req := httptest.NewRequest(http.MethodHead, "/healthz", nil)
84 rr := httptest.NewRecorder()
85 server.engine.ServeHTTP(rr, req)
86
87 if rr.Code != http.StatusOK {
88 t.Fatalf("unexpected status code: got %d want %d; body=%s", rr.Code, http.StatusOK, rr.Body.String())
89 }
90 if rr.Body.Len() != 0 {
91 t.Fatalf("expected empty body for HEAD request, got %q", rr.Body.String())
92 }
93 })
94}
95
96func TestManagementResponseExposesPluginSupportHeaderForCORS(t *testing.T) {
97 t.Setenv("MANAGEMENT_PASSWORD", "test-management-key")

Callers

nothing calls this directly

Calls 5

RunMethod · 0.80
BytesMethod · 0.80
LenMethod · 0.80
newTestServerFunction · 0.70
StringMethod · 0.45

Tested by

no test coverage detected