use of io.stackgres.operator.common.StackGresClusterReview in project stackgres by ongres.
the class ScriptsConfigValidatorTest method givenACreationUsingScriptsFromBinaryConfigMap_shouldValidateConfigMapReference.
@Test
void givenACreationUsingScriptsFromBinaryConfigMap_shouldValidateConfigMapReference() throws ValidationFailed {
final StackGresClusterReview review = getCreationReview();
String randomConfigMapName = StringUtil.generateRandom();
String randomConfigMapKey = StringUtil.generateRandom();
prepareForConfigMap(review, randomConfigMapName, randomConfigMapKey);
final StackGresCluster cluster = review.getRequest().getObject();
final String namespace = cluster.getMetadata().getNamespace();
when(configMapFinder.findByNameAndNamespace(randomConfigMapName, namespace)).thenReturn(Optional.of(new ConfigMapBuilder().withNewMetadata().withName(randomConfigMapName).withNamespace(namespace).endMetadata().withBinaryData(ImmutableMap.of(randomConfigMapKey, "CREATE DATABASE test;")).build()));
validator.validate(review);
final List<StackGresClusterScriptEntry> scripts = cluster.getSpec().getInitData().getScripts();
verify(configMapFinder, times(scripts.size())).findByNameAndNamespace(randomConfigMapName, namespace);
}
use of io.stackgres.operator.common.StackGresClusterReview in project stackgres by ongres.
the class SslValidatorTest method givenACreationUsingPrivateKeyFromNonexistentSecretKey_shouldFail.
@Test
void givenACreationUsingPrivateKeyFromNonexistentSecretKey_shouldFail() {
final StackGresClusterReview review = getCreationReview();
when(secretFinder.findByNameAndNamespace("secret1", "default")).thenReturn(Optional.of(secret1));
when(secretFinder.findByNameAndNamespace("secret1", "default")).thenReturn(Optional.of(secret2));
prepareForSsl(review);
review.getRequest().getObject().getSpec().getPostgres().getSsl().getPrivateKeySecretKeySelector().setKey("test1");
ValidationUtils.assertValidationFailed(() -> validator.validate(review), ErrorType.INVALID_CR_REFERENCE, "Private key Secret secret2 or key test1 not found");
verify(secretFinder, times(1)).findByNameAndNamespace("secret1", "default");
verify(secretFinder, times(1)).findByNameAndNamespace("secret2", "default");
}
use of io.stackgres.operator.common.StackGresClusterReview in project stackgres by ongres.
the class SslValidatorTest method givenACreationUsingPrivateKeyFromNonexistentSecret_shouldFail.
@Test
void givenACreationUsingPrivateKeyFromNonexistentSecret_shouldFail() {
final StackGresClusterReview review = getCreationReview();
when(secretFinder.findByNameAndNamespace("secret1", "default")).thenReturn(Optional.of(secret1));
prepareForSsl(review);
ValidationUtils.assertValidationFailed(() -> validator.validate(review), ErrorType.INVALID_CR_REFERENCE, "Private key Secret secret2 or key test not found");
verify(secretFinder, times(1)).findByNameAndNamespace("secret1", "default");
verify(secretFinder, times(1)).findByNameAndNamespace("secret2", "default");
}
use of io.stackgres.operator.common.StackGresClusterReview in project stackgres by ongres.
the class SslValidatorTest method givenAValidCreation_shouldPass.
@Test
void givenAValidCreation_shouldPass() throws ValidationFailed {
final StackGresClusterReview review = getCreationReview();
when(secretFinder.findByNameAndNamespace("secret1", "default")).thenReturn(Optional.of(secret1));
when(secretFinder.findByNameAndNamespace("secret2", "default")).thenReturn(Optional.of(secret2));
prepareForSsl(review);
validator.validate(review);
verify(secretFinder, times(1)).findByNameAndNamespace("secret1", "default");
verify(secretFinder, times(1)).findByNameAndNamespace("secret2", "default");
}
use of io.stackgres.operator.common.StackGresClusterReview in project stackgres by ongres.
the class SslValidatorTest method givenACreationUsingCertificateFromNonexistentSecret_shouldFail.
@Test
void givenACreationUsingCertificateFromNonexistentSecret_shouldFail() {
final StackGresClusterReview review = getCreationReview();
prepareForSsl(review);
ValidationUtils.assertValidationFailed(() -> validator.validate(review), ErrorType.INVALID_CR_REFERENCE, "Certificate Secret secret1 or key test not found");
verify(secretFinder, times(1)).findByNameAndNamespace("secret1", "default");
verify(secretFinder, times(0)).findByNameAndNamespace("secret2", "default");
}
Aggregations