(t *testing.T)
| 12 | ) |
| 13 | |
| 14 | func Test_runAdd(t *testing.T) { |
| 15 | tests := []struct { |
| 16 | name string |
| 17 | stdin string |
| 18 | opts AddOptions |
| 19 | httpStubs func(*httpmock.Registry) |
| 20 | wantStdout string |
| 21 | wantStderr string |
| 22 | wantErrMsg string |
| 23 | }{ |
| 24 | { |
| 25 | name: "valid key format, not already in use", |
| 26 | stdin: "ssh-ed25519 asdf", |
| 27 | httpStubs: func(reg *httpmock.Registry) { |
| 28 | reg.Register( |
| 29 | httpmock.REST("GET", "user/keys"), |
| 30 | httpmock.StringResponse("[]")) |
| 31 | reg.Register( |
| 32 | httpmock.REST("POST", "user/keys"), |
| 33 | httpmock.RESTPayload(200, ``, func(payload map[string]interface{}) { |
| 34 | assert.Contains(t, payload, "key") |
| 35 | assert.Empty(t, payload["title"]) |
| 36 | })) |
| 37 | }, |
| 38 | wantStdout: "", |
| 39 | wantStderr: "✓ Public key added to your account\n", |
| 40 | wantErrMsg: "", |
| 41 | opts: AddOptions{KeyFile: "-"}, |
| 42 | }, |
| 43 | { |
| 44 | name: "valid signing key format, not already in use", |
| 45 | stdin: "ssh-ed25519 asdf", |
| 46 | httpStubs: func(reg *httpmock.Registry) { |
| 47 | reg.Register( |
| 48 | httpmock.REST("GET", "user/ssh_signing_keys"), |
| 49 | httpmock.StringResponse("[]")) |
| 50 | reg.Register( |
| 51 | httpmock.REST("POST", "user/ssh_signing_keys"), |
| 52 | httpmock.RESTPayload(200, ``, func(payload map[string]interface{}) { |
| 53 | assert.Contains(t, payload, "key") |
| 54 | assert.Empty(t, payload["title"]) |
| 55 | })) |
| 56 | }, |
| 57 | wantStdout: "", |
| 58 | wantStderr: "✓ Public key added to your account\n", |
| 59 | wantErrMsg: "", |
| 60 | opts: AddOptions{KeyFile: "-", Type: "signing"}, |
| 61 | }, |
| 62 | { |
| 63 | name: "valid key format, already in use", |
| 64 | stdin: "ssh-ed25519 asdf title", |
| 65 | httpStubs: func(reg *httpmock.Registry) { |
| 66 | reg.Register( |
| 67 | httpmock.REST("GET", "user/keys"), |
| 68 | httpmock.StringResponse(`[ |
| 69 | { |
| 70 | "id": 1, |
| 71 | "key": "ssh-ed25519 asdf", |
nothing calls this directly
no test coverage detected