1
0
Fork 0
mirror of https://github.com/external-secrets/external-secrets.git synced 2024-12-15 17:51:01 +00:00

Tests: Finished refactoring tests to table tests

Signed-off-by: Dominic Meddick <dom.meddick@engineerbetter.com>
This commit is contained in:
William Young 2022-05-05 14:31:18 +01:00 committed by Dominic Meddick
parent ad76205264
commit b0719d2f54
No known key found for this signature in database
GPG key ID: 1F85C721D58846C5

View file

@ -234,6 +234,7 @@ type ValidateStoreTestCase struct {
}
func TestValidateStore(t *testing.T) {
namespace := "my-namespace"
testCases := []ValidateStoreTestCase{
{
store: makeSecretStore("", "some-region"),
@ -243,6 +244,38 @@ func TestValidateStore(t *testing.T) {
store: makeSecretStore("some-OCID", ""),
err: fmt.Errorf("region cannot be empty"),
},
{
store: makeSecretStore("some-OCID", "some-region", withSecretAuth("", "a-tenant")),
err: fmt.Errorf("user cannot be empty"),
},
{
store: makeSecretStore("some-OCID", "some-region", withSecretAuth("user-OCID", "")),
err: fmt.Errorf("tenant cannot be empty"),
},
{
store: makeSecretStore("vault-OCID", "some-region", withSecretAuth("user-OCID", "a-tenant"), withPrivateKey("", "key", nil)),
err: fmt.Errorf("privateKey.name cannot be empty"),
},
{
store: makeSecretStore("vault-OCID", "some-region", withSecretAuth("user-OCID", "a-tenant"), withPrivateKey("bob", "key", &namespace)),
err: fmt.Errorf("namespace not allowed with namespaced SecretStore"),
},
{
store: makeSecretStore("vault-OCID", "some-region", withSecretAuth("user-OCID", "a-tenant"), withPrivateKey("bob", "", nil)),
err: fmt.Errorf("privateKey.key cannot be empty"),
},
{
store: makeSecretStore("vault-OCID", "some-region", withSecretAuth("user-OCID", "a-tenant"), withPrivateKey("bob", "key", nil), withFingerprint("", "key", nil)),
err: fmt.Errorf("fingerprint.name cannot be empty"),
},
{
store: makeSecretStore("vault-OCID", "some-region", withSecretAuth("user-OCID", "a-tenant"), withPrivateKey("bob", "key", nil), withFingerprint("kelly", "key", &namespace)),
err: fmt.Errorf("namespace not allowed with namespaced SecretStore"),
},
{
store: makeSecretStore("vault-OCID", "some-region", withSecretAuth("user-OCID", "a-tenant"), withPrivateKey("bob", "key", nil), withFingerprint("kelly", "", nil)),
err: fmt.Errorf("fingerprint.key cannot be empty"),
},
}
p := VaultManagementService{}
for _, tc := range testCases {
@ -261,65 +294,3 @@ func TestValidateStoreSuccess(t *testing.T) {
t.Errorf("want nil got err")
}
}
func TestSecretAuthNoUser(t *testing.T) {
p := VaultManagementService{}
store := makeSecretStore("some-OCID", "some-region", withSecretAuth("", "a-tenant"))
err := p.ValidateStore(store)
if err == nil {
t.Errorf("want err got nil")
}
}
func TestSecretAuthNoTenancy(t *testing.T) {
p := VaultManagementService{}
store := makeSecretStore("some-OCID", "some-region", withSecretAuth("user-OCID", ""))
err := p.ValidateStore(store)
if err == nil {
t.Errorf("want err got nil")
}
}
func TestSecretAuthNoPrivateKey(t *testing.T) {
p := VaultManagementService{}
store := makeSecretStore("vault-OCID", "some-region", withSecretAuth("user-OCID", "a-tenant"), withPrivateKey("", "key", nil))
err := p.ValidateStore(store)
if err == nil {
t.Errorf("want err got nil")
}
namespace := "my-namespace"
store = makeSecretStore("vault-OCID", "some-region", withSecretAuth("user-OCID", "a-tenant"), withPrivateKey("bob", "key", &namespace))
err = p.ValidateStore(store)
if err == nil {
t.Errorf("want err got nil")
}
store = makeSecretStore("vault-OCID", "some-region", withSecretAuth("user-OCID", "a-tenant"), withPrivateKey("bob", "", nil))
err = p.ValidateStore(store)
if err == nil {
t.Errorf("want err got nil")
}
}
func TestSecretAuthNoFingerprint(t *testing.T) {
p := VaultManagementService{}
store := makeSecretStore("vault-OCID", "some-region", withSecretAuth("user-OCID", "a-tenant"), withPrivateKey("bob", "key", nil), withFingerprint("", "key", nil))
err := p.ValidateStore(store)
if err == nil {
t.Errorf("want err got nil")
}
namespace := "my-namespace"
store = makeSecretStore("vault-OCID", "some-region", withSecretAuth("user-OCID", "a-tenant"), withPrivateKey("bob", "key", nil), withFingerprint("kelly", "key", &namespace))
err = p.ValidateStore(store)
if err == nil {
t.Errorf("want err got nil")
}
store = makeSecretStore("vault-OCID", "some-region", withSecretAuth("user-OCID", "a-tenant"), withPrivateKey("bob", "key", nil), withFingerprint("kelly", "", nil))
err = p.ValidateStore(store)
if err == nil {
t.Errorf("want err got nil")
}
}