Add mutex to fix race in attestation test client

Signed-off-by: Cody Soyland <codysoyland@github.com>
This commit is contained in:
Cody Soyland 2025-02-13 10:18:30 -05:00
parent 556e72fc6a
commit ad2cfe074f
No known key found for this signature in database

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++