-
Notifications
You must be signed in to change notification settings - Fork 20
/
bot_test.go
55 lines (50 loc) · 1.18 KB
/
bot_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 wxworkbot
import (
"github.com/stretchr/testify/assert"
"net/http"
"os"
"testing"
"time"
)
func GetTestBotKey() string {
return os.Getenv("WXWORK_BOT_KEY")
}
func TestMarshalUnsupportedMessage(t *testing.T) {
text := struct {
Foo string
}{
Foo: "bar",
}
_, err := marshalMessage(text)
assert.Equal(t, ErrUnsupportedMessage, err)
}
func TestSendWithInvalidBotKey(t *testing.T) {
textMsg := textMessage{
Text: Text{
Content: "广州今日天气:29度,大部分多云,降雨概率:60%",
MentionedList: []string{"wangqing", "@all"},
MentionedMobileList: []string{"13800001111", "@all"},
},
}
bot := New("这是一个错误的 BOT KEY")
err := bot.Send(textMsg)
assert.NotNil(t, err)
}
func TestWithCustomHttpClient(t *testing.T) {
botKey := GetTestBotKey()
if len(botKey) == 0 {
return
}
bot := WxWorkBot{
Key: botKey,
Client: &http.Client{
Timeout: 1 * time.Second,
},
}
err := bot.Send(Text{
Content: "广州今日天气:29度,大部分多云,降雨概率:60%",
MentionedList: []string{"wangqing", "@all"},
MentionedMobileList: []string{"13800001111", "@all"},
})
assert.Nil(t, err)
}