summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulien Dessaux2024-12-01 12:51:18 +0100
committerJulien Dessaux2024-12-17 23:19:46 +0100
commit6cf2ca82de3a2bbef1277158ed933d35e6193845 (patch)
tree2a07ffcf7cc2ea8ecf226118266be269a805d51f
parentchore(tfstated): improve error messages and refactored PRAGMA code in the dat... (diff)
downloadtfstated-6cf2ca82de3a2bbef1277158ed933d35e6193845.tar.gz
tfstated-6cf2ca82de3a2bbef1277158ed933d35e6193845.tar.bz2
tfstated-6cf2ca82de3a2bbef1277158ed933d35e6193845.zip
chore(tfstated): fix testing race condition
-rw-r--r--cmd/tfstated/main_test.go6
1 files changed, 6 insertions, 0 deletions
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)