Merge pull request #10439 from cli/attestation-client-race-fix

Add mutex to fix race in attestation test client
This commit is contained in:
William Martin 2025-02-13 16:30:39 +01:00 committed by GitHub
commit fd6ae5559f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -5,6 +5,7 @@ import (
"fmt"
"io"
"net/http"
"sync"
"github.com/cli/cli/v2/pkg/cmd/attestation/test/data"
"github.com/golang/snappy"
@ -58,12 +59,16 @@ func (m *reqFailHttpClient) Get(url string) (*http.Response, error) {
type failAfterNCallsHttpClient struct {
mock.Mock
mu sync.Mutex
FailOnCallN int
FailOnAllSubsequentCalls bool
NumCalls int
}
func (m *failAfterNCallsHttpClient) Get(url string) (*http.Response, error) {
m.mu.Lock()
defer m.mu.Unlock()
m.On("OnGetFailAfterNCalls").Return()
m.NumCalls++