-
Notifications
You must be signed in to change notification settings - Fork 14
/
collector_test.go
59 lines (52 loc) · 2.24 KB
/
collector_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
package kafka
import (
"reflect"
"testing"
"github.com/prometheus/client_golang/prometheus"
)
func Test_NewCollector(t *testing.T) {
t.Run("When_Default_Prefix_Value_Used", func(t *testing.T) {
cronsumerMetric := &ConsumerMetric{}
expectedTotalProcessedMessagesCounter := prometheus.NewDesc(
prometheus.BuildFQName(Name, "processed_messages_total", "current"),
"Total number of processed messages.",
emptyStringList,
nil,
)
expectedTotalUnprocessedMessagesCounter := prometheus.NewDesc(
prometheus.BuildFQName(Name, "unprocessed_messages_total", "current"),
"Total number of unprocessed messages.",
emptyStringList,
nil,
)
collector := NewMetricCollector("", cronsumerMetric)
if !reflect.DeepEqual(collector.totalProcessedMessagesCounter, expectedTotalProcessedMessagesCounter) {
t.Errorf("Expected: %+v, Actual: %+v", collector.totalProcessedMessagesCounter, expectedTotalProcessedMessagesCounter)
}
if !reflect.DeepEqual(collector.totalUnprocessedMessagesCounter, expectedTotalUnprocessedMessagesCounter) {
t.Errorf("Expected: %+v, Actual: %+v", collector.totalUnprocessedMessagesCounter, expectedTotalUnprocessedMessagesCounter)
}
})
t.Run("When_Custom_Prefix_Value_Used", func(t *testing.T) {
cronsumerMetric := &ConsumerMetric{}
expectedTotalProcessedMessagesCounter := prometheus.NewDesc(
prometheus.BuildFQName("custom_prefix", "processed_messages_total", "current"),
"Total number of processed messages.",
emptyStringList,
nil,
)
expectedTotalUnprocessedMessagesCounter := prometheus.NewDesc(
prometheus.BuildFQName("custom_prefix", "unprocessed_messages_total", "current"),
"Total number of unprocessed messages.",
emptyStringList,
nil,
)
collector := NewMetricCollector("custom_prefix", cronsumerMetric)
if !reflect.DeepEqual(collector.totalProcessedMessagesCounter, expectedTotalProcessedMessagesCounter) {
t.Errorf("Expected: %+v, Actual: %+v", collector.totalProcessedMessagesCounter, expectedTotalProcessedMessagesCounter)
}
if !reflect.DeepEqual(collector.totalUnprocessedMessagesCounter, expectedTotalUnprocessedMessagesCounter) {
t.Errorf("Expected: %+v, Actual: %+v", collector.totalUnprocessedMessagesCounter, expectedTotalUnprocessedMessagesCounter)
}
})
}