-
Notifications
You must be signed in to change notification settings - Fork 0
/
util_test.go
72 lines (60 loc) · 1.86 KB
/
util_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
package congruent
import (
"net/http"
"testing"
)
func TestBasicAuth(t *testing.T) {
expected := "Basic dXNlcm5hbWU6cGFzc3dvcmQ="
enc := BasicAuth("username", "password")
if enc != expected {
t.Errorf("expected %v, got %v", expected, enc)
}
}
func TestMergeHTTPHeader(t *testing.T) {
expected := http.Header{
"Authorization": []string{"stillnotvalidlol"},
"Content-Type": []string{"application/json"},
"X-Custom-Thing": []string{"v custom"}}
dest := http.Header{
"Authorization": []string{"notvalidlol"},
"Content-Type": []string{"application/json"}}
src := http.Header{
"Authorization": []string{"stillnotvalidlol"},
"X-Custom-Thing": []string{"v custom"}}
mergeHTTPHeader(&dest, &src)
for k, va := range expected {
h := dest.Get(k)
if h != va[0] {
t.Errorf("for header %v: got %v, expected %v", k, h, va[0])
}
}
if ld, lv := len(dest), len(expected); ld != lv {
t.Errorf("expected len did not match dest, %v != %v", ld, lv)
}
}
func TestMergeHTTPHeaders(t *testing.T) {
expected := http.Header{
"Authorization": []string{"stillnotrightlol"},
"Content-Type": []string{"application/json"},
"X-Custom-Thing": []string{"v custom"},
"X-Custom-Thing-Two": []string{"so custom"}}
dest := http.Header{
"Authorization": []string{"notvalidlol"},
"Content-Type": []string{"application/json"}}
src1 := http.Header{
"Authorization": []string{"stillnotvalidlol"},
"X-Custom-Thing": []string{"v custom"}}
src2 := http.Header{
"Authorization": []string{"stillnotrightlol"},
"X-Custom-Thing-Two": []string{"so custom"}}
mergeHTTPHeaders(&dest, &src1, &src2)
for k, va := range expected {
h := dest.Get(k)
if h != va[0] {
t.Errorf("for header %v: got %v, expected %v", k, h, va[0])
}
}
if ld, lv := len(dest), len(expected); ld != lv {
t.Errorf("expected len did not match dest, %v != %v", ld, lv)
}
}