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

Function Test_gpgKeyUploadHTTPError

pkg/cmd/gpg-key/add/add_test.go:72–90  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

70}
71
72func Test_gpgKeyUploadHTTPError(t *testing.T) {
73 reg := &httpmock.Registry{}
74 defer reg.Verify(t)
75 reg.Register(
76 httpmock.REST("POST", "user/gpg_keys"),
77 httpmock.WithHeader(
78 httpmock.StatusStringResponse(http.StatusInternalServerError, `{"message":"Internal Server Error"}`),
79 "Content-Type", "application/json",
80 ),
81 )
82
83 err := gpgKeyUpload(&http.Client{Transport: reg}, "github.com", strings.NewReader("-----BEGIN PGP PUBLIC KEY BLOCK-----"), "")
84
85 var httpErr api.HTTPError
86 require.ErrorAs(t, err, &httpErr)
87 assert.Equal(t, http.StatusInternalServerError, httpErr.StatusCode)
88 assert.Contains(t, err.Error(), "HTTP 500")
89 assert.EqualError(t, err, "HTTP 500: Internal Server Error (https://api.github.com/user/gpg_keys)")
90}
91
92func Test_runAdd(t *testing.T) {
93 tests := []struct {

Callers

nothing calls this directly

Calls 9

VerifyMethod · 0.95
RegisterMethod · 0.95
RESTFunction · 0.92
WithHeaderFunction · 0.92
StatusStringResponseFunction · 0.92
gpgKeyUploadFunction · 0.85
EqualMethod · 0.80
ContainsMethod · 0.80
ErrorMethod · 0.45

Tested by

no test coverage detected