forked from hiboxsystems/redis_sentinel_exporter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sentinel_info_test.go
63 lines (56 loc) · 1.33 KB
/
sentinel_info_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
package main
import (
"bytes"
"io/ioutil"
"testing"
"github.com/stretchr/testify/assert"
)
func TestParseValue(t *testing.T) {
cases := map[string]interface{}{
"ok": 1.0,
"down": 0.0,
"fail": 0.0,
"13.0": 13.0,
"foobar": "foobar",
}
for in, out := range cases {
assert.Equal(t, out, ParseValue(in))
}
}
func TestParseMasterInfo(t *testing.T) {
masterA := ParseMasterInfo("foobar,foo=bar,name=mymaster,status=ok,address=127.0.0.1:6379,slaves=2,sentinels=3")
assert.NotNil(t, masterA)
assert.Equal(t, "mymaster", masterA.Metrics["name"].(string))
_, ok := masterA.Metrics["foobar"]
assert.False(t, ok)
_, ok = masterA.Metrics["foo"]
assert.False(t, ok)
assert.Equal(t, 1.0, masterA.Metrics["status"].(float64))
}
func TestParseInfo(t *testing.T) {
tests := []struct {
filename string
master bool
}{
{
filename: "test_data/case-1",
master: true,
},
{
filename: "test_data/case-2",
},
}
for _, test := range tests {
b, err := ioutil.ReadFile(test.filename)
if err != nil {
t.Fatal(err)
}
b = bytes.Replace(b, []byte("\n"), []byte("\r\n"), -1)
metricRequiredKeys := metricBuildInfo
for metricName := range metricMap {
metricRequiredKeys = append(metricRequiredKeys, metricName)
}
si := ParseInfo(string(b), metricRequiredKeys, test.master)
assert.NotNil(t, si)
}
}