-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathstrings_test.go
More file actions
227 lines (211 loc) · 5.29 KB
/
strings_test.go
File metadata and controls
227 lines (211 loc) · 5.29 KB
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
package github
import (
"testing"
"github.com/stretchr/testify/assert"
)
//goland:noinspection HttpUrlsUsage
func TestIsPlugin(t *testing.T) {
t.Parallel()
testCases := []struct {
scenario string
url string
expected bool
}{
{
scenario: "has http",
url: "http://github.com/owner/my-plugin",
expected: true,
},
{
scenario: "has https",
url: "https://github.com/owner/my-plugin",
expected: true,
},
{
scenario: "has no protocol",
url: "github.com/owner/my-plugin",
expected: true,
},
{
scenario: "not a github plugin",
url: "gitlab.com/owner/my-plugin",
},
}
for _, tc := range testCases {
tc := tc
t.Run(tc.scenario, func(t *testing.T) {
t.Parallel()
assert.Equal(t, tc.expected, isPlugin(tc.url))
})
}
}
//goland:noinspection HttpUrlsUsage
func TestParseURL(t *testing.T) {
t.Parallel()
testCases := []struct {
scenario string
url string
expectedOwner string
expectedRepository string
expectedVersion string
expectedError string
}{
// Failure cases.
{
scenario: "not github without scheme",
url: "gitlab.com/owner/my-plugin",
expectedError: "not a github url",
},
{
scenario: "not github with scheme",
url: "http://gitlab.com/owner/my-plugin",
expectedError: "not a github url",
},
{
scenario: "missing hostname",
url: "/owner/my-plugin",
expectedError: "not a github url",
},
{
scenario: "missing owner",
url: "github.com//my-plugin",
expectedError: "missing github owner",
},
{
scenario: "missing repository",
url: "github.com/owner",
expectedError: "missing github repository",
},
{
scenario: "missing repository with slash",
url: "github.com/owner/",
expectedError: "missing github repository",
},
{
scenario: "missing repository with double slash",
url: "github.com/owner//",
expectedError: "missing github repository",
},
// Success cases.
{
scenario: "without scheme and without version",
url: "github.com/owner/my-plugin",
expectedOwner: "owner",
expectedRepository: "my-plugin",
},
{
scenario: "without scheme and with version",
url: "github.com/owner/my-plugin@v1.1.0",
expectedOwner: "owner",
expectedRepository: "my-plugin",
expectedVersion: "v1.1.0",
},
{
scenario: "with http:// and without version",
url: "http://github.com/owner/my-plugin",
expectedOwner: "owner",
expectedRepository: "my-plugin",
},
{
scenario: "with https:// and without version",
url: "https://github.com/owner/my-plugin",
expectedOwner: "owner",
expectedRepository: "my-plugin",
},
{
scenario: "with scheme and version",
url: "https://github.com/owner/my-plugin@v1.1.0",
expectedOwner: "owner",
expectedRepository: "my-plugin",
expectedVersion: "v1.1.0",
},
{
scenario: "with www and without scheme and without version",
url: "www.github.com/owner/my-plugin",
expectedOwner: "owner",
expectedRepository: "my-plugin",
},
{
scenario: "with www and without scheme and with version",
url: "www.github.com/owner/my-plugin@v1.1.0",
expectedOwner: "owner",
expectedRepository: "my-plugin",
expectedVersion: "v1.1.0",
},
{
scenario: "with www and with http:// and without version",
url: "http://www.github.com/owner/my-plugin",
expectedOwner: "owner",
expectedRepository: "my-plugin",
},
{
scenario: "with www and with https:// and without version",
url: "https://www.github.com/owner/my-plugin",
expectedOwner: "owner",
expectedRepository: "my-plugin",
},
{
scenario: "with www and with scheme and version",
url: "https://www.github.com/owner/my-plugin@v1.1.0",
expectedOwner: "owner",
expectedRepository: "my-plugin",
expectedVersion: "v1.1.0",
},
}
for _, tc := range testCases {
tc := tc
t.Run(tc.scenario, func(t *testing.T) {
t.Parallel()
owner, repository, version, err := parseURL(tc.url)
assert.Equal(t, tc.expectedOwner, owner)
assert.Equal(t, tc.expectedRepository, repository)
assert.Equal(t, tc.expectedVersion, version)
if tc.expectedError == "" {
assert.NoError(t, err)
} else {
assert.EqualError(t, err, tc.expectedError)
}
})
}
}
func TestTrimVersion(t *testing.T) {
t.Parallel()
testCases := []struct {
scenario string
version string
expected string
}{
{
scenario: "master",
version: "master",
expected: "master",
},
{
scenario: "only v",
version: "v",
expected: "v",
},
{
scenario: "volley",
version: "volley",
expected: "volley",
},
{
scenario: "no v prefix",
version: "1.3.2",
expected: "1.3.2",
},
{
scenario: "with v prefix",
version: "v1.3.2",
expected: "1.3.2",
},
}
for _, tc := range testCases {
tc := tc
t.Run(tc.scenario, func(t *testing.T) {
t.Parallel()
assert.Equal(t, tc.expected, trimVersion(tc.version))
})
}
}