forked from mdlayher/prombolt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
prombolt_test.go
36 lines (29 loc) · 944 Bytes
/
prombolt_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
package prombolt
import (
"io/ioutil"
"net/http"
"net/http/httptest"
"testing"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
)
// testCollector performs a single metrics collection pass against the input
// prometheus.Collector, and returns a string containing metrics output.
func testCollector(t *testing.T, collector prometheus.Collector) string {
if err := prometheus.Register(collector); err != nil {
t.Fatalf("failed to register Prometheus collector: %v", err)
}
defer prometheus.Unregister(collector)
promServer := httptest.NewServer(promhttp.Handler())
defer promServer.Close()
resp, err := http.Get(promServer.URL)
if err != nil {
t.Fatalf("failed to GET data from prometheus: %v", err)
}
defer resp.Body.Close()
buf, err := ioutil.ReadAll(resp.Body)
if err != nil {
t.Fatalf("failed to read server response: %v", err)
}
return string(buf)
}