-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathserve_mux_test.go
45 lines (38 loc) · 1.04 KB
/
serve_mux_test.go
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
39
40
41
42
43
44
45
package promhttp_test
import (
"net/http"
"net/http/httptest"
"testing"
"github.com/prometheus/client_golang/prometheus"
"github.com/travelaudience/go-promhttp"
)
func TestServeMux(t *testing.T) {
mux := &promhttp.ServeMux{
ServeMux: &http.ServeMux{},
}
reg := prometheus.NewRegistry()
mux.Handle("/a", http.HandlerFunc(func(_ http.ResponseWriter, _ *http.Request) {
t.Log("handler a")
}))
mux.Handle("/b", http.HandlerFunc(func(_ http.ResponseWriter, _ *http.Request) {
t.Log("handler b")
}))
mux.HandleFunc("/c", func(_ http.ResponseWriter, _ *http.Request) {
t.Log("handler c")
})
reg.Register(mux)
srv := httptest.NewServer(mux)
defer srv.Close()
for i := 0; i < 10; i++ {
if _, err := http.Get(srv.URL + "/a"); err != nil {
t.Fatalf("unexpected error: %s", err.Error())
}
if _, err := http.Get(srv.URL + "/b"); err != nil {
t.Fatalf("unexpected error: %s", err.Error())
}
if _, err := http.Get(srv.URL + "/c"); err != nil {
t.Fatalf("unexpected error: %s", err.Error())
}
}
assertMetrics(t, reg, 15)
}