Debian Codegraph @

exporter/tile38_test.go

raw symbols SCIP
1 package exporter
2
3 import (
4 "os"
5 "strings"
6 "testing"
7
8 "github.com/prometheus/client_golang/prometheus"
9 )
10
11 func TestTile38(t *testing.T) {
12 if os.Getenv("TEST_TILE38_URI") == "" {
13 t.Skipf("TEST_TILE38_URI not set - skipping")
14 }
15
16 tsts := []struct {
17 addr string
18 isTile38 bool
19 wantTile38Metrics bool
20 }{
21 {addr: os.Getenv("TEST_TILE38_URI"), isTile38: true, wantTile38Metrics: true},
22 {addr: os.Getenv("TEST_TILE38_URI"), isTile38: false, wantTile38Metrics: false},
23 {addr: os.Getenv("TEST_REDIS_URI"), isTile38: true, wantTile38Metrics: false},
24 {addr: os.Getenv("TEST_REDIS_URI"), isTile38: false, wantTile38Metrics: false},
25 }
26
27 for _, tst := range tsts {
28 e, _ := NewRedisExporter(tst.addr, Options{Namespace: "test", IsTile38: tst.isTile38})
29
30 chM := make(chan prometheus.Metric)
31 go func() {
32 e.Collect(chM)
33 close(chM)
34 }()
35
36 wantedMetrics := map[string]bool{
37 "tile38_threads_total": false,
38 "tile38_cpus_total": false,
39 "tile38_go_goroutines_total": false,
40 "tile38_avg_item_size_bytes": false,
41 }
42
43 for m := range chM {
44 for want := range wantedMetrics {
45 if strings.Contains(m.Desc().String(), want) {
46 wantedMetrics[want] = true
47 }
48 }
49 }
50
51 if tst.wantTile38Metrics {
52 for want, found := range wantedMetrics {
53 if !found {
54 t.Errorf("%s was *not* found in tile38 metrics but expected", want)
55 }
56 }
57 } else if !tst.wantTile38Metrics {
58 for want, found := range wantedMetrics {
59 if found {
60 t.Errorf("%s was *found* in tile38 metrics but *not* expected", want)
61 }
62 }
63 }
64 }
65 }