(t *testing.T)
| 191 | } |
| 192 | |
| 193 | func 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 | }, |
nothing calls this directly
no test coverage detected