-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathslackmsg_test.go
More file actions
96 lines (86 loc) · 1.94 KB
/
Copy pathslackmsg_test.go
File metadata and controls
96 lines (86 loc) · 1.94 KB
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
package slackmsg_test
import (
"context"
"testing"
"time"
"github.com/spider-pigs/slackmsg"
)
func TestSimpleMsg(t *testing.T) {
// create message
msg := slackmsg.New()
msg.Text = "I am a test message!"
attachment := slackmsg.Attachment{
Text: "And here’s an attachment!",
}
msg.AddAttachment(attachment)
// send message
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
webhook := "https://hooks.slack.com..."
err := msg.Send(ctx, webhook)
if err == nil {
t.Error("error should be set")
}
json, err := msg.ToJSON()
if err != nil {
t.Error("error should not be set")
}
if len(json) == 0 {
t.Error("JSON string should not be empty")
}
}
func TestActionMsg(t *testing.T) {
// create message
msg := slackmsg.New()
msg.Text = "Would you like to play a game?"
attachment := slackmsg.Attachment{
Text: "Choose a game to play",
Fallback: "You are unable to choose a game",
CallbackID: "wopr_game",
Color: "#3AA3E3",
Type: "default",
Actions: []slackmsg.Action{
{
Name: "game",
Text: "Chess",
Type: "button",
Value: "chess",
},
{
Name: "game",
Text: "Falken's Maze",
Type: "button",
Value: "maze",
},
{
Name: "game",
Text: "Thermonuclear War",
Style: "danger",
Type: "button",
Value: "war",
Confirm: slackmsg.Confirm{
Title: "Are you sure?",
Text: "Wouldn't you prefer a good game of chess?",
OkText: "Yes",
DismissText: "No",
},
},
},
}
msg.AddAttachment(attachment)
// send message
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
webhook := "https://hooks.slack.com..."
err := msg.Send(ctx, webhook)
if err == nil {
t.Error("error should be set")
}
json, err := msg.ToJSON()
if err != nil {
t.Error("error should not be set")
}
if len(json) == 0 {
t.Error("JSON string should not be empty")
}
}