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