forked from kbudde/rabbitmq_exporter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bertmap_test.go
79 lines (65 loc) · 2.07 KB
/
bertmap_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
69
70
71
72
73
74
75
76
77
78
79
package main
import (
"io/ioutil"
"testing"
"github.com/kylelemons/godebug/pretty"
)
func TestStatsEquivalence(t *testing.T) {
endpoints := []string{"queues", "exchanges", "nodes"}
labels := map[string][]string{
"queues": queueLabelKeys,
"exchanges": exchangeLabelKeys,
"nodes": nodeLabelKeys,
}
versions := []string{"3.6.8", "3.7.0"}
for _, version := range versions {
for _, endpoint := range endpoints {
base := endpoint + "-" + version
assertBertStatsEquivalence(t, base, labels[endpoint])
}
}
}
func TestMetricMapEquivalence(t *testing.T) {
endpoints := []string{"overview"}
versions := []string{"3.6.8", "3.7.0"}
for _, version := range versions {
for _, endpoint := range endpoints {
base := endpoint + "-" + version
assertBertMetricMapEquivalence(t, base)
}
}
}
func tryReadFiles(t *testing.T, base, firstExt, secondExt string) ([]byte, []byte) {
firstFile := "testdata/" + base + "." + firstExt
first, err := ioutil.ReadFile(firstFile)
if err != nil {
t.Fatalf("Error reading %s", firstFile)
}
secondFile := "testdata/" + base + "." + secondExt
second, err := ioutil.ReadFile(secondFile)
if err != nil {
t.Fatalf("Error reading %s", secondFile)
}
return first, second
}
func assertBertStatsEquivalence(t *testing.T, baseFileName string, labels []string) {
t.Helper()
json, bert := tryReadFiles(t, baseFileName, "json", "bert")
jsonReply := makeJSONReply(json)
bertReply := makeBERTReply(bert)
bertParsed := bertReply.MakeStatsInfo(labels)
jsonParsed := jsonReply.MakeStatsInfo(labels)
if diff := pretty.Compare(jsonParsed, bertParsed); diff != "" {
t.Errorf("JSON/BERT mismatch for %s:\n%s", baseFileName, diff)
}
}
func assertBertMetricMapEquivalence(t *testing.T, baseFileName string) {
json, bert := tryReadFiles(t, baseFileName, "json", "bert")
jsonReply := makeJSONReply(json)
bertReply := makeBERTReply(bert)
bertParsed := bertReply.MakeMap()
jsonParsed := jsonReply.MakeMap()
if diff := pretty.Compare(jsonParsed, bertParsed); diff != "" {
t.Errorf("JSON/BERT mismatch for %s:\n%s", baseFileName, diff)
}
}