Skip to content

Commit

Permalink
test: add missing checks for vault binary in unit tests (#23986)
Browse files Browse the repository at this point in the history
  • Loading branch information
mismithhisler authored Sep 18, 2024
1 parent 52f0b40 commit 25b2bd8
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
6 changes: 3 additions & 3 deletions nomad/vault_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1169,6 +1169,9 @@ func TestVaultClient_CreateToken_Root_Target_Role(t *testing.T) {
func TestVaultClient_CreateToken_Denylist_Role(t *testing.T) {
ci.Parallel(t)

v := testutil.NewTestVault(t)
defer v.Stop()

// Need to skip if test is 0.6.4
version, err := testutil.VaultVersion()
if err != nil {
Expand All @@ -1179,9 +1182,6 @@ func TestVaultClient_CreateToken_Denylist_Role(t *testing.T) {
t.Skipf("Vault has a regression in v0.6.4 that this test hits")
}

v := testutil.NewTestVault(t)
defer v.Stop()

// Set the configs token in a new test role
v.Config.Token = defaultTestVaultDenylistRoleAndToken(v, t, 5)
v.Config.Role = "test"
Expand Down
22 changes: 17 additions & 5 deletions testutil/vault.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func NewTestVaultFromPath(t testing.T, binary string) *TestVault {
t.Helper()

if _, err := exec.LookPath(binary); err != nil {
t.Skipf("Skipping test %s, Vault binary %q not found in path.", t.Name(), binary)
t.Skipf("Skipping test, Vault binary %q not found in path.", binary)
}

// Define which log level to use. Default to the same as Nomad but allow a
Expand Down Expand Up @@ -140,10 +140,13 @@ func NewTestVault(t testing.T) *TestVault {
return NewTestVaultFromPath(t, "vault")
}

// NewTestVaultDelayed returns a test Vault server that has not been started.
// Start must be called and it is the callers responsibility to deal with any
// port conflicts that may occur and retry accordingly.
func NewTestVaultDelayed(t testing.T) *TestVault {
func NewTestVaultDelayedFromPath(t testing.T, binary string) *TestVault {
t.Helper()

if _, err := exec.LookPath(binary); err != nil {
t.Skipf("Skipping test, Vault binary not %q found in path.", binary)
}

port := ci.PortAllocator.Grab(1)[0]
token := uuid.Generate()
bind := fmt.Sprintf("-dev-listen-address=127.0.0.1:%d", port)
Expand Down Expand Up @@ -184,6 +187,15 @@ func NewTestVaultDelayed(t testing.T) *TestVault {
return tv
}

// NewTestVaultDelayed returns a test Vault server that has not been started.
// Start must be called and it is the callers responsibility to deal with any
// port conflicts that may occur and retry accordingly.
func NewTestVaultDelayed(t testing.T) *TestVault {
t.Helper()

return NewTestVaultDelayedFromPath(t, "vault")
}

// Start starts the test Vault server and waits for it to respond to its HTTP
// API
func (tv *TestVault) Start() error {
Expand Down

0 comments on commit 25b2bd8

Please sign in to comment.