Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions core/internal/cltest/mocks.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"net/http"
"net/http/httptest"
"sync"
"sync/atomic"
"testing"
"time"

Expand Down Expand Up @@ -168,15 +169,15 @@ func NewHTTPMockServer(
response string,
callback ...func(http.Header, string),
) *httptest.Server {
called := false
var called atomic.Bool
handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
b, err := io.ReadAll(r.Body)
assert.NoError(t, err)
assert.Equal(t, wantMethod, r.Method)
if len(callback) > 0 {
callback[0](r.Header, string(b))
}
called = true
called.Store(true)

w.WriteHeader(status)
_, _ = io.WriteString(w, response) // Assignment for errcheck. Only used in tests so we can ignore.
Expand All @@ -185,7 +186,7 @@ func NewHTTPMockServer(
server := httptest.NewServer(handler)
t.Cleanup(func() {
server.Close()
assert.True(t, called, "expected call Mock HTTP endpoint '%s'", server.URL)
assert.True(t, called.Load(), "expected call Mock HTTP endpoint '%s'", server.URL)
})
return server
}
Expand Down
Loading