-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils_test.go
65 lines (49 loc) · 1.55 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
package quick
import (
"github.com/stretchr/testify/assert"
"net/http"
"net/url"
"testing"
)
func TestMergeHeaders(t *testing.T) {
h1 := make(http.Header)
h1.Set("Context-Type", "text/html")
h2 := make(http.Header)
h2.Set("Context-Type", "text/xml")
h2.Set("Server", "nginx")
h3 := MergeHeaders(h1, h2)
asserts := assert.New(t)
asserts.Equal(h3.Get("Context-type"), "text/xml")
asserts.Equal(h3.Get("Server"), "nginx")
}
func TestCopyHeader(t *testing.T) {
h1 := make(http.Header)
h1.Set("Context-Type", "text/html")
h2 := CopyHeader(h1)
asserts := assert.New(t)
asserts.Equal(h1.Get("Context-Type"), h2.Get("Context-Type"))
}
func TestMergeQueryString(t *testing.T) {
asserts := assert.New(t)
u, _ := url.Parse("http://example.com")
u2, _ := MergeQueryString(u, "c=3&d=4")
asserts.Equal(u2.Query().Encode(), "c=3&d=4")
u, _ = url.Parse("http://example.com?a=1&b=2")
u2, _ = MergeQueryString(u, "c=3&d=4")
asserts.Equal(u2.Query().Encode(), "a=1&b=2&c=3&d=4")
u, _ = url.Parse("http://example.com?a=1")
u2, _ = MergeQueryString(u, "a=2")
asserts.Equal(u2.Query().Encode(), "a=2")
u, _ = url.Parse("http://example.com?a=1")
u2, _ = MergeQueryString(u, "a=2&a=3")
asserts.Equal(u2.Query().Encode(), "a=3")
}
func TestReplaceQueryString(t *testing.T) {
asserts := assert.New(t)
u, _ := url.Parse("http://example.com")
u2, _ := ReplaceQueryString(u, "c=3&d=4")
asserts.Equal(u2.Query().Encode(), "c=3&d=4")
u, _ = url.Parse("http://example.com?a=1")
u2, _ = ReplaceQueryString(u, "c=3&d=4")
asserts.Equal(u2.Query().Encode(), "c=3&d=4")
}