-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathutils_test.go
86 lines (79 loc) · 2.41 KB
/
utils_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
81
82
83
84
85
86
package httprelay
import (
"log"
"net/http"
"testing"
assert "github.com/cobratbq/goutils/std/testing"
)
func TestProcessConnectionHdr(t *testing.T) {
headers := map[string]struct{}{}
processConnectionHdr(headers, "Keep-Alive, Foo ,Bar")
assert.Equal(t, len(headers), 3)
assert.ElementPresent(t, headers, "Keep-Alive")
assert.ElementPresent(t, headers, "Foo")
assert.ElementPresent(t, headers, "Bar")
}
func TestFullHost(t *testing.T) {
var tests = map[string]string{
"localhost": "localhost:80",
"localhost:1234": "localhost:1234",
"bla": "bla:80",
"www.google.com": "www.google.com:80",
"www.google.com:80": "www.google.com:80",
"www.google.com:443": "www.google.com:443",
"google.com:8080": "google.com:8080",
}
var result string
for src, dst := range tests {
result = fullHost(src)
assert.Equal(t, result, dst)
}
}
func TestProcessConnectionHdrs(t *testing.T) {
var hdrs = map[string]struct{}{}
var val = "Keep-Alive , \tFoo,bar"
processConnectionHdr(hdrs, val)
assert.Equal(t, len(hdrs), 3)
assert.ElementPresent(t, hdrs, "Keep-Alive")
assert.ElementPresent(t, hdrs, "Foo")
assert.ElementPresent(t, hdrs, "bar")
}
func TestProcessConnectionHdrsBad(t *testing.T) {
var hdrs = map[string]struct{}{}
var val = "Illegal spaces, Capiche?, close"
processConnectionHdr(hdrs, val)
assert.Equal(t, len(hdrs), 1)
log.Printf("Headers: %#v\n", hdrs)
assert.ElementAbsent(t, hdrs, "Illegal spaces")
assert.ElementAbsent(t, hdrs, "Capiche?")
assert.ElementPresent(t, hdrs, "close")
}
func TestCopyHeaders(t *testing.T) {
var src = http.Header{}
src.Add("Transfer-Encoding", "gzip")
src.Add("Content-Type", "image/jpeg")
src.Add("Trailer", "something")
src.Add("Content-Encoding", "gzip")
src.Add("Via", "bla:1234")
src.Add("Connection", "Keep-Alive, Foo")
src.Add("Keep-Alive", "close")
src.Add("Foo", "Bar")
var dst = http.Header{}
copyHeaders(dst, src)
var k string
if len(dst) != 3 {
t.Errorf("Expected exactly 2 headers, but found a different number: %#v\n", dst)
}
for k = range hopByHopHeaders {
// check simple dropped headers
assert.KeyAbsent(t, dst, k)
}
for _, k = range []string{"Connection", "Keep-Alive", "Foo"} {
// check special treatment of Connection header and its values
assert.KeyAbsent(t, dst, k)
}
for _, k = range []string{"Content-Type", "Content-Encoding", "Via"} {
// check remaining headers
assert.KeyPresent(t, dst, k)
}
}