-
Notifications
You must be signed in to change notification settings - Fork 0
/
client_test.go
55 lines (46 loc) · 905 Bytes
/
client_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 http
import (
"bytes"
"strings"
"testing"
)
func TestDo(t *testing.T) {
req := &Request{
Method: "GET",
Host: "example.com",
Path: "/index.html",
}
c := NewClient()
resp, err := c.Do(req)
if err != nil {
t.Fatal(err)
}
if resp.Status != 200 {
t.Fatalf("\nwant:\t%d\ngot:\t%d\n", 200, resp.Status)
}
contentType := "text/html; charset=UTF-8"
if resp.Header["Content-Type"] != contentType {
t.Fatalf("\nwant:\t%s\ngot:\t%s\n", contentType, resp.Header["Content-Type"])
}
}
func TestRawRequest(t *testing.T) {
req := &Request{
Method: "GET",
Header: Header{
"Key": "Value",
},
Host: "example.com",
Port: 80,
Body: strings.NewReader("_"),
}
buf := bytes.NewBuffer(nil)
write(buf, req)
got := buf.String()
want := `GET / HTTP/1.1
Host: example.com:80
Key: Value
_`
if got != want {
t.Fatalf("expected:\t%s\nactual:\t%s\n", want, got)
}
}