-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathclient_test.go
52 lines (43 loc) · 973 Bytes
/
client_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
46
47
48
49
50
51
52
package promhttp_test
import (
"crypto/tls"
"net/http"
"net/http/httptest"
"strings"
"testing"
"github.com/prometheus/client_golang/prometheus"
"github.com/travelaudience/go-promhttp"
)
func TestClient_ForRecipient(t *testing.T) {
r := prometheus.NewRegistry()
c := promhttp.Client{
Client: &http.Client{
Transport: &http.Transport{
TLSClientConfig: &tls.Config{
InsecureSkipVerify: true,
},
},
},
Registerer: r,
}
ca, err := c.ForRecipient("a")
if err != nil {
t.Fatalf("unexpected error: %s", err.Error())
}
cb, err := c.ForRecipient("b")
if err != nil {
t.Fatalf("unexpected error: %s", err.Error())
}
srv := httptest.NewTLSServer(http.NotFoundHandler())
defer srv.Close()
url := strings.Replace(srv.URL, "127.0.0.1", "localhost", 1)
for i := 0; i < 15; i++ {
if _, err := ca.Get(url); err != nil {
t.Fatal(err)
}
if _, err := cb.Get(url); err != nil {
t.Fatal(err)
}
}
assertMetrics(t, r, 14)
}