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