forked from slack-go/slack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
chat_test.go
32 lines (28 loc) · 870 Bytes
/
chat_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
package slack
import (
"encoding/json"
"net/http"
"testing"
)
func postMessageInvalidChannelHandler(rw http.ResponseWriter, r *http.Request) {
rw.Header().Set("Content-Type", "application/json")
response, _ := json.Marshal(chatResponseFull{
SlackResponse: SlackResponse{Ok: false, Error: "channel_not_found"},
})
rw.Write(response)
}
func TestPostMessageInvalidChannel(t *testing.T) {
http.HandleFunc("/chat.postMessage", postMessageInvalidChannelHandler)
once.Do(startServer)
SLACK_API = "http://" + serverAddr + "/"
api := New("testing-token")
_, _, err := api.PostMessage("CXXXXXXXX", "hello", PostMessageParameters{})
if err == nil {
t.Errorf("Expected error: %s; instead succeeded", "channel_not_found")
return
}
if err.Error() != "channel_not_found" {
t.Errorf("Expected error: %s; received: %s", "channel_not_found", err)
return
}
}