1
|
|
|
package urlpath_test |
2
|
|
|
|
3
|
|
|
import ( |
4
|
|
|
"fmt" |
5
|
|
|
"github.com/stefanoj3/dirstalk/pkg/common/urlpath" |
6
|
|
|
"github.com/stretchr/testify/assert" |
7
|
|
|
"strings" |
8
|
|
|
"testing" |
9
|
|
|
) |
10
|
|
|
|
11
|
|
|
func TestJoin(t *testing.T) { |
12
|
|
|
testCases := []struct{ |
13
|
|
|
input []string |
14
|
|
|
expectedOutput string |
15
|
|
|
}{ |
16
|
|
|
{ |
17
|
|
|
input: []string{"/home"}, |
18
|
|
|
expectedOutput: "/home", |
19
|
|
|
}, |
20
|
|
|
{ |
21
|
|
|
input: []string{"/home/"}, |
22
|
|
|
expectedOutput: "/home/", |
23
|
|
|
}, |
24
|
|
|
{ |
25
|
|
|
input: []string{"/home/", "test"}, |
26
|
|
|
expectedOutput: "/home/test", |
27
|
|
|
}, |
28
|
|
|
{ |
29
|
|
|
input: []string{"/home/", "/test"}, |
30
|
|
|
expectedOutput: "/home/test", |
31
|
|
|
}, |
32
|
|
|
{ |
33
|
|
|
input: []string{"/home/", "/test/"}, |
34
|
|
|
expectedOutput: "/home/test/", |
35
|
|
|
}, |
36
|
|
|
{ |
37
|
|
|
input: []string{"/home", "/test/"}, |
38
|
|
|
expectedOutput: "/home/test/", |
39
|
|
|
}, |
40
|
|
|
{ |
41
|
|
|
input: []string{"/home", "test/"}, |
42
|
|
|
expectedOutput: "/home/test/", |
43
|
|
|
}, |
44
|
|
|
{ |
45
|
|
|
input: []string{"/home", "test"}, |
46
|
|
|
expectedOutput: "/home/test", |
47
|
|
|
}, |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
for _, tc := range testCases { |
51
|
|
|
tc := tc |
52
|
|
|
scenario := fmt.Sprintf( |
53
|
|
|
"Input: `%s`, Expected output: `%s`", |
54
|
|
|
strings.Join(tc.input, ","), |
55
|
|
|
tc.expectedOutput, |
56
|
|
|
) |
57
|
|
|
|
58
|
|
|
t.Run(scenario, func(t *testing.T) { |
59
|
|
|
t.Parallel() |
60
|
|
|
|
61
|
|
|
output := urlpath.Join(tc.input...) |
62
|
|
|
|
63
|
|
|
assert.Equal(t, tc.expectedOutput, output) |
64
|
|
|
}) |
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
|