-
Notifications
You must be signed in to change notification settings - Fork 0
/
slack_test.go
54 lines (44 loc) · 991 Bytes
/
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
package slack
import (
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
"net/http/httptest"
"testing"
)
func handler() http.Handler {
r := http.NewServeMux()
r.HandleFunc("/services", testHandler)
return r
}
func testHandler(w http.ResponseWriter, r *http.Request) {
body := r.Body
if body == nil {
http.Error(w, "missing value", http.StatusBadRequest)
return
}
defer body.Close()
var msg Message
b, _ := ioutil.ReadAll(r.Body)
err := json.Unmarshal(b, &msg)
if err != nil {
http.Error(w, "cannot unmarshal body", http.StatusBadRequest)
return
}
}
func TestSlack(t *testing.T) {
srv := httptest.NewServer(handler())
defer srv.Close()
slackURL := fmt.Sprintf("%s/services", srv.URL)
attachment1 := Attachment{}
attachment1.AddField(Field{Title: "Field", Value: "Field test value"})
msg := Message{
Text: "the is a slack test massage",
Attachments: []Attachment{attachment1},
}
err := Send(slackURL, msg)
if err != nil {
t.Error(err)
}
}