(t *testing.T)
| 90 | } |
| 91 | |
| 92 | func 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 | ) |
nothing calls this directly
no test coverage detected