(t *testing.T)
| 13 | ) |
| 14 | |
| 15 | func 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 | ) |
nothing calls this directly
no test coverage detected