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

Function Test_runAdd

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

Source from the content-addressed store, hash-verified

90}
91
92func Test_runAdd(t *testing.T) {
93 tests := []struct {
94 name string
95 stdin string
96 httpStubs func(*httpmock.Registry)
97 wantStdout string
98 wantStderr string
99 wantErrMsg string
100 opts AddOptions
101 }{
102 {
103 name: "valid key",
104 stdin: "-----BEGIN PGP PUBLIC KEY BLOCK-----",
105 httpStubs: func(reg *httpmock.Registry) {
106 reg.Register(
107 httpmock.REST("POST", "user/gpg_keys"),
108 httpmock.RESTPayload(200, `{}`, func(payload map[string]any) {
109 assert.Contains(t, payload, "armored_public_key")
110 assert.NotContains(t, payload, "title")
111 }))
112 },
113 wantStdout: "✓ GPG key added to your account\n",
114 wantStderr: "",
115 wantErrMsg: "",
116 opts: AddOptions{KeyFile: "-"},
117 },
118 {
119 name: "valid key with title",
120 stdin: "-----BEGIN PGP PUBLIC KEY BLOCK-----",
121 httpStubs: func(reg *httpmock.Registry) {
122 reg.Register(
123 httpmock.REST("POST", "user/gpg_keys"),
124 httpmock.RESTPayload(200, `{}`, func(payload map[string]any) {
125 assert.Contains(t, payload, "armored_public_key")
126 assert.Contains(t, payload, "name")
127 }))
128 },
129 wantStdout: "✓ GPG key added to your account\n",
130 wantStderr: "",
131 wantErrMsg: "",
132 opts: AddOptions{KeyFile: "-", Title: "some title"},
133 },
134 {
135 name: "binary format fails",
136 stdin: "gCAAAAA7H7MHTZWFLJKD3vP4F7v",
137 httpStubs: func(reg *httpmock.Registry) {
138 reg.Register(
139 httpmock.REST("POST", "user/gpg_keys"),
140 httpmock.StatusStringResponse(422, `{
141 "message": "Validation Failed",
142 "errors": [{
143 "resource": "GpgKey",
144 "code": "custom",
145 "message": "We got an error doing that."
146 }],
147 "documentation_url": "https://docs.github.com/v3/users/gpg_keys"
148 }`),
149 )

Callers

nothing calls this directly

Calls 15

RegisterMethod · 0.95
VerifyMethod · 0.95
RESTFunction · 0.92
RESTPayloadFunction · 0.92
StatusStringResponseFunction · 0.92
WithHeaderFunction · 0.92
TestFunction · 0.92
NewMockConfigFunction · 0.92
ContainsMethod · 0.80
SetStdinTTYMethod · 0.80
SetStdoutTTYMethod · 0.80
SetStderrTTYMethod · 0.80

Tested by

no test coverage detected