Passed
Pull Request — master (#54)
by Stefano
02:14
created

urlpath_test.TestJoin   A

Complexity

Conditions 3

Size

Total Lines 53
Code Lines 31

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 31
nop 1
dl 0
loc 53
rs 9.1359
c 0
b 0
f 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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