MCPcopy Index your code
hub / github.com/google/go-github / TestCheckResponse

Function TestCheckResponse

github/github_test.go:3264–3292  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

3262}
3263
3264func TestCheckResponse(t *testing.T) {
3265 t.Parallel()
3266 res := &http.Response{
3267 Request: &http.Request{},
3268 StatusCode: http.StatusBadRequest,
3269 Body: io.NopCloser(strings.NewReader(`{"message":"m",
3270 "errors": [{"resource": "r", "field": "f", "code": "c"}],
3271 "block": {"reason": "dmca", "created_at": "2016-03-17T15:39:46Z"}}`)),
3272 }
3273 var err *ErrorResponse
3274 errors.As(CheckResponse(res), &err)
3275
3276 if err == nil {
3277 t.Error("Expected error response.")
3278 }
3279
3280 want := &ErrorResponse{
3281 Response: res,
3282 Message: "m",
3283 Errors: []Error{{Resource: "r", Field: "f", Code: "c"}},
3284 Block: &ErrorBlock{
3285 Reason: "dmca",
3286 CreatedAt: &Timestamp{time.Date(2016, time.March, 17, 15, 39, 46, 0, time.UTC)},
3287 },
3288 }
3289 if !errors.Is(err, want) {
3290 t.Errorf("Error = %#v, want %#v", err, want)
3291 }
3292}
3293
3294func TestCheckResponse_RateLimit(t *testing.T) {
3295 t.Parallel()

Callers

nothing calls this directly

Calls 3

CheckResponseFunction · 0.85
ErrorMethod · 0.45
IsMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…