1 package resourcename
2
3 import (
4 "testing"
5
6 "gotest.tools/v3/assert"
7 )
8
9 func TestJoin(t *testing.T) {
10 t.Parallel()
11 for _, tt := range []struct {
12 name string
13 input []string
14 expected string
15 }{
16 {
17 name: "zero",
18 input: []string{},
19 expected: "/",
20 },
21 {
22 name: "one",
23 input: []string{"parent/1"},
24 expected: "parent/1",
25 },
26 {
27 name: "two",
28 input: []string{
29 "parent/1",
30 "child/2",
31 },
32 expected: "parent/1/child/2",
33 },
34 {
35 name: "root first",
36 input: []string{
37 "/",
38 "child/2",
39 },
40 expected: "child/2",
41 },
42 {
43 name: "root last",
44 input: []string{
45 "parent/1",
46 "/",
47 },
48 expected: "parent/1",
49 },
50 {
51 name: "root second",
52 input: []string{
53 "parent/1",
54 "/",
55 "child/2",
56 },
57 expected: "parent/1/child/2",
58 },
59 {
60 name: "root first and last",
61 input: []string{
62 "/",
63 "child/1",
64 "/",
65 },
66 expected: "child/1",
67 },
68 {
69 name: "only roots",
70 input: []string{
71 "/",
72 "/",
73 },
74 expected: "/",
75 },
76 {
77 name: "empty first",
78 input: []string{
79 "",
80 "child/2",
81 },
82 expected: "child/2",
83 },
84 {
85 name: "empty second",
86 input: []string{
87 "parent/1",
88 "",
89 "child/2",
90 },
91 expected: "parent/1/child/2",
92 },
93 {
94 name: "invalid first suffix",
95 input: []string{
96 "parent/1/",
97 "child/2",
98 },
99 expected: "parent/1/child/2",
100 },
101 {
102 name: "invalid last suffix",
103 input: []string{
104 "parent/1",
105 "child/2/",
106 },
107 expected: "parent/1/child/2",
108 },
109
110 {
111 name: "fully qualified first",
112 input: []string{
113 "//foo.example.com/foo/1",
114 "bar/2",
115 },
116 expected: "//foo.example.com/foo/1/bar/2",
117 },
118 {
119 name: "fully qualified second",
120 input: []string{
121 "foo/1",
122 "//foo.example.com/bar/2",
123 },
124 expected: "foo/1/bar/2",
125 },
126 {
127 name: "fully qualified both",
128 input: []string{
129 "//foo.example.com/foo/1",
130 "//bar.example.com/bar/2",
131 },
132 expected: "//foo.example.com/foo/1/bar/2",
133 },
134
135
136
137 {
138 name: "first slash prefix",
139 input: []string{
140 "/parent/1",
141 "child/2",
142 },
143 expected: "parent/1/child/2",
144 },
145 {
146 name: "second slash prefix",
147 input: []string{
148 "parent/1",
149 "/child/2",
150 },
151 expected: "parent/1/child/2",
152 },
153 {
154 name: "thirds slash prefix",
155 input: []string{
156 "parent/1",
157 "child/2",
158 "/extra/3",
159 },
160 expected: "parent/1/child/2/extra/3",
161 },
162 {
163 name: "all slash prefix",
164 input: []string{
165 "/parent/1",
166 "/child/2",
167 "/extra/3",
168 },
169 expected: "parent/1/child/2/extra/3",
170 },
171 } {
172 tt := tt
173 t.Run(tt.name, func(t *testing.T) {
174 t.Parallel()
175 actual := Join(tt.input...)
176 assert.Equal(t, actual, tt.expected)
177 })
178 }
179 }
180
View as plain text