-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain_metrics_test.go
More file actions
34 lines (25 loc) · 866 Bytes
/
main_metrics_test.go
File metadata and controls
34 lines (25 loc) · 866 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package main
import (
"net/http/httptest"
"strings"
"testing"
)
func TestMetricsHandlerPublic(t *testing.T) {
server := createTestMainServer()
// Record a sample metric so the exposition contains the HTTP requests metric
server.metrics.RecordHTTPRequest("GET", "public", "200")
handler := server.metricsHandler()
req := httptest.NewRequest("GET", "/metrics", nil)
w := httptest.NewRecorder()
handler.ServeHTTP(w, req)
if w.Code != 200 {
t.Fatalf("Expected status 200, got %d", w.Code)
}
body := w.Body.String()
if !strings.Contains(body, "patchwork_http_requests_total") {
t.Errorf("Expected metrics output to contain 'patchwork_http_requests_total', got: %s", body)
}
if !strings.Contains(body, "# HELP") || !strings.Contains(body, "# TYPE") {
t.Errorf("Expected metrics exposition to contain HELP/TYPE comments, got: %s", body)
}
}