(t *testing.T)
| 109 | } |
| 110 | |
| 111 | func Test_deleteRun(t *testing.T) { |
| 112 | keyResp := "{\"title\":\"My Key\"}" |
| 113 | tests := []struct { |
| 114 | name string |
| 115 | tty bool |
| 116 | opts DeleteOptions |
| 117 | httpStubs func(*httpmock.Registry) |
| 118 | prompterStubs func(*prompter.PrompterMock) |
| 119 | wantStdout string |
| 120 | wantErr bool |
| 121 | wantErrMsg string |
| 122 | }{ |
| 123 | { |
| 124 | name: "delete tty", |
| 125 | tty: true, |
| 126 | opts: DeleteOptions{KeyID: "123"}, |
| 127 | prompterStubs: func(pm *prompter.PrompterMock) { |
| 128 | pm.ConfirmDeletionFunc = func(_ string) error { |
| 129 | return nil |
| 130 | } |
| 131 | }, |
| 132 | httpStubs: func(reg *httpmock.Registry) { |
| 133 | reg.Register(httpmock.REST("GET", "user/keys/123"), httpmock.StatusStringResponse(200, keyResp)) |
| 134 | reg.Register(httpmock.REST("DELETE", "user/keys/123"), httpmock.StatusStringResponse(204, "")) |
| 135 | }, |
| 136 | wantStdout: "✓ SSH key \"My Key\" (123) deleted from your account\n", |
| 137 | }, |
| 138 | { |
| 139 | name: "delete with confirm flag tty", |
| 140 | tty: true, |
| 141 | opts: DeleteOptions{KeyID: "123", Confirmed: true}, |
| 142 | httpStubs: func(reg *httpmock.Registry) { |
| 143 | reg.Register(httpmock.REST("GET", "user/keys/123"), httpmock.StatusStringResponse(200, keyResp)) |
| 144 | reg.Register(httpmock.REST("DELETE", "user/keys/123"), httpmock.StatusStringResponse(204, "")) |
| 145 | }, |
| 146 | wantStdout: "✓ SSH key \"My Key\" (123) deleted from your account\n", |
| 147 | }, |
| 148 | { |
| 149 | name: "not found tty", |
| 150 | tty: true, |
| 151 | opts: DeleteOptions{KeyID: "123"}, |
| 152 | httpStubs: func(reg *httpmock.Registry) { |
| 153 | reg.Register(httpmock.REST("GET", "user/keys/123"), httpmock.StatusStringResponse(404, "")) |
| 154 | }, |
| 155 | wantErr: true, |
| 156 | wantErrMsg: "HTTP 404 (https://api.github.com/user/keys/123)", |
| 157 | }, |
| 158 | { |
| 159 | name: "delete no tty", |
| 160 | opts: DeleteOptions{KeyID: "123", Confirmed: true}, |
| 161 | httpStubs: func(reg *httpmock.Registry) { |
| 162 | reg.Register(httpmock.REST("GET", "user/keys/123"), httpmock.StatusStringResponse(200, keyResp)) |
| 163 | reg.Register(httpmock.REST("DELETE", "user/keys/123"), httpmock.StatusStringResponse(204, "")) |
| 164 | }, |
| 165 | wantStdout: "", |
| 166 | }, |
| 167 | { |
| 168 | name: "not found no tty", |
nothing calls this directly
no test coverage detected