MCPcopy
hub / github.com/cli/cli / Test_runAdd

Function Test_runAdd

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

Source from the content-addressed store, hash-verified

13)
14
15func Test_runAdd(t *testing.T) {
16 tests := []struct {
17 name string
18 stdin string
19 httpStubs func(*httpmock.Registry)
20 wantStdout string
21 wantStderr string
22 wantErrMsg string
23 opts AddOptions
24 }{
25 {
26 name: "valid key",
27 stdin: "-----BEGIN PGP PUBLIC KEY BLOCK-----",
28 httpStubs: func(reg *httpmock.Registry) {
29 reg.Register(
30 httpmock.REST("POST", "user/gpg_keys"),
31 httpmock.RESTPayload(200, ``, func(payload map[string]interface{}) {
32 assert.Contains(t, payload, "armored_public_key")
33 assert.NotContains(t, payload, "title")
34 }))
35 },
36 wantStdout: "✓ GPG key added to your account\n",
37 wantStderr: "",
38 wantErrMsg: "",
39 opts: AddOptions{KeyFile: "-"},
40 },
41 {
42 name: "valid key with title",
43 stdin: "-----BEGIN PGP PUBLIC KEY BLOCK-----",
44 httpStubs: func(reg *httpmock.Registry) {
45 reg.Register(
46 httpmock.REST("POST", "user/gpg_keys"),
47 httpmock.RESTPayload(200, ``, func(payload map[string]interface{}) {
48 assert.Contains(t, payload, "armored_public_key")
49 assert.Contains(t, payload, "name")
50 }))
51 },
52 wantStdout: "✓ GPG key added to your account\n",
53 wantStderr: "",
54 wantErrMsg: "",
55 opts: AddOptions{KeyFile: "-", Title: "some title"},
56 },
57 {
58 name: "binary format fails",
59 stdin: "gCAAAAA7H7MHTZWFLJKD3vP4F7v",
60 httpStubs: func(reg *httpmock.Registry) {
61 reg.Register(
62 httpmock.REST("POST", "user/gpg_keys"),
63 httpmock.StatusStringResponse(422, `{
64 "message": "Validation Failed",
65 "errors": [{
66 "resource": "GpgKey",
67 "code": "custom",
68 "message": "We got an error doing that."
69 }],
70 "documentation_url": "https://docs.github.com/v3/users/gpg_keys"
71 }`),
72 )

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
NewBlankConfigFunction · 0.92
ContainsMethod · 0.80
SetStdinTTYMethod · 0.80
SetStdoutTTYMethod · 0.80
SetStderrTTYMethod · 0.80

Tested by

no test coverage detected