Skip to content

Commit

Permalink
Add basic initialization test
Browse files Browse the repository at this point in the history
Signed-off-by: dttung2905 <[email protected]>
  • Loading branch information
dttung2905 committed Nov 18, 2024
1 parent fd3d905 commit 0003f49
Showing 1 changed file with 26 additions and 2 deletions.
28 changes: 26 additions & 2 deletions pkg/scaling/resolver/hashicorpvault_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ func TestHashicorpVaultHandler_getSecretValue_specify_secret_type(t *testing.T)
Path: "kv_v2/data/keda",
Key: "test",
}}
assert.Equalf(t, kedav1alpha1.VaultSecretTypeGeneric, secrets[0].Type, "Expected secret to not have a vlue")
assert.Equalf(t, kedav1alpha1.VaultSecretTypeGeneric, secrets[0].Type, "Expected secret to not have a value")
secrets, _ = vaultHandler.ResolveSecrets(secrets)
assert.Len(t, secrets, 1, "Supposed to get back one secret")
secret := secrets[0]
Expand All @@ -202,7 +202,7 @@ func TestHashicorpVaultHandler_getSecretValue_specify_secret_type(t *testing.T)
Path: "kv/keda",
Key: "test",
}}
assert.Equalf(t, kedav1alpha1.VaultSecretTypeGeneric, secrets[0].Type, "Expected secret to not have a vlue")
assert.Equalf(t, kedav1alpha1.VaultSecretTypeGeneric, secrets[0].Type, "Expected secret to not have a value")
secrets, _ = vaultHandler.ResolveSecrets(secrets)
assert.Len(t, secrets, 1, "Supposed to get back one secret")
secret = secrets[0]
Expand Down Expand Up @@ -628,3 +628,27 @@ func TestHashicorpVaultHandler_Token_VaultTokenAuth(t *testing.T) {
}()
}
}

func TestHashicorpVaultHandler_Initialize_with_SecretRef(t *testing.T) {
server := mockVault(t, false)
defer server.Close()

vault := kedav1alpha1.HashiCorpVault{
Address: server.URL,
Authentication: kedav1alpha1.VaultAuthenticationToken,
Credential: &kedav1alpha1.Credential{
TokenSecret: &kedav1alpha1.HashicorpVaultTokenSecret{
ValueFrom: kedav1alpha1.ValueFromSecret{
SecretKeyRef: kedav1alpha1.SecretKeyRef{
Name: "my-secret",
Key: "my-key",
},
},
},
},
}
vaultHandler := NewHashicorpVaultHandler(&vault)
err := vaultHandler.Initialize(context.TODO(), nil, logf.Log.WithName("test"), "", nil)
defer vaultHandler.Stop()
assert.Nil(t, err)
}

0 comments on commit 0003f49

Please sign in to comment.