@@ -489,7 +489,7 @@ func TestRepositoriesService_DownloadReleaseAsset_FollowRedirect(t *testing.T) {
489
489
})
490
490
mux .HandleFunc ("/yo" , func (w http.ResponseWriter , r * http.Request ) {
491
491
testMethod (t , r , "GET" )
492
- testHeader (t , r , "Accept" , "*/*" )
492
+ testHeader (t , r , "Accept" , defaultMediaType )
493
493
w .Header ().Set ("Content-Type" , "application/octet-stream" )
494
494
w .Header ().Set ("Content-Disposition" , "attachment; filename=hello-world.txt" )
495
495
fmt .Fprint (w , "Hello World" )
@@ -511,6 +511,48 @@ func TestRepositoriesService_DownloadReleaseAsset_FollowRedirect(t *testing.T) {
511
511
}
512
512
}
513
513
514
+ func TestRepositoriesService_DownloadReleaseAsset_FollowMultipleRedirects (t * testing.T ) {
515
+ t .Parallel ()
516
+ client , mux , _ := setup (t )
517
+
518
+ mux .HandleFunc ("/repos/o/r/releases/assets/1" , func (w http.ResponseWriter , r * http.Request ) {
519
+ w .Header ().Set ("Content-Type" , "application/json; charset=utf-8" )
520
+ testMethod (t , r , "GET" )
521
+ testHeader (t , r , "Accept" , defaultMediaType )
522
+ // /yo, below will be served as baseURLPath/yo
523
+ http .Redirect (w , r , baseURLPath + "/yo" , http .StatusMovedPermanently )
524
+ })
525
+ mux .HandleFunc ("/yo" , func (w http.ResponseWriter , r * http.Request ) {
526
+ w .Header ().Set ("Content-Type" , "text/html;charset=utf-8" )
527
+ testMethod (t , r , "GET" )
528
+ testHeader (t , r , "Accept" , defaultMediaType )
529
+ // /yo2, below will be served as baseURLPath/yo2
530
+ http .Redirect (w , r , baseURLPath + "/yo2" , http .StatusFound )
531
+ })
532
+ mux .HandleFunc ("/yo2" , func (w http.ResponseWriter , r * http.Request ) {
533
+ w .Header ().Set ("Content-Type" , "application/octet-stream" )
534
+ w .Header ().Set ("Content-Disposition" , "attachment; filename=hello-world.txt" )
535
+ testMethod (t , r , "GET" )
536
+ testHeader (t , r , "Accept" , defaultMediaType )
537
+ fmt .Fprint (w , "Hello World" )
538
+ })
539
+
540
+ ctx := context .Background ()
541
+ reader , _ , err := client .Repositories .DownloadReleaseAsset (ctx , "o" , "r" , 1 , http .DefaultClient )
542
+ if err != nil {
543
+ t .Errorf ("Repositories.DownloadReleaseAsset returned error: %v" , err )
544
+ }
545
+ content , err := io .ReadAll (reader )
546
+ if err != nil {
547
+ t .Errorf ("Reading Repositories.DownloadReleaseAsset returned error: %v" , err )
548
+ }
549
+ reader .Close ()
550
+ want := []byte ("Hello World" )
551
+ if ! bytes .Equal (want , content ) {
552
+ t .Errorf ("Repositories.DownloadReleaseAsset returned %+v, want %+v" , content , want )
553
+ }
554
+ }
555
+
514
556
func TestRepositoriesService_DownloadReleaseAsset_FollowRedirectToError (t * testing.T ) {
515
557
t .Parallel ()
516
558
client , mux , _ := setup (t )
@@ -523,7 +565,7 @@ func TestRepositoriesService_DownloadReleaseAsset_FollowRedirectToError(t *testi
523
565
})
524
566
mux .HandleFunc ("/yo" , func (w http.ResponseWriter , r * http.Request ) {
525
567
testMethod (t , r , "GET" )
526
- testHeader (t , r , "Accept" , "*/*" )
568
+ testHeader (t , r , "Accept" , defaultMediaType )
527
569
w .WriteHeader (http .StatusNotFound )
528
570
})
529
571
0 commit comments