-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathchannels_test.go
55 lines (43 loc) · 1.18 KB
/
channels_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 main
import (
"net/http"
"net/http/httptest"
"testing"
)
func TestPreparePayload(t *testing.T) {
message := "msg"
textField := "content"
additionalData := "{\"someKey\":\"someValue\",\"someOtherKey\":\"someOtherValue\"}"
json, err := PreparePayload(message, textField, additionalData)
if err != nil {
t.Fatal("PreparePayload returned error: ", err)
}
strJSON := string(json)
expectedValue := `{"content":"msg","someKey":"someValue","someOtherKey":"someOtherValue"}`
if strJSON != expectedValue {
t.Errorf("Expected %s, got %s", expectedValue, strJSON)
}
}
func TestSendRequest(t *testing.T) {
// 1. start web server
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
}))
defer ts.Close()
res, err := http.Get(ts.URL)
if err != nil {
t.Fatal(err)
}
webhook := ts.URL
json := []byte(`{"content":"msg","someKey":"someValue","someOtherKey":"someOtherValue"}`)
resp, err := SendRequest(webhook, json)
res.Body.Close()
if err != nil {
t.Fatal(err)
}
if err != nil {
t.Fatal("SendRequest returned error: ", err)
}
if resp.StatusCode != 200 {
t.Errorf("Expected status code %d, got %d", 200, resp.StatusCode)
}
}