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