-
Notifications
You must be signed in to change notification settings - Fork 0
/
channels_test.go
50 lines (39 loc) · 1.05 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
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()
_, err := http.Get(ts.URL)
if err != nil {
t.Fatal(err)
}
webhook := ts.URL
json := []byte(`{"content":"msg","someKey":"someValue","someOtherKey":"someOtherValue"}`)
err = SendRequest(webhook, json)
if err != nil {
t.Fatal(err)
}
if err != nil {
t.Error("SendRequest returned error: ", err)
}
}