@@ -38,22 +38,11 @@ func Test_azdo_provider_getRepoDetails(t *testing.T) {
38
38
require .EqualValues (t , false , details .pushStatus )
39
39
})
40
40
41
- t .Run ("ssh not supported" , func (t * testing.T ) {
42
- // arrange
43
- provider := getAzdoScmProviderTestHarness (mockinput .NewMockConsole ())
44
- ctx := context .Background ()
45
-
46
- // act
47
- details , e := provider .gitRepoDetails (ctx , "git@ssh.dev.azure.com:v3/fake_org/repo1/repo1" )
48
-
49
- // assert
50
- require .Error (t , e , ErrSSHNotSupported )
51
- require .EqualValues (t , (* gitRepositoryDetails )(nil ), details )
52
- })
53
-
54
41
t .Run ("non azure devops https remote" , func (t * testing.T ) {
55
42
//arrange
56
- provider := & AzdoScmProvider {}
43
+ provider := & AzdoScmProvider {
44
+ env : environment .New ("test" ),
45
+ }
57
46
ctx := context .Background ()
58
47
59
48
//act
@@ -66,7 +55,9 @@ func Test_azdo_provider_getRepoDetails(t *testing.T) {
66
55
67
56
t .Run ("non azure devops git remote" , func (t * testing.T ) {
68
57
//arrange
69
- provider := & AzdoScmProvider {}
58
+ provider := & AzdoScmProvider {
59
+ env : environment .New ("test" ),
60
+ }
70
61
ctx := context .Background ()
71
62
72
63
//act
@@ -221,3 +212,116 @@ func getAzdoCiProviderTestHarness(console input.Console) *AzdoCiProvider {
221
212
console : console ,
222
213
}
223
214
}
215
+
216
+ func Test_parseAzDoRemote (t * testing.T ) {
217
+
218
+ // the url can be in the form of:
219
+ // - https://dev.azure.com/[org|user]/[project]/_git/[repo]
220
+ t .Run ("valid HTTPS remote" , func (t * testing.T ) {
221
+ remoteUrl := "https://dev.azure.com/org/project/_git/repo"
222
+ expected := & azdoRemote {
223
+ Project : "project" ,
224
+ RepositoryName : "repo" ,
225
+ }
226
+
227
+ result , err := parseAzDoRemote (remoteUrl )
228
+
229
+ require .NoError (t , err )
230
+ require .Equal (t , expected , result )
231
+ })
232
+
233
+ // the url can be in the form of:
234
+ // - https://[user]@dev.azure.com/[org|user]/[project]/_git/[repo]
235
+ t .Run ("valid user HTTPS remote" , func (t * testing.T ) {
236
+ remoteUrl := "https://user@visualstudio.com/org/project/_git/repo"
237
+ expected := & azdoRemote {
238
+ Project : "project" ,
239
+ RepositoryName : "repo" ,
240
+ }
241
+
242
+ result , err := parseAzDoRemote (remoteUrl )
243
+
244
+ require .NoError (t , err )
245
+ require .Equal (t , expected , result )
246
+ })
247
+
248
+ // the url can be in the form of:
249
+ // - https://[org].visualstudio.com/[project]/_git/[repo]
250
+ t .Run ("valid legacy HTTPS remote" , func (t * testing.T ) {
251
+ remoteUrl := "https://visualstudio.com/org/project/_git/repo"
252
+ expected := & azdoRemote {
253
+ Project : "project" ,
254
+ RepositoryName : "repo" ,
255
+ }
256
+
257
+ result , err := parseAzDoRemote (remoteUrl )
258
+
259
+ require .NoError (t , err )
260
+ require .Equal (t , expected , result )
261
+ })
262
+
263
+ t .Run ("valid legacy HTTPS remote with org" , func (t * testing.T ) {
264
+ remoteUrl := "https://org.visualstudio.com/org/project/_git/repo"
265
+ expected := & azdoRemote {
266
+ Project : "project" ,
267
+ RepositoryName : "repo" ,
268
+ }
269
+
270
+ result , err := parseAzDoRemote (remoteUrl )
271
+
272
+ require .NoError (t , err )
273
+ require .Equal (t , expected , result )
274
+ })
275
+
276
+ // the url can be in the form of:
277
+ // - git@ssh.dev.azure.com:v[1-3]/[user|org]/[project]/[repo]
278
+ // - git@vs-ssh.visualstudio.com:v[1-3]/[user|org]/[project]/[repo]
279
+ // - git@ssh.visualstudio.com:v[1-3]/[user|org]/[project]/[repo]
280
+ t .Run ("valid SSH remote" , func (t * testing.T ) {
281
+ remoteUrl := "git@ssh.dev.azure.com:v3/org/project/repo"
282
+ expected := & azdoRemote {
283
+ Project : "project" ,
284
+ RepositoryName : "repo" ,
285
+ }
286
+
287
+ result , err := parseAzDoRemote (remoteUrl )
288
+
289
+ require .NoError (t , err )
290
+ require .Equal (t , expected , result )
291
+ })
292
+
293
+ t .Run ("valid legacy SSH remote" , func (t * testing.T ) {
294
+ remoteUrl := "git@vs-ssh.visualstudio.com:v3/org/project/repo"
295
+ expected := & azdoRemote {
296
+ Project : "project" ,
297
+ RepositoryName : "repo" ,
298
+ }
299
+
300
+ result , err := parseAzDoRemote (remoteUrl )
301
+
302
+ require .NoError (t , err )
303
+ require .Equal (t , expected , result )
304
+ })
305
+
306
+ t .Run ("valid legacy SSH remote" , func (t * testing.T ) {
307
+ remoteUrl := "git@ssh.visualstudio.com:v3/org/project/repo"
308
+ expected := & azdoRemote {
309
+ Project : "project" ,
310
+ RepositoryName : "repo" ,
311
+ }
312
+
313
+ result , err := parseAzDoRemote (remoteUrl )
314
+
315
+ require .NoError (t , err )
316
+ require .Equal (t , expected , result )
317
+ })
318
+
319
+ t .Run ("invalid remote" , func (t * testing.T ) {
320
+ remoteUrl := "https://github.com/user/repo"
321
+
322
+ result , err := parseAzDoRemote (remoteUrl )
323
+
324
+ require .Error (t , err )
325
+ require .Nil (t , result )
326
+ })
327
+ }
0 commit comments