-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathwebhook_test.go
94 lines (77 loc) · 2.46 KB
/
webhook_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
package webhook
import (
"testing"
)
func TestWebHook(t *testing.T) {
webHook := NewWebHook("example-access-token")
payLoad := &PayLoad{}
webHook.APIURL = ""
err := webHook.sendPayload(payLoad)
if nil == err {
t.Error("api request error should be catch!")
}
webHook.APIURL = "http://google.com/"
err = webHook.sendPayload(payLoad)
if nil == err {
t.Error("api response error should be catch!")
}
webHook.AccessToken = ""
err = webHook.sendPayload(payLoad)
if nil == err {
t.Error("json unmarshal error should be catch!")
}
webHook.resetAPIURL()
err = webHook.sendPayload(payLoad)
if nil == err {
t.Error(err)
}
webHook.APIURL = "http://ip.cip.cc/"
err = webHook.sendPayload(payLoad)
if nil == err {
t.Error("response struct error should be catch!")
}
webHook.resetAPIURL()
webHook.AccessToken = "example-access-token"
payLoad = &PayLoad{
MsgType: "text",
Text: struct {
Content string `json:"content"`
}{
Content: "test msg",
},
}
// test send text message
err = webHook.SendTextMsg("Test text message", false, "")
if nil == err {
t.Error("token missing error should be catch!")
}
// test send link message
err = webHook.SendLinkMsg("A link message", "Click me to baidu search", "", "https://www.baidu.com")
if nil == err {
t.Error("token missing error should be catch!")
}
// test send markdown message
err = webHook.SendMarkdownMsg("A markdown message", "# This is title \n > Hello World", false, "13800138000")
if nil == err {
t.Error("token missing error should be catch!")
}
// test send action card message
err = webHook.SendActionCardMsg("A action card message", "This is a action card message", []string{}, []string{}, true, true)
if nil == err {
t.Error("links and titles cannot be null error should be catch!")
}
err = webHook.SendActionCardMsg("A action card message", "This is a action card message", []string{"Title 1"}, []string{}, true, true)
if nil == err {
t.Error("links and titles length not equal error should be catch!")
}
err = webHook.SendActionCardMsg("A action card message", "This is a action card message", []string{"Baidu Search"}, []string{"https://www.baidu.com"}, true, true)
if err == nil {
t.Error("token missing error should be catch!")
}
// test send link card message
err = webHook.SendLinkCardMsg([]LinkMsg{{Title: "Hello Bob", MessageURL: "https://www.google.com", PicURL: ""}})
if nil == err {
t.Error("token missing error should be catch!")
}
t.Log("All test had pass ..")
}