-
Notifications
You must be signed in to change notification settings - Fork 3
/
chatwork_notifier_test.go
70 lines (59 loc) · 1.43 KB
/
chatwork_notifier_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
package main
import (
"errors"
"github.com/joho/godotenv"
"github.com/stretchr/testify/assert"
"os"
"testing"
)
func NewTestChatworkNotifier() *ChatworkNotifier {
godotenv.Load()
apiToken := os.Getenv("TEST_CHATWORK_API_TOKEN")
roomID := os.Getenv("TEST_CHATWORK_ROOM_ID")
if len(apiToken) == 0 || len(roomID) == 0 {
return nil
}
return NewChatworkNotifier(apiToken, roomID)
}
func TestChatworkNotifier_PostStatus_True(t *testing.T) {
notifier := NewTestChatworkNotifier()
if notifier == nil {
return
}
param := PostStatusParam{
CheckURL: "https://www.google.co.jp/",
BeforeStatusCode: 500,
CurrentStatusCode: 200,
HTTPError: nil,
}
err := notifier.PostStatus(¶m)
assert.NoError(t, err)
}
func TestChatworkNotifier_PostStatus_False(t *testing.T) {
notifier := NewTestChatworkNotifier()
if notifier == nil {
return
}
param := PostStatusParam{
CheckURL: "https://www.google.co.jp/aaa",
BeforeStatusCode: 0,
CurrentStatusCode: 404,
HTTPError: nil,
}
err := notifier.PostStatus(¶m)
assert.NoError(t, err)
}
func TestChatworkNotifier_PostStatus_HasError(t *testing.T) {
notifier := NewTestChatworkNotifier()
if notifier == nil {
return
}
param := PostStatusParam{
CheckURL: "https://aaaaaaaaa/",
BeforeStatusCode: 0,
CurrentStatusCode: 0,
HTTPError: errors.New("Test"),
}
err := notifier.PostStatus(¶m)
assert.NoError(t, err)
}