-
-
Notifications
You must be signed in to change notification settings - Fork 101
/
fake_http_response_test.go
58 lines (46 loc) · 1.15 KB
/
fake_http_response_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
58
package main
import "strings"
type fakeHttpResponse struct {
statusCode int
location string
body []byte
headers map[string]string
}
func newFakeHttpResponse(statusCode int, location string, body []byte, headers map[string]string) *fakeHttpResponse {
hs := make(map[string]string, len(headers))
for k, v := range headers {
hs[strings.ToLower(k)] = v
}
return &fakeHttpResponse{statusCode, location, body, hs}
}
func newFakeHtmlResponse(location string, body string) *fakeHttpResponse {
return newFakeHttpResponse(
200,
location,
[]byte(body),
map[string]string{"content-type": "text/html"},
)
}
func newFakeXmlResponse(location string, body string) *fakeHttpResponse {
return newFakeHttpResponse(
200,
location,
[]byte(body),
map[string]string{"content-type": "application/xml"},
)
}
func (r *fakeHttpResponse) URL() string {
return r.location
}
func (r *fakeHttpResponse) StatusCode() int {
return r.statusCode
}
func (r *fakeHttpResponse) Header(name string) string {
if v, ok := r.headers[strings.ToLower(name)]; ok {
return v
}
return ""
}
func (r *fakeHttpResponse) Body() ([]byte, error) {
return r.body, nil
}