forked from slack-go/slack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bots_test.go
50 lines (44 loc) · 1.2 KB
/
bots_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
package slack
import (
"net/http"
"testing"
)
func getBotInfo(rw http.ResponseWriter, r *http.Request) {
rw.Header().Set("Content-Type", "application/json")
response := []byte(`{"ok": true, "bot": {
"id":"B02875YLA",
"deleted":false,
"name":"github",
"icons": {
"image_36":"https:\/\/a.slack-edge.com\/2fac\/plugins\/github\/assets\/service_36.png",
"image_48":"https:\/\/a.slack-edge.com\/2fac\/plugins\/github\/assets\/service_48.png",
"image_72":"https:\/\/a.slack-edge.com\/2fac\/plugins\/github\/assets\/service_72.png"
}
}}`)
rw.Write(response)
}
func TestGetBotInfo(t *testing.T) {
http.HandleFunc("/bots.info", getBotInfo)
once.Do(startServer)
api := New("testing-token", OptionAPIURL("http://"+serverAddr+"/"))
bot, err := api.GetBotInfo("B02875YLA")
if err != nil {
t.Errorf("Unexpected error: %s", err)
return
}
if bot.ID != "B02875YLA" {
t.Fatal("Incorrect ID")
}
if bot.Name != "github" {
t.Fatal("Incorrect Name")
}
if len(bot.Icons.Image36) == 0 {
t.Fatal("Missing Image36")
}
if len(bot.Icons.Image48) == 0 {
t.Fatal("Missing Image38")
}
if len(bot.Icons.Image72) == 0 {
t.Fatal("Missing Image72")
}
}