TestDeleteRepoDoesNotFollowRedirect pins that a renamed or transferred repo surfaces the 3xx to the caller rather than being followed. deleteRun relies on seeing that status to explain what happened, so following the redirect would report success while deleting nothing. The Location header matters:
(t *testing.T)
| 57 | // The Location header matters: without it Go cannot follow a redirect at all, so a stub that |
| 58 | // omits it passes whatever the redirect policy is. |
| 59 | func TestDeleteRepoDoesNotFollowRedirect(t *testing.T) { |
| 60 | reg := &httpmock.Registry{} |
| 61 | defer reg.Verify(t) |
| 62 | |
| 63 | reg.Register( |
| 64 | httpmock.REST("DELETE", "repos/OWNER/REPO"), |
| 65 | func(req *http.Request) (*http.Response, error) { |
| 66 | resp, err := httpmock.StatusStringResponse(301, "")(req) |
| 67 | if err != nil { |
| 68 | return nil, err |
| 69 | } |
| 70 | resp.Header.Set("Location", "https://api.github.com/repos/OWNER/RENAMED") |
| 71 | return resp, nil |
| 72 | }, |
| 73 | ) |
| 74 | |
| 75 | err := deleteRepo(&http.Client{Transport: reg}, ghrepo.New("OWNER", "REPO")) |
| 76 | require.Error(t, err) |
| 77 | |
| 78 | var httpErr api.HTTPError |
| 79 | require.ErrorAs(t, err, &httpErr) |
| 80 | assert.Equal(t, 301, httpErr.StatusCode) |
| 81 | } |
nothing calls this directly
no test coverage detected