forked from bittersweet/notifilter-receive
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathslack_test.go
57 lines (47 loc) · 1.28 KB
/
slack_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
56
57
package main
import (
"net/http"
"net/http/httptest"
"net/url"
"testing"
)
func closeTestServer(test_server *httptest.Server) {
transport = nil
test_server.Close()
}
func createTestServer(handler func(w http.ResponseWriter, r *http.Request)) *httptest.Server {
test_server := httptest.NewServer(http.HandlerFunc(handler))
SetTransport(&http.Transport{Proxy: func(*http.Request) (*url.URL, error) { return url.Parse(test_server.URL) }})
return test_server
}
func returnTestResponseForPath(path string, dummy_response string, t *testing.T) *httptest.Server {
dummy_data := []byte(dummy_response)
return createTestServer(func(w http.ResponseWriter, r *http.Request) {
if r.URL.Path != path {
t.Error("Path doesn't match")
}
w.Write(dummy_data)
})
}
func TestSendSlack(t *testing.T) {
var resp string = `
{
"ok": true,
"channel": "C0434MV7L",
"ts": "1405895017.000506",
"message": {
"text": "User mark created",
"username": "Notifier",
"type": "message",
"subtype": "bot_message"
}
}
`
test_server := returnTestResponseForPath("/api/chat.postMessage", resp, t)
defer closeTestServer(test_server)
s := slackNotifier{}
notifierResponse := s.sendMessage("mark", []byte("Message"))
if notifierResponse.response.Ok != true {
t.Error("response is not correct")
}
}