forked from Tinkoff/prometheus-actions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
helpers_test.go
57 lines (52 loc) · 1.34 KB
/
helpers_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
package main
import (
"reflect"
"testing"
"github.com/prometheus/common/model"
"github.com/stretchr/testify/assert"
)
func TestStandardizeSpaces(t *testing.T) {
input := `line 1
line 2
line 3`
out := StandardizeSpaces(input)
assert.Equal(t, "line 1 line 2 line 3", out)
input = `
(
node_filesystem_free{instance="localhost", mountpoint="/var/lib/docker"} /
node_filesystem_size{instance="localhost", mountpoint="/var/lib/docker"}
) * 100 < 100
`
out = StandardizeSpaces(input)
assert.Equal(t, `( node_filesystem_free{instance="localhost", mountpoint="/var/lib/docker"} / node_filesystem_size{instance="localhost", mountpoint="/var/lib/docker"} ) * 100 < 100`, out)
}
func TestLabelSetEnviron(t *testing.T) {
tests := []struct {
in model.LabelSet
out []string
}{
{
in: model.LabelSet{
model.LabelName("__name__"): model.LabelValue("up"),
},
out: []string{
"LABEL___NAME___0=up",
},
},
{
in: model.LabelSet{
model.LabelName("__name__"): model.LabelValue("up"),
model.LabelName("instance"): model.LabelValue("127.0.0.1:9090"),
},
out: []string{
"LABEL___NAME___0=up",
"LABEL_INSTANCE_0=127.0.0.1:9090",
},
},
}
for _, test := range tests {
if !reflect.DeepEqual(test.out, LabelSetEnviron(0, test.in)) {
assert.Equal(t, test.out, LabelSetEnviron(0, test.in))
}
}
}