aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/github.com/aws/smithy-go/transport/http/url_test.go
blob: a77dabfe32ee6d107fc66850956e3004a32048a3 (plain) (blame)
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
package http

import (
	"fmt"
	"testing"
)

func TestJoinPath(t *testing.T) {
	cases := []struct {
		A, B   string
		Expect string
	}{
		0: {
			A: "", B: "/bar",
			Expect: "/bar",
		},
		1: {
			A: "/", B: "/bar",
			Expect: "/bar",
		},
		2: {
			A: "/foo/", B: "/bar",
			Expect: "/foo/bar",
		},
		3: {
			A: "foo/", B: "/bar",
			Expect: "/foo/bar",
		},
		4: {
			A: "/foo/", B: "bar",
			Expect: "/foo/bar",
		},
		5: {
			A: "foo", B: "/bar",
			Expect: "/foo/bar",
		},
		6: {
			A: "", B: "",
			Expect: "/",
		},
		7: {
			A: "foo", B: "",
			Expect: "/foo",
		},
		8: {
			A: "foo/", B: "",
			Expect: "/foo/",
		},
		9: {
			A: "foo//", B: "//bar",
			Expect: "/foo///bar",
		},
	}

	for i, c := range cases {
		t.Run(fmt.Sprintf("%d:%s,%s:%s", i, c.A, c.B, c.Expect), func(t *testing.T) {
			actual := JoinPath(c.A, c.B)
			if e, a := c.Expect, actual; e != a {
				t.Errorf("expect %v path, got %v", e, a)
			}
		})
	}
}

func TestJoinRawQuery(t *testing.T) {
	cases := []struct {
		A, B   string
		Expect string
	}{
		0: {
			A: "", B: "bar",
			Expect: "bar",
		},
		1: {
			A: "foo", B: "bar",
			Expect: "foo&bar",
		},
		2: {
			A: "foo&", B: "bar",
			Expect: "foo&bar",
		},
		3: {
			A: "foo", B: "",
			Expect: "foo",
		},
		4: {
			A: "", B: "&bar",
			Expect: "bar",
		},
		5: {
			A: "foo&", B: "&bar",
			Expect: "foo&bar",
		},
		6: {
			A: "", B: "",
			Expect: "",
		},
		7: {
			A: "foo&baz", B: "bar",
			Expect: "foo&baz&bar",
		},
		8: {
			A: "foo", B: "baz&bar",
			Expect: "foo&baz&bar",
		},
		9: {
			A: "&foo&", B: "&baz&bar&",
			Expect: "foo&baz&bar",
		},
		10: {
			A: "&foo&&&", B: "&&&baz&&&bar&",
			Expect: "foo&baz&&&bar",
		},
	}

	for i, c := range cases {
		t.Run(fmt.Sprintf("%d:%s,%s:%s", i, c.A, c.B, c.Expect), func(t *testing.T) {
			actual := JoinRawQuery(c.A, c.B)
			if e, a := c.Expect, actual; e != a {
				t.Errorf("expect %v query, got %v", e, a)
			}
		})
	}
}