-
Notifications
You must be signed in to change notification settings - Fork 107
/
client_test.go
70 lines (63 loc) · 1.34 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package main
import (
"net/http"
"reflect"
"sort"
"testing"
)
func TestBuildHeaders(t *testing.T) {
var testSet = []struct {
H string // headers passed via flag
Res map[string][]string
}{
{
"User-Agent:go-wrk 0.1 bechmark\nContent-Type:text/html;",
map[string][]string{
"User-Agent": []string{"go-wrk 0.1 bechmark"},
"Content-Type": []string{"text/html;"},
},
},
{
"Key:Value",
map[string][]string{
"Key": []string{"Value"},
},
},
{
"Key1:Value1\nKey2:Value2",
map[string][]string{
"Key1": []string{"Value1"},
"Key2": []string{"Value2"},
},
},
{
// the headers are set (not added) thus same key values
// are replaced.
"Key1:Value1A\nKey1:Value1B",
map[string][]string{
"Key1": []string{"Value1B"},
},
},
{
// a key with no value gets removed by design of the package.
"Key1",
map[string][]string{},
},
}
for _, set := range testSet {
tmpHeaders := http.Header{}
for k, v := range set.Res {
tmpHeaders[k] = append(tmpHeaders[k], v...)
sort.Strings(tmpHeaders[k])
}
headers, _ := buildHeaders(set.H)
for _, v := range headers {
sort.Strings(v)
}
// comparison; using the not very efficient reflect.DeepEqual
// because its a small test suite.
if !reflect.DeepEqual(tmpHeaders, headers) {
t.Errorf("Different results")
}
}
}