-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathprometheusFeeder_test.go
63 lines (54 loc) · 1.62 KB
/
prometheusFeeder_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
package main
import (
"testing"
prom "github.com/prometheus/client_golang/prometheus"
"github.com/stretchr/testify/assert"
)
const ENV = "foobar"
func TestNewPrometheusFeeder(t *testing.T) {
feeder := newPrometheusFeeder(ENV, &healthCheckController{})
assert.NotNil(t, feeder)
assert.Equal(t, ENV, feeder.environment, "Environment should be set correctly.")
}
func TestInitServiceStatusMetrics(t *testing.T) {
gauge := initServiceStatusMetrics()
assert.NotNil(t, gauge)
duplicateGauge := prom.NewGaugeVec(
prom.GaugeOpts{
Namespace: "upp",
Subsystem: "health",
Name: "servicestatus",
Help: "Status of the service: 0 - healthy; 1 - unhealthy",
},
[]string{
"environment",
"service",
})
err := prom.Register(duplicateGauge)
assert.NotNil(t, err, "Gauge should've been registered already.")
_, ok := err.(prom.AlreadyRegisteredError)
assert.True(t, ok, "Expecting an 'AlreadyRegisteredError'.")
}
func TestIgnitePilotLight(t *testing.T) {
ignitePilotLight(ENV)
duplicateGauge := prom.NewGaugeVec(
prom.GaugeOpts{
Namespace: "upp",
Subsystem: "health",
Name: "pilotlight",
Help: "Pilot light for the service monitoring UPP service health",
},
[]string{
"environment",
})
err := prom.Register(duplicateGauge)
assert.NotNil(t, err, "Gauge should've been registered already.")
_, ok := err.(prom.AlreadyRegisteredError)
assert.True(t, ok, "Expecting an 'AlreadyRegisteredError'.")
}
func TestInverseBoolToFloat64(t *testing.T) {
one := inverseBoolToFloat64(false)
assert.Equal(t, float64(1), one)
zero := inverseBoolToFloat64(true)
assert.Equal(t, float64(0), zero)
}