-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain_test.go
More file actions
38 lines (32 loc) · 999 Bytes
/
Copy pathmain_test.go
File metadata and controls
38 lines (32 loc) · 999 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
35
36
37
38
package main
import (
"net/http"
"net/http/httptest"
"strings"
"testing"
"github.com/prometheus/client_golang/prometheus"
)
func TestMetricsHandlerFor_DisablesCompression(t *testing.T) {
t.Parallel()
registry := prometheus.NewRegistry()
gauge := prometheus.NewGauge(prometheus.GaugeOpts{
Name: "ebeacon_metrics_handler_test",
Help: "test metric",
})
registry.MustRegister(gauge)
gauge.Set(1)
handler := metricsHandlerFor(registry, registry)
rec := httptest.NewRecorder()
req := httptest.NewRequest(http.MethodGet, "/metrics", nil)
req.Header.Set("Accept-Encoding", "gzip")
handler.ServeHTTP(rec, req)
if rec.Code != http.StatusOK {
t.Fatalf("status: got %d body %q", rec.Code, rec.Body.String())
}
if got := rec.Header().Get("Content-Encoding"); got != "" {
t.Fatalf("content-encoding: got %q want empty", got)
}
if body := rec.Body.String(); !strings.Contains(body, "ebeacon_metrics_handler_test") {
t.Fatalf("response body missing test metric: %q", body)
}
}