(t *testing.T)
| 152 | } |
| 153 | |
| 154 | func Test_deleteRun(t *testing.T) { |
| 155 | keysResp := "[{\"id\":123,\"key_id\":\"ABC123\"}]" |
| 156 | tests := []struct { |
| 157 | name string |
| 158 | tty bool |
| 159 | opts DeleteOptions |
| 160 | httpStubs func(*httpmock.Registry) |
| 161 | prompterStubs func(*prompter.PrompterMock) |
| 162 | wantStdout string |
| 163 | wantErr bool |
| 164 | wantErrMsg string |
| 165 | }{ |
| 166 | { |
| 167 | name: "delete tty", |
| 168 | tty: true, |
| 169 | opts: DeleteOptions{KeyID: "ABC123", Confirmed: false}, |
| 170 | prompterStubs: func(pm *prompter.PrompterMock) { |
| 171 | pm.ConfirmDeletionFunc = func(_ string) error { |
| 172 | return nil |
| 173 | } |
| 174 | }, |
| 175 | httpStubs: func(reg *httpmock.Registry) { |
| 176 | reg.Register(httpmock.REST("GET", "user/gpg_keys"), httpmock.StatusStringResponse(200, keysResp)) |
| 177 | reg.Register(httpmock.REST("DELETE", "user/gpg_keys/123"), httpmock.StatusStringResponse(204, "")) |
| 178 | }, |
| 179 | wantStdout: "✓ GPG key ABC123 deleted from your account\n", |
| 180 | }, |
| 181 | { |
| 182 | name: "delete with confirm flag tty", |
| 183 | tty: true, |
| 184 | opts: DeleteOptions{KeyID: "ABC123", Confirmed: true}, |
| 185 | httpStubs: func(reg *httpmock.Registry) { |
| 186 | reg.Register(httpmock.REST("GET", "user/gpg_keys"), httpmock.StatusStringResponse(200, keysResp)) |
| 187 | reg.Register(httpmock.REST("DELETE", "user/gpg_keys/123"), httpmock.StatusStringResponse(204, "")) |
| 188 | }, |
| 189 | wantStdout: "✓ GPG key ABC123 deleted from your account\n", |
| 190 | }, |
| 191 | { |
| 192 | name: "not found tty", |
| 193 | tty: true, |
| 194 | opts: DeleteOptions{KeyID: "ABC123", Confirmed: true}, |
| 195 | httpStubs: func(reg *httpmock.Registry) { |
| 196 | reg.Register(httpmock.REST("GET", "user/gpg_keys"), httpmock.StatusStringResponse(200, "[]")) |
| 197 | }, |
| 198 | wantErr: true, |
| 199 | wantErrMsg: "unable to delete GPG key ABC123: either the GPG key is not found or it is not owned by you", |
| 200 | }, |
| 201 | { |
| 202 | name: "delete no tty", |
| 203 | opts: DeleteOptions{KeyID: "ABC123", Confirmed: true}, |
| 204 | httpStubs: func(reg *httpmock.Registry) { |
| 205 | reg.Register(httpmock.REST("GET", "user/gpg_keys"), httpmock.StatusStringResponse(200, keysResp)) |
| 206 | reg.Register(httpmock.REST("DELETE", "user/gpg_keys/123"), httpmock.StatusStringResponse(204, "")) |
| 207 | }, |
| 208 | wantStdout: "", |
| 209 | }, |
| 210 | { |
| 211 | name: "not found no tty", |
nothing calls this directly
no test coverage detected