MCPcopy Create free account
hub / github.com/cli/cli / TestClientErrors

Function TestClientErrors

pkg/cmd/event/client/client_test.go:193–354  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

191}
192
193func TestClientErrors(t *testing.T) {
194 create := func(c EventClient) error {
195 _, _, err := c.CreateSubscription(context.Background(), "https://github.com/OWNER/REPO/pull/1", []string{"test.a"})
196 return err
197 }
198 get := func(c EventClient) error {
199 _, err := c.GetSubscription(context.Background(), "sub_1")
200 return err
201 }
202 del := func(c EventClient) error {
203 return c.DeleteSubscription(context.Background(), "sub_1")
204 }
205 list := func(c EventClient) error {
206 _, err := c.ListSubscriptions(context.Background(), 30)
207 return err
208 }
209 stream := func(c EventClient) error {
210 _, err := c.OpenStream(context.Background(), "sub_1")
211 return err
212 }
213
214 tests := []struct {
215 name string
216 call func(EventClient) error
217 matcher httpmock.Matcher
218 responder httpmock.Responder
219 wantErr error
220 wantMessage string
221 wantHint string
222 }{
223 {
224 name: "create on a missing resource",
225 call: create,
226 matcher: httpmock.REST("POST", "event-subscriptions"),
227 responder: errorResponse(http.StatusNotFound, "Not Found"),
228 wantErr: ErrResourceNotFound,
229 wantMessage: "Not Found",
230 },
231 {
232 name: "create with an invalid field",
233 call: create,
234 matcher: httpmock.REST("POST", "event-subscriptions"),
235 responder: httpmock.StatusJSONResponse(http.StatusUnprocessableEntity, map[string]any{
236 "message": "Validation Failed",
237 "errors": []map[string]string{{"resource": "EventSubscription", "field": "resource_url", "code": "invalid"}},
238 }),
239 wantMessage: "Validation Failed\nEventSubscription.resource_url is invalid",
240 wantHint: "invalid subscription request",
241 },
242 {
243 name: "create rejected without invalid fields",
244 call: create,
245 matcher: httpmock.REST("POST", "event-subscriptions"),
246 responder: errorResponse(http.StatusUnprocessableEntity, "Subscription limit exceeded"),
247 wantErr: ErrSubscriptionLimit,
248 wantMessage: "Subscription limit exceeded",
249 wantHint: "request rejected, or the subscription limit may have been reached",
250 },

Callers

nothing calls this directly

Calls 12

RESTFunction · 0.92
StatusJSONResponseFunction · 0.92
errorResponseFunction · 0.85
EqualMethod · 0.80
newTestClientFunction · 0.70
CreateSubscriptionMethod · 0.65
GetSubscriptionMethod · 0.65
DeleteSubscriptionMethod · 0.65
ListSubscriptionsMethod · 0.65
OpenStreamMethod · 0.65
RunMethod · 0.65
RegisterMethod · 0.45

Tested by

no test coverage detected