MCPcopy Create free account
hub / github.com/cli/cli / TestDeleteRepoDoesNotFollowRedirect

Function TestDeleteRepoDoesNotFollowRedirect

pkg/cmd/repo/delete/http_test.go:59–81  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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.
59func 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}

Callers

nothing calls this directly

Calls 9

VerifyMethod · 0.95
RegisterMethod · 0.95
RESTFunction · 0.92
StatusStringResponseFunction · 0.92
NewFunction · 0.92
deleteRepoFunction · 0.85
EqualMethod · 0.80
SetMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected