@@ -489,7 +489,7 @@ func TestRepositoriesService_DownloadReleaseAsset_FollowRedirect(t *testing.T) {
489489})
490490mux .HandleFunc ("/yo" , func (w http.ResponseWriter , r * http.Request ) {
491491testMethod (t , r , "GET" )
492- testHeader (t , r , "Accept" , "*/*" )
492+ testHeader (t , r , "Accept" , defaultMediaType )
493493w .Header ().Set ("Content-Type" , "application/octet-stream" )
494494w .Header ().Set ("Content-Disposition" , "attachment; filename=hello-world.txt" )
495495fmt .Fprint (w , "Hello World" )
@@ -511,6 +511,48 @@ func TestRepositoriesService_DownloadReleaseAsset_FollowRedirect(t *testing.T) {
511511}
512512}
513513
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+
514556func TestRepositoriesService_DownloadReleaseAsset_FollowRedirectToError (t * testing.T ) {
515557t .Parallel ()
516558client , mux , _ := setup (t )
@@ -523,7 +565,7 @@ func TestRepositoriesService_DownloadReleaseAsset_FollowRedirectToError(t *testi
523565})
524566mux .HandleFunc ("/yo" , func (w http.ResponseWriter , r * http.Request ) {
525567testMethod (t , r , "GET" )
526- testHeader (t , r , "Accept" , "*/*" )
568+ testHeader (t , r , "Accept" , defaultMediaType )
527569w .WriteHeader (http .StatusNotFound )
528570})
529571
0 commit comments