This repository has been archived by the owner on Feb 19, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
/
mapper_test.go
96 lines (89 loc) · 1.7 KB
/
mapper_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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
package main
import "testing"
func Test_rename_metric(t *testing.T) {
cases := []struct {
source string
expect string
}{
{
source: "Foo",
expect: "foo",
}, {
source: "foo_bar",
expect: "foo_bar",
}, {
source: "foo.bar",
expect: "foo_bar",
}, {
source: "foo-bar",
expect: "foo_bar",
}, {
source: "foo$bar",
expect: "foo_bar",
}, {
source: "foo(bar)",
expect: "foo_bar",
},
}
for _, c := range cases {
name, _ := renameMetric(c.source)
if name != c.expect {
t.Errorf("expected metric named %s, got %s", c.expect, name)
}
}
}
func Test_rename_jobs_metric(t *testing.T) {
cases := []struct {
source string
expect string
labels map[string]string
}{
{
source: "jobs.run.foo.bar",
expect: "jobs_run_foo",
labels: map[string]string{
"chronos_job": "bar",
},
},
}
for _, c := range cases {
metricName, labels := renameMetric(c.source)
if metricName != c.expect {
t.Errorf("expected rate named %s, but was %s", c.expect, metricName)
}
for labelName, labelValue := range labels {
if expectValue := c.labels[labelName]; labelValue != expectValue {
t.Errorf("expected %s value %s, but was %s", labelName, expectValue, labelValue)
}
}
}
}
func Test_rename_rate(t *testing.T) {
cases := []struct {
name string
expect string
}{
{
name: "mean_rate",
expect: "mean",
}, {
name: "m1_rate",
expect: "1m",
}, {
name: "m5_rate",
expect: "5m",
}, {
name: "m15_rate",
expect: "15m",
}, {
name: "foo",
expect: "foo",
},
}
for _, c := range cases {
name := renameRate(c.name)
if name != c.expect {
t.Errorf("expected rate named %s, got %s", c.expect, name)
}
}
}