forked from philchia/agollo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
request_test.go
46 lines (38 loc) · 915 Bytes
/
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
package agollo
import (
"bytes"
"net/http"
"net/http/httptest"
"testing"
)
func TestRequest(t *testing.T) {
request := newHTTPRequester(&http.Client{})
serv := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {
rw.Write([]byte("test"))
}))
bts, err := request.request(serv.URL)
if err != nil {
t.Error(err)
}
if !bytes.Equal(bts, []byte("test")) {
t.FailNow()
}
serv = httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {
rw.WriteHeader(http.StatusInternalServerError)
}))
bts, err = request.request(serv.URL)
if err != nil {
t.Error(err)
}
if len(bts) != 0 {
t.FailNow()
}
serv = httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {
rw.WriteHeader(http.StatusInternalServerError)
}))
serv.Close()
_, err = request.request(serv.URL)
if err == nil {
t.FailNow()
}
}