Skip to content
This repository has been archived by the owner on Jul 11, 2023. It is now read-only.

Commit

Permalink
pkg/cert/providers: add ValidateCertManagerOptions test
Browse files Browse the repository at this point in the history
Unit test for `ValidateCertManagerOptions` and `ValidateVaultOptions`

Signed-off-by: Eduard Serra <[email protected]>
  • Loading branch information
eduser25 committed Jun 29, 2021
1 parent 16902d7 commit a0535f5
Showing 1 changed file with 136 additions and 0 deletions.
136 changes: 136 additions & 0 deletions pkg/certificate/providers/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,3 +210,139 @@ func TestGetCertificateFromKubernetes(t *testing.T) {
assert.Equal(testElement.expectNilVal, cert == nil)
}
}

func TestValidateCertManagerOptions(t *testing.T) {
assert := tassert.New(t)

testCases := []struct {
testName string
options CertManagerOptions
expectErr bool
}{
{
testName: "Empty issuer",
options: CertManagerOptions{
IssuerName: "",
IssuerKind: "test-kind",
IssuerGroup: "test-group",
},
expectErr: true,
},
{
testName: "Empty kind",
options: CertManagerOptions{
IssuerName: "test-name",
IssuerKind: "",
IssuerGroup: "test-group",
},
expectErr: true,
},
{
testName: "Empty group",
options: CertManagerOptions{
IssuerName: "test-name",
IssuerKind: "test-kind",
IssuerGroup: "",
},
expectErr: true,
},
{
testName: "Valid cert manager opts",
options: CertManagerOptions{
IssuerName: "test-name",
IssuerKind: "test-kind",
IssuerGroup: "test-group",
},
expectErr: false,
},
}

for _, t := range testCases {
err := ValidateCertManagerOptions(t.options)
if t.expectErr {
assert.Error(err, "test '%s' didn't error as expected", t.testName)
} else {
assert.NoError(err, "test '%s' didn't succeed as expected", t.testName)
}
}
}

func TestValidateVaultOptions(t *testing.T) {
assert := tassert.New(t)

testCases := []struct {
testName string
options VaultOptions
expectErr bool
}{
{
testName: "invalid proto",
options: VaultOptions{
VaultProtocol: "ftp",
VaultHost: "vault-host",
VaultToken: "vault-token",
VaultRole: "vault-role",
},
expectErr: true,
},
{
testName: "Empty host",
options: VaultOptions{
VaultProtocol: "http",
VaultHost: "",
VaultToken: "vault-token",
VaultRole: "vault-role",
},
expectErr: true,
},
{
testName: "Empty token",
options: VaultOptions{
VaultProtocol: "https",
VaultHost: "vault-host",
VaultToken: "",
VaultRole: "vault-role",
},
expectErr: true,
},
{
testName: "Empty role",
options: VaultOptions{
VaultProtocol: "http",
VaultHost: "vault-host",
VaultToken: "vault-token",
VaultRole: "",
},
expectErr: true,
},
{
testName: "Empty role",
options: VaultOptions{
VaultProtocol: "https",
VaultHost: "vault-host",
VaultToken: "vault-token",
VaultRole: "",
},
expectErr: true,
},
{
testName: "Valid config",
options: VaultOptions{
VaultProtocol: "https",
VaultHost: "vault-host",
VaultToken: "vault-token",
VaultRole: "role",
},
expectErr: false,
},
}

for _, t := range testCases {
err := ValidateVaultOptions(t.options)
if t.expectErr {
assert.Error(err, "test '%s' didn't error as expected", t.testName)
} else {
assert.NoError(err, "test '%s' didn't succeed as expected", t.testName)
}
}
}

0 comments on commit a0535f5

Please sign in to comment.