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

Function TestCheckResponse_unexpectedErrorStructure

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

Source from the content-addressed store, hash-verified

3855}
3856
3857func TestCheckResponse_unexpectedErrorStructure(t *testing.T) {
3858 t.Parallel()
3859 httpBody := `{"message":"m", "errors": ["error 1"]}`
3860 res := &http.Response{
3861 Request: &http.Request{},
3862 StatusCode: http.StatusBadRequest,
3863 Body: io.NopCloser(strings.NewReader(httpBody)),
3864 }
3865 var err *ErrorResponse
3866 errors.As(CheckResponse(res), &err)
3867
3868 if err == nil {
3869 t.Error("Expected error response.")
3870 }
3871
3872 want := &ErrorResponse{
3873 Response: res,
3874 Message: "m",
3875 Errors: []Error{{Message: "error 1"}},
3876 }
3877 if !errors.Is(err, want) {
3878 t.Errorf("Error = %#v, want %#v", err, want)
3879 }
3880 data, err2 := io.ReadAll(err.Response.Body)
3881 if err2 != nil {
3882 t.Fatalf("failed to read response body: %v", err)
3883 }
3884 if got := string(data); got != httpBody {
3885 t.Errorf("ErrorResponse.Response.Body = %q, want %q", got, httpBody)
3886 }
3887}
3888
3889// TestCheckResponse_LargeBodyTruncated verifies that CheckResponse reads at
3890// most maxErrorBodySize bytes from an error response body, so that a

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…