| 1 | package exporterscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/ |
| 2 | |
| 3 | import ( |
| 4 | "osscip-go gomod github.com/golang/go/src go1.25.0 os/" |
| 5 | "stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/" |
| 6 | "testingscip-go gomod github.com/golang/go/src go1.25.0 testing/" |
| 7 | |
| 8 | "github.com/prometheus/client_golang/prometheusscip-go gomod github.com/prometheus/client_golang v1.23.2 `github.com/prometheus/client_golang/prometheus`/" |
| 9 | ) |
| 10 | |
| 11 | func TestTile38scip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/TestTile38().(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#) { |
| 12 | if osscip-go gomod github.com/golang/go/src go1.25.0 os/.Getenvscip-go gomod github.com/golang/go/src go1.25.0 os/Getenv().("TEST_TILE38_URI") == "" { |
| 13 | t.Skipfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Skipf().("TEST_TILE38_URI not set - skipping") |
| 14 | } |
| 15 | |
| 16 | tsts := []struct { |
| 17 | addr string |
| 18 | isTile38 bool |
| 19 | wantTile38Metrics bool |
| 20 | }{ |
| 21 | {addr: osscip-go gomod github.com/golang/go/src go1.25.0 os/.Getenvscip-go gomod github.com/golang/go/src go1.25.0 os/Getenv().("TEST_TILE38_URI"), isTile38: true, wantTile38Metrics: true}, |
| 22 | {addr: osscip-go gomod github.com/golang/go/src go1.25.0 os/.Getenvscip-go gomod github.com/golang/go/src go1.25.0 os/Getenv().("TEST_TILE38_URI"), isTile38: false, wantTile38Metrics: false}, |
| 23 | {addr: osscip-go gomod github.com/golang/go/src go1.25.0 os/.Getenvscip-go gomod github.com/golang/go/src go1.25.0 os/Getenv().("TEST_REDIS_URI"), isTile38: true, wantTile38Metrics: false}, |
| 24 | {addr: osscip-go gomod github.com/golang/go/src go1.25.0 os/.Getenvscip-go gomod github.com/golang/go/src go1.25.0 os/Getenv().("TEST_REDIS_URI"), isTile38: false, wantTile38Metrics: false}, |
| 25 | } |
| 26 | |
| 27 | for _, tst := range tsts { |
| 28 | e, _ := NewRedisExporterscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/NewRedisExporter().(tst.addr, Optionsscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/Options#{Namespacescip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/Options#Namespace.: "test", IsTile38scip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/Options#IsTile38.: tst.isTile38}) |
| 29 | |
| 30 | chM := make(chan prometheusscip-go gomod github.com/prometheus/client_golang v1.23.2 `github.com/prometheus/client_golang/prometheus`/.Metricscip-go gomod github.com/prometheus/client_golang v1.23.2 `github.com/prometheus/client_golang/prometheus`/Metric#) |
| 31 | go func() { |
| 32 | e.Collectscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/Exporter#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 stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/.Containsscip-go gomod github.com/golang/go/src go1.25.0 strings/Contains().(m.Descscip-go gomod github.com/prometheus/client_golang v1.23.2 `github.com/prometheus/client_golang/prometheus`/Metric#Desc().().Stringscip-go gomod github.com/prometheus/client_golang v1.23.2 `github.com/prometheus/client_golang/prometheus`/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.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#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.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("%s was *found* in tile38 metrics but *not* expected", want) |
| 61 | } |
| 62 | } |
| 63 | } |
| 64 | } |
| 65 | } |