-
Notifications
You must be signed in to change notification settings - Fork 2
/
jitsiexporter_test.go
68 lines (54 loc) · 1.75 KB
/
jitsiexporter_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
66
67
68
// nolint: goerr113
package jitsiexporter_test
import (
"errors"
"fmt"
"testing"
"git.xsfx.dev/prometheus/jitsiexporter"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/testutil"
"github.com/stretchr/testify/assert"
)
func TestUpdate(t *testing.T) {
assert := assert.New(t)
s := make(map[string]interface{})
s["foo"] = "foo"
s["bar"] = 1
s["zonk"] = float64(1)
mockStater := &jitsiexporter.MockStater{}
mockStater.On("Now", "http://foo.tld").Return(s, nil)
m := &jitsiexporter.Metrics{
URL: "http://foo.tld",
Metrics: make(map[string]jitsiexporter.Metric),
Stater: mockStater,
}
err := m.Update()
assert.Empty(err)
assert.Equal(float64(1), testutil.ToFloat64(m.Metrics["jitsi_zonk"].Gauge))
assert.Equal(jitsiexporter.Metric{Name: "", Gauge: prometheus.Gauge(nil)}, m.Metrics["jitsi_foo"])
assert.Equal(jitsiexporter.Metric{Name: "", Gauge: prometheus.Gauge(nil)}, m.Metrics["jitsi_bar"])
assert.Equal(len(m.Metrics), 1)
}
func TestUpdateOnError(t *testing.T) {
assert := assert.New(t)
mockStater := &jitsiexporter.MockStater{}
mockStater.On("Now", "http://foo.tld").Return(nil, errors.New("something went foo"))
e := prometheus.NewCounter(prometheus.CounterOpts{Name: "jitsi_fetch_errors"})
metricsMap := make(map[string]jitsiexporter.Metric)
metricsMap["testmetric"] = jitsiexporter.Metric{
Name: "testmetric",
Gauge: prometheus.NewGauge(prometheus.GaugeOpts{Name: "jitsi_testmetric"}),
}
m := &jitsiexporter.Metrics{
URL: "http://foo.tld",
Metrics: metricsMap,
Stater: mockStater,
Errors: e,
}
assert.Equal(1, len(m.Metrics))
err := m.Update()
fmt.Println(err)
assert.NotEmpty(err)
assert.Equal(0, len(m.Metrics))
assert.Equal(float64(1), testutil.ToFloat64(e))
}