/
header_list_test.go
80 lines (69 loc) · 1.72 KB
/
header_list_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
71
72
73
74
75
76
77
78
79
80
package hpack
import (
assert "github.com/Jxck/assertion"
"net/http"
"sort"
"testing"
)
func TestNewHeaderList(t *testing.T) {
header := make(http.Header)
header.Add("method", "get")
header.Add("host", "example.com")
header.Add(":authority", "example.com")
header.Add("cookie", "a")
header.Add("cookie", "b")
actual := ToHeaderList(header)
expected := &HeaderList{
{"method", "get"},
{"host", "example.com"},
{":authority", "example.com"},
{"cookie", "a"},
{"cookie", "b"},
}
sort.Sort(actual)
sort.Sort(expected)
assert.Equal(t, actual, expected)
}
func TestToHeader(t *testing.T) {
header := make(http.Header)
header.Add("method", "get")
header.Add("host", "example.com")
header.Add(":authority", "example.com")
header.Add("cookie", "a")
header.Add("cookie", "b")
headerList := HeaderList{
{"method", "get"},
{"host", "example.com"},
{":authority", "example.com"},
{"cookie", "a"},
{"cookie", "b"},
}
actual := headerList.ToHeader()
assert.Equal(t, actual, header)
}
func TestEmit(t *testing.T) {
hl := NewHeaderList()
hf1 := NewHeaderField("key1", "value1")
hf2 := NewHeaderField("key2", "value2")
hl.Emit(hf1)
hl.Emit(hf2)
assert.Equal(t, hl.Len(), 2)
}
func TestEmitSort(t *testing.T) {
hl := &HeaderList{
NewHeaderField(":method", "GET"),
NewHeaderField(":scheme", "http"),
NewHeaderField(":path", "/"),
NewHeaderField(":authority", "www.example.com"),
NewHeaderField("cache-control", "no-cache"),
}
sort.Sort(hl)
expected := &HeaderList{
NewHeaderField(":authority", "www.example.com"),
NewHeaderField(":method", "GET"),
NewHeaderField(":path", "/"),
NewHeaderField(":scheme", "http"),
NewHeaderField("cache-control", "no-cache"),
}
assert.Equal(t, hl, expected)
}