// Copyright 2026 The Gitea Authors. All rights reserved. // SPDX-License-Identifier: MIT package services import ( "context" "net/http" "testing" "github.com/stretchr/testify/require" ) func TestRawBodyCancellationPreservesContextError(t *testing.T) { started := make(chan struct{}) client := newTestClient(t, http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { _, _ = w.Write([]byte(`{"incomplete":`)) w.(http.Flusher).Flush() close(started) <-r.Context().Done() })) ctx, cancel := context.WithCancel(context.Background()) defer cancel() go func() { <-started; cancel() }() var result any require.ErrorIs(t, getJSON(ctx, client, "resource", &result), context.Canceled) }