-
Notifications
You must be signed in to change notification settings - Fork 76
/
nginx_exporter_test.go
43 lines (36 loc) · 764 Bytes
/
nginx_exporter_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
package main
import (
"net/http"
"net/http/httptest"
"testing"
"github.com/prometheus/client_golang/prometheus"
)
const (
nginxStatus = `Active connections: 91
server accepts handled requests
145249 145249 151557
Reading: 0 Writing: 24 Waiting: 66
`
metricCount = 8
)
func TestNginxStatus(t *testing.T) {
handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte(nginxStatus))
})
server := httptest.NewServer(handler)
e := NewExporter(server.URL)
ch := make(chan prometheus.Metric)
go func() {
defer close(ch)
e.Collect(ch)
}()
for i := 1; i <= metricCount; i++ {
m := <-ch
if m == nil {
t.Error("expected metric but got nil")
}
}
if <-ch != nil {
t.Error("expected closed channel")
}
}