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

Function TestDo_AcceptedError_LargeBodyTruncated

github/github_test.go:2281–2305  ·  view source on GitHub ↗

TestDo_AcceptedError_LargeBodyTruncated verifies that when the API returns a 202 Accepted with a body larger than maxErrorBodySize, the client reads at most maxErrorBodySize bytes into AcceptedError.Raw and does not allocate unbounded memory.

(t *testing.T)

Source from the content-addressed store, hash-verified

2279// most maxErrorBodySize bytes into AcceptedError.Raw and does not allocate
2280// unbounded memory.
2281func TestDo_AcceptedError_LargeBodyTruncated(t *testing.T) {
2282 t.Parallel()
2283 client, mux, _ := setup(t)
2284
2285 // Serve a 202 response whose body exceeds the cap by one byte.
2286 mux.HandleFunc("/", func(w http.ResponseWriter, _ *http.Request) {
2287 w.WriteHeader(http.StatusAccepted)
2288 fmt.Fprint(w, strings.Repeat("x", maxErrorBodySize+1))
2289 })
2290
2291 req, _ := client.NewRequest(t.Context(), "GET", ".", nil)
2292 _, err := client.Do(req, nil)
2293 if err == nil {
2294 t.Fatal("Expected AcceptedError, got nil")
2295 }
2296
2297 var aerr *AcceptedError
2298 if !errors.As(err, &aerr) {
2299 t.Fatalf("Expected *AcceptedError, got %T: %v", err, err)
2300 }
2301
2302 if got, want := len(aerr.Raw), maxErrorBodySize; got != want {
2303 t.Errorf("AcceptedError.Raw length = %v, want %v (maxErrorBodySize)", got, want)
2304 }
2305}
2306
2307// Test that an error caused by the internal http client's Do() function
2308// does not leak the client secret.

Callers

nothing calls this directly

Calls 3

NewRequestMethod · 0.80
setupFunction · 0.70
DoMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…