forked from oliver006/redis_exporter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtile38_test.go
65 lines (56 loc) · 1.56 KB
/
tile38_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
53
54
55
56
57
58
59
60
61
62
63
64
65
package exporter
import (
"os"
"strings"
"testing"
"github.com/prometheus/client_golang/prometheus"
)
func TestTile38(t *testing.T) {
if os.Getenv("TEST_TILE38_URI") == "" {
t.Skipf("TEST_TILE38_URI not set - skipping")
}
tsts := []struct {
addr string
isTile38 bool
wantTile38Metrics bool
}{
{addr: os.Getenv("TEST_TILE38_URI"), isTile38: true, wantTile38Metrics: true},
{addr: os.Getenv("TEST_TILE38_URI"), isTile38: false, wantTile38Metrics: false},
{addr: os.Getenv("TEST_REDIS_URI"), isTile38: true, wantTile38Metrics: false},
{addr: os.Getenv("TEST_REDIS_URI"), isTile38: false, wantTile38Metrics: false},
}
for _, tst := range tsts {
e, _ := NewRedisExporter(tst.addr, Options{Namespace: "test", IsTile38: tst.isTile38})
chM := make(chan prometheus.Metric)
go func() {
e.Collect(chM)
close(chM)
}()
wantedMetrics := map[string]bool{
"tile38_threads_total": false,
"tile38_cpus_total": false,
"tile38_go_goroutines_total": false,
"tile38_avg_item_size_bytes": false,
}
for m := range chM {
for want := range wantedMetrics {
if strings.Contains(m.Desc().String(), want) {
wantedMetrics[want] = true
}
}
}
if tst.wantTile38Metrics {
for want, found := range wantedMetrics {
if !found {
t.Errorf("%s was *not* found in tile38 metrics but expected", want)
}
}
} else if !tst.wantTile38Metrics {
for want, found := range wantedMetrics {
if found {
t.Errorf("%s was *found* in tile38 metrics but *not* expected", want)
}
}
}
}
}