From a98768b3b6017d97e725f907e7f2b2a75a509a6f Mon Sep 17 00:00:00 2001 From: Alex Castle Date: Tue, 15 Feb 2022 08:38:31 -0800 Subject: [PATCH] Fix flakey test run on OSX On OSX newer versions of docker treat the host 'localhost' differently than '127.0.0.1'. Using resource.GetHostPort for url building will return an OS appropriate hostname --- hcvault/keysource_test.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/hcvault/keysource_test.go b/hcvault/keysource_test.go index 9290acc1a..48a31dc83 100644 --- a/hcvault/keysource_test.go +++ b/hcvault/keysource_test.go @@ -25,7 +25,8 @@ func TestMain(m *testing.M) { logger.Fatalf("Could not start resource: %s", err) } - os.Setenv("VAULT_ADDR", fmt.Sprintf("http://127.0.0.1:%v", resource.GetPort("8200/tcp"))) + vaultAddr := fmt.Sprintf("http://%s", resource.GetHostPort("8200/tcp")) + os.Setenv("VAULT_ADDR", vaultAddr) os.Setenv("VAULT_TOKEN", "secret") // exponential backoff-retry, because the application in the container might not be ready to accept connections yet if err := pool.Retry(func() error { @@ -45,7 +46,7 @@ func TestMain(m *testing.M) { logger.Fatalf("Could not connect to docker: %s", err) } - key := NewMasterKey(fmt.Sprintf("http://127.0.0.1:%v", resource.GetPort("8200/tcp")), "sops", "main") + key := NewMasterKey(vaultAddr, "sops", "main") err = key.createVaultTransitAndKey() if err != nil { logger.Fatal(err)