-
Notifications
You must be signed in to change notification settings - Fork 68
/
raw_request_test.go
57 lines (48 loc) · 1.04 KB
/
raw_request_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 bot
import (
"context"
"io"
"net/http"
"strings"
"testing"
)
type clientMock struct {
requestURI string
}
func (c *clientMock) Do(req *http.Request) (*http.Response, error) {
c.requestURI = req.URL.RequestURI()
resp := http.Response{
StatusCode: 200,
Body: io.NopCloser(strings.NewReader(`{"ok":true}`)),
}
return &resp, nil
}
func Test_rawRequest_url(t *testing.T) {
cm := &clientMock{}
b := &Bot{
token: "XXX",
client: cm,
}
err := b.rawRequest(context.Background(), "foo", nil, nil)
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
if cm.requestURI != "/botXXX/foo" {
t.Fatalf("unexpected requestURI: %s", cm.requestURI)
}
}
func Test_rawRequest_url_testEnv(t *testing.T) {
cm := &clientMock{}
b := &Bot{
token: "XXX",
client: cm,
testEnvironment: true,
}
err := b.rawRequest(context.Background(), "foo", nil, nil)
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
if cm.requestURI != "/botXXX/test/foo" {
t.Fatalf("unexpected requestURI: %s", cm.requestURI)
}
}