-
Notifications
You must be signed in to change notification settings - Fork 7
/
client_test.go
54 lines (42 loc) · 1.11 KB
/
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
package client
import (
"net/http"
"testing"
)
func TestMergeHeader(t *testing.T) {
cases := map[string]string{
"Content-Type": "text/plain",
"X-Test-1": "Value 1",
}
req, err := http.NewRequest("GET", "http://localhost:8080", nil)
if err != nil {
t.Errorf("Error creating request: %v", err)
}
// add some default to the original request header
req.Header.Set("Content-Type", "text/plain")
header := http.Header{}
header.Set("X-Test-1", "Value 1")
req = mergeHeader(req, header)
for test, exp := range cases {
res := req.Header.Get(test)
if res != exp {
t.Errorf("expected %s, got %s", exp, res)
}
}
// Test multipart requests
req, err = multipartForm("http://localhost:8080", NewValues(), nil)
if err != nil {
t.Errorf("Error creating multipart request: %v", err)
}
cases = map[string]string{
"Content-Type": req.Header.Get("Content-Type"), // will have header from multipartForm
"X-Test-1": "Value 1",
}
req = mergeHeader(req, header)
for test, exp := range cases {
res := req.Header.Get(test)
if res != exp {
t.Errorf("expected %s, got %s", exp, res)
}
}
}