-
Notifications
You must be signed in to change notification settings - Fork 3
/
config_test.go
91 lines (74 loc) · 3.59 KB
/
config_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
package main
import (
"github.com/stretchr/testify/assert"
"testing"
)
func TestLoadConfigFromData(t *testing.T) {
yamlData := `name1:
check_url: "http://example.com/1"
type: slack
api_token: "xoxp-0000000000-0000000000-0000000000-000000"
webhook_url: "https://hooks.slack.com/services/XXXXXXXXX/XXXXXXXXX/XXXXXXXXXXXXXXXX"
user_name: "zatsu_monitor"
channel: "#general"
name2:
check_url: "http://example.com/2"
type: chatwork
api_token: "AAAAAAAA"
room_id: 111111`
config, err := LoadConfigFromData(yamlData)
assert.NoError(t, err)
assert.Equal(t, "http://example.com/1", config["name1"]["check_url"])
assert.Equal(t, "slack", config["name1"]["type"])
assert.Equal(t, "xoxp-0000000000-0000000000-0000000000-000000", config["name1"]["api_token"])
assert.Equal(t, "https://hooks.slack.com/services/XXXXXXXXX/XXXXXXXXX/XXXXXXXXXXXXXXXX", config["name1"]["webhook_url"])
assert.Equal(t, "zatsu_monitor", config["name1"]["user_name"])
assert.Equal(t, "#general", config["name1"]["channel"])
assert.Equal(t, "http://example.com/2", config["name2"]["check_url"])
assert.Equal(t, "chatwork", config["name2"]["type"])
assert.Equal(t, "AAAAAAAA", config["name2"]["api_token"])
assert.Equal(t, "111111", config["name2"]["room_id"])
}
func TestLoadConfigFromData2(t *testing.T) {
yamlData := `name1: &common
check_url: "http://example.com/1"
type: slack
api_token: "xoxp-0000000000-0000000000-0000000000-000000"
webhook_url: "https://hooks.slack.com/services/XXXXXXXXX/XXXXXXXXX/XXXXXXXXXXXXXXXX"
user_name: "zatsu_monitor"
channel: "#general"
name2:
<<: *common
channel: "#random"`
config, err := LoadConfigFromData(yamlData)
assert.NoError(t, err)
assert.Equal(t, "http://example.com/1", config["name1"]["check_url"])
assert.Equal(t, "slack", config["name1"]["type"])
assert.Equal(t, "xoxp-0000000000-0000000000-0000000000-000000", config["name1"]["api_token"])
assert.Equal(t, "https://hooks.slack.com/services/XXXXXXXXX/XXXXXXXXX/XXXXXXXXXXXXXXXX", config["name1"]["webhook_url"])
assert.Equal(t, "zatsu_monitor", config["name1"]["user_name"])
assert.Equal(t, "#general", config["name1"]["channel"])
assert.Equal(t, "http://example.com/1", config["name2"]["check_url"])
assert.Equal(t, "slack", config["name2"]["type"])
assert.Equal(t, "xoxp-0000000000-0000000000-0000000000-000000", config["name2"]["api_token"])
assert.Equal(t, "https://hooks.slack.com/services/XXXXXXXXX/XXXXXXXXX/XXXXXXXXXXXXXXXX", config["name2"]["webhook_url"])
assert.Equal(t, "zatsu_monitor", config["name2"]["user_name"])
assert.Equal(t, "#random", config["name2"]["channel"])
}
func TestLoadConfigFromFile(t *testing.T) {
config, err := LoadConfigFromFile("test/config.yml")
assert.NoError(t, err)
assert.Equal(t, "http://example.com/1", config["name1"]["check_url"])
assert.Equal(t, "slack", config["name1"]["type"])
assert.Equal(t, "xoxp-0000000000-0000000000-0000000000-000000", config["name1"]["api_token"])
assert.Equal(t, "https://hooks.slack.com/services/XXXXXXXXX/XXXXXXXXX/XXXXXXXXXXXXXXXX", config["name1"]["webhook_url"])
assert.Equal(t, "zatsu_monitor", config["name1"]["user_name"])
assert.Equal(t, "#general", config["name1"]["channel"])
assert.Equal(t, "", config["name1"]["check_only_top_of_status_code"])
assert.Equal(t, "http://example.com/2", config["name2"]["check_url"])
assert.Equal(t, "chatwork", config["name2"]["type"])
assert.Equal(t, "AAAAAAAA", config["name2"]["api_token"])
assert.Equal(t, "111111", config["name2"]["room_id"])
assert.Equal(t, "true", config["name3"]["check_only_top_of_status_code"])
assert.Equal(t, "false", config["name4"]["check_only_top_of_status_code"])
}