Skip to content

Commit

Permalink
Fix flakey test run on OSX
Browse files Browse the repository at this point in the history
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
  • Loading branch information
acastle committed Feb 15, 2022
1 parent 6130ffe commit a98768b
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions hcvault/keysource_test.go
Expand Up @@ -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 {
Expand All @@ -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)
Expand Down

0 comments on commit a98768b

Please sign in to comment.