From 6cf2ca82de3a2bbef1277158ed933d35e6193845 Mon Sep 17 00:00:00 2001 From: Julien Dessaux Date: Sun, 1 Dec 2024 12:51:18 +0100 Subject: chore(tfstated): fix testing race condition --- cmd/tfstated/main_test.go | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'cmd') diff --git a/cmd/tfstated/main_test.go b/cmd/tfstated/main_test.go index 82b7736..bd21918 100644 --- a/cmd/tfstated/main_test.go +++ b/cmd/tfstated/main_test.go @@ -7,6 +7,7 @@ import ( "net/http" "net/url" "os" + "sync" "testing" "time" @@ -20,6 +21,7 @@ var baseURI = url.URL{ } var db *database.DB var adminPassword string +var adminPasswordMutex sync.Mutex func TestMain(m *testing.M) { ctx := context.Background() @@ -47,6 +49,8 @@ func TestMain(m *testing.M) { } database.AdvertiseAdminPassword = func(password string) { + adminPasswordMutex.Lock() + defer adminPasswordMutex.Unlock() adminPassword = password } go run( @@ -84,6 +88,8 @@ func runHTTPRequest(method string, auth bool, uriRef *url.URL, body io.Reader, t return } if auth { + adminPasswordMutex.Lock() + defer adminPasswordMutex.Unlock() req.SetBasicAuth("admin", adminPassword) } resp, err := client.Do(req) -- cgit v1.2.3