forked from mirrors/forgejo
**Backport:** https://codeberg.org/forgejo/forgejo/pulls/11007 Found while working on https://codeberg.org/forgejo/forgejo/pulls/10798#issuecomment-10083846: The symptom was that the go-github client never returned a `resp.After`, so I tracked down the root cause, which was that, with the mocked http server ... Mocked headers never reached the calling client, because w.WriteHeader() was called before the headers were set in the response. Fix by moving w.WriteHeader() to the right place just before w.Write(), which writes the body. Test added which fails without the fix and succeeds with it. Co-authored-by: Nils Goroll <nils.goroll@uplex.de> Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/11058 Co-authored-by: forgejo-backport-action <forgejo-backport-action@noreply.codeberg.org> Co-committed-by: forgejo-backport-action <forgejo-backport-action@noreply.codeberg.org>
24 lines
672 B
Go
24 lines
672 B
Go
// Copyright 2026 The Forgejo Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package unittest
|
|
|
|
import (
|
|
"net/http"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
// NOTE: This is a test of the unittest helper itself
|
|
func TestMockWebServer(t *testing.T) {
|
|
server := NewMockWebServer(t, "https://example.com", "testdata", false)
|
|
defer server.Close()
|
|
request, err := http.NewRequest("GET", server.URL+"/", nil)
|
|
require.NoError(t, err)
|
|
response, err := server.Client().Do(request)
|
|
require.NoError(t, err)
|
|
assert.Len(t, response.Header["Header"], 1)
|
|
assert.Equal(t, "value", response.Header["Header"][0])
|
|
}
|