Skip to content

Commit

Permalink
add TestRepositoriesService_DownloadReleaseAsset_FollowRedirectToError
Browse files Browse the repository at this point in the history
  • Loading branch information
WillAbides committed Aug 27, 2023
1 parent 92434e9 commit 8b802ce
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions github/repos_releases_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,36 @@ func TestRepositoriesService_DownloadReleaseAsset_FollowRedirect(t *testing.T) {
}
}

func TestRepositoriesService_DownloadReleaseAsset_FollowRedirectToError(t *testing.T) {
client, mux, _, teardown := setup()
defer teardown()

mux.HandleFunc("/repos/o/r/releases/assets/1", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
testHeader(t, r, "Accept", defaultMediaType)
// /yo, below will be served as baseURLPath/yo
http.Redirect(w, r, baseURLPath+"/yo", http.StatusFound)
})
mux.HandleFunc("/yo", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
testHeader(t, r, "Accept", "*/*")
w.WriteHeader(http.StatusNotFound)
})

ctx := context.Background()
resp, loc, err := client.Repositories.DownloadReleaseAsset(ctx, "o", "r", 1, http.DefaultClient)
if err == nil {
t.Error("Repositories.DownloadReleaseAsset did not return an error")
}
if resp != nil {
resp.Close()
t.Error("Repositories.DownloadReleaseAsset returned stream, want nil")
}
if loc != "" {
t.Errorf(`Repositories.DownloadReleaseAsset returned "%s", want empty ""`, loc)
}
}

func TestRepositoriesService_DownloadReleaseAsset_APIError(t *testing.T) {
client, mux, _, teardown := setup()
defer teardown()
Expand Down

0 comments on commit 8b802ce

Please sign in to comment.