@@ -200,26 +200,81 @@ func TestHTTPManagedTransport_E2E(t *testing.T) {
200
200
repo .Free ()
201
201
}
202
202
203
- func TestHTTPManagedTransport_HandleRedirect (t * testing.T ) {
204
- g := NewWithT (t )
203
+ func TestTrimActionSuffix (t * testing.T ) {
204
+ tests := []struct {
205
+ name string
206
+ inURL string
207
+ wantURL string
208
+ }{
209
+ {
210
+ name : "ignore other suffixes" ,
211
+ inURL : "https://gitlab/repo/podinfo.git/somethingelse" ,
212
+ wantURL : "https://gitlab/repo/podinfo.git/somethingelse" ,
213
+ },
214
+ {
215
+ name : "trim /info/refs?service=git-upload-pack" ,
216
+ inURL : "https://gitlab/repo/podinfo.git/info/refs?service=git-upload-pack" ,
217
+ wantURL : "https://gitlab/repo/podinfo.git" ,
218
+ },
219
+ {
220
+ name : "trim /git-upload-pack" ,
221
+ inURL : "https://gitlab/repo/podinfo.git/git-upload-pack" ,
222
+ wantURL : "https://gitlab/repo/podinfo.git" ,
223
+ },
224
+ {
225
+ name : "trim /info/refs?service=git-receive-pack" ,
226
+ inURL : "https://gitlab/repo/podinfo.git/info/refs?service=git-receive-pack" ,
227
+ wantURL : "https://gitlab/repo/podinfo.git" ,
228
+ },
229
+ {
230
+ name : "trim /git-receive-pack" ,
231
+ inURL : "https://gitlab/repo/podinfo.git/git-receive-pack" ,
232
+ wantURL : "https://gitlab/repo/podinfo.git" ,
233
+ },
234
+ }
205
235
206
- tmpDir := t .TempDir ()
236
+ for _ , tt := range tests {
237
+ t .Run (tt .name , func (t * testing.T ) {
238
+ g := NewWithT (t )
239
+
240
+ gotURL := trimActionSuffix (tt .inURL )
241
+ g .Expect (gotURL ).To (Equal (tt .wantURL ))
242
+ })
243
+ }
244
+ }
245
+
246
+ func TestHTTPManagedTransport_HandleRedirect (t * testing.T ) {
247
+ tests := []struct {
248
+ name string
249
+ repoURL string
250
+ }{
251
+ {name : "http to https" , repoURL : "http://github.com/stefanprodan/podinfo" },
252
+ {name : "handle gitlab redirect" , repoURL : "https://gitlab.com/stefanprodan/podinfo" },
253
+ }
207
254
208
255
// Force managed transport to be enabled
209
256
InitManagedTransport (logr .Discard ())
210
257
211
- id := "http://obj-id"
212
- AddTransportOptions (id , TransportOptions {
213
- TargetURL : "http://github.com/stefanprodan/podinfo" ,
214
- })
258
+ for _ , tt := range tests {
259
+ t .Run (tt .name , func (t * testing.T ) {
260
+ g := NewWithT (t )
215
261
216
- // GitHub will cause a 301 and redirect to https
217
- repo , err := git2go .Clone (id , tmpDir , & git2go.CloneOptions {
218
- CheckoutOptions : git2go.CheckoutOptions {
219
- Strategy : git2go .CheckoutForce ,
220
- },
221
- })
262
+ tmpDir := t .TempDir ()
222
263
223
- g .Expect (err ).ToNot (HaveOccurred ())
224
- repo .Free ()
264
+ id := "http://obj-id"
265
+ AddTransportOptions (id , TransportOptions {
266
+ TargetURL : tt .repoURL ,
267
+ })
268
+
269
+ // GitHub will cause a 301 and redirect to https
270
+ repo , err := git2go .Clone (id , tmpDir , & git2go.CloneOptions {
271
+ CheckoutOptions : git2go.CheckoutOptions {
272
+ Strategy : git2go .CheckoutForce ,
273
+ },
274
+ })
275
+
276
+ g .Expect (err ).ToNot (HaveOccurred ())
277
+ repo .Free ()
278
+ })
279
+ }
225
280
}
0 commit comments