-
Notifications
You must be signed in to change notification settings - Fork 6
/
incoming_test.go
55 lines (48 loc) · 1.12 KB
/
incoming_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
package bearychat
import "testing"
func TestValidateIncoming(t *testing.T) {
var m Incoming
m = Incoming{}
if err := m.Validate(); err == nil {
t.Errorf("text should not be empty: %+v", err)
}
m = Incoming{
Text: "test",
Attachments: []IncomingAttachment{{}},
}
if err := m.Validate(); err == nil {
t.Errorf("title or text should not be empty: %+v", err)
}
m = Incoming{
Text: "test",
Attachments: []IncomingAttachment{
{
Text: "test",
Images: []IncomingAttachmentImage{{}},
},
},
}
if err := m.Validate(); err == nil {
t.Errorf("image url should not be empty: %+v", err)
}
}
func ExampleIncoming() {
m := Incoming{
Text: "Hello, **BearyChat",
Notification: "Hello, BearyChat in notification",
Markdown: true,
Channel: "#所有人",
User: "@bearybot",
Attachments: []IncomingAttachment{
{Text: "attachment 1", Color: "#cb3f20"},
{Title: "attachment 2", Color: "#ffa500"},
{
Text: "愿原力与你同在",
Images: []IncomingAttachmentImage{
{URL: "http://img3.douban.com/icon/ul15067564-30.jpg"},
},
},
},
}
m.Build()
}