-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
main_test.go
129 lines (91 loc) · 2.87 KB
/
main_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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
package main
import (
"encoding/json"
"github.com/stretchr/testify/assert"
"os"
"testing"
)
func setupTestEnvironmentVariables() {
os.Setenv("HTTP_PORT", "Just testing...")
os.Setenv("MESSAGE", "Just testing...")
os.Setenv("NOTIFICATION_RULES", `[{"channel":"#test", "labels":["test"]}]`)
os.Setenv("REACTION_RULES", `[{"action":"approved", "reaction":"thumbsup"}]`)
os.Setenv("SLACK_AVATAR_URL", "Just testing...")
os.Setenv("SLACK_USERNAME", "Just testing...")
os.Setenv("SLACK_TOKEN", "xoxp-slack-token")
}
func TestEnvironmentMissingHttpPort(t *testing.T) {
defer func() { recover() }()
setupTestEnvironmentVariables()
os.Unsetenv("HTTP_PORT")
InitEnvironment()
t.Error("should panic about missing env: HTTP_PORT")
}
func TestEnvironmentMissingMessage(t *testing.T) {
defer func() { recover() }()
setupTestEnvironmentVariables()
os.Unsetenv("MESSAGE")
InitEnvironment()
t.Error("should panic about missing env: MESSAGE")
}
func TestEnvironmentMissingNotificationRules(t *testing.T) {
defer func() { recover() }()
setupTestEnvironmentVariables()
os.Unsetenv("NOTIFICATION_RULES")
InitEnvironment()
t.Error("should panic about missing env: NOTIFICATION_RULES")
}
func TestEnvironmentMissingReactionRules(t *testing.T) {
defer func() { recover() }()
setupTestEnvironmentVariables()
os.Unsetenv("REACTION_RULES")
InitEnvironment()
t.Error("should panic about missing env: REACTION_RULES")
}
func TestEnvironmentMissingSlackAvatarUrl(t *testing.T) {
defer func() { recover() }()
setupTestEnvironmentVariables()
os.Unsetenv("SLACK_AVATAR_URL")
InitEnvironment()
t.Error("should panic about missing env: SLACK_AVATAR_URL")
}
func TestEnvironmentMissingSlackUsername(t *testing.T) {
defer func() { recover() }()
setupTestEnvironmentVariables()
os.Unsetenv("SLACK_USERNAME")
InitEnvironment()
t.Error("should panic about missing env: SLACK_USERNAME")
}
func TestEnvironmentMissingSlackToken(t *testing.T) {
defer func() { recover() }()
setupTestEnvironmentVariables()
os.Unsetenv("SLACK_TOKEN")
InitEnvironment()
t.Error("should panic about missing env: SLACK_TOKEN")
}
func TestEnvironmentWithInvalidReactionRulesJson(t *testing.T) {
defer func() {
if r := recover(); r != nil {
ok := r.(*json.SyntaxError)
assert.ErrorContains(t, ok, "unexpected end of JSON input")
}
}()
setupTestEnvironmentVariables()
os.Unsetenv("REACTION_RULES")
os.Setenv("REACTION_RULES", `{"wrong`)
main()
t.Error("should panic invalid json on REACTION_RULES")
}
func TestEnvironmentWithInvalidNotificationRuleJson(t *testing.T) {
defer func() {
if r := recover(); r != nil {
ok := r.(*json.SyntaxError)
assert.ErrorContains(t, ok, "unexpected end of JSON input")
}
}()
setupTestEnvironmentVariables()
os.Unsetenv("NOTIFICATION_RULES")
os.Setenv("NOTIFICATION_RULES", `{"wrong`)
main()
t.Error("should panic invalid json on NOTIFICATION_RULES")
}