use of io.stackgres.operator.common.StackGresClusterReview in project stackgres by ongres.
the class ClusterConstraintValidatorTest method validNodeSelector_shouldPass.
@Test
void validNodeSelector_shouldPass() throws ValidationFailed {
StackGresClusterReview review = getValidReview();
review.getRequest().getObject().getSpec().getPod().setScheduling(new StackGresClusterPodScheduling());
review.getRequest().getObject().getSpec().getPod().getScheduling().setNodeSelector(new HashMap<>());
review.getRequest().getObject().getSpec().getPod().getScheduling().getNodeSelector().put("test", "true");
validator.validate(review);
}
use of io.stackgres.operator.common.StackGresClusterReview in project stackgres by ongres.
the class ClusterConstraintValidatorTest method sslCertificateSecretWithEmptyName_shouldFail.
@Test
void sslCertificateSecretWithEmptyName_shouldFail() {
StackGresClusterReview review = getValidReview();
review.getRequest().getObject().getSpec().getPostgres().setSsl(new StackGresClusterSsl());
review.getRequest().getObject().getSpec().getPostgres().getSsl().setEnabled(true);
review.getRequest().getObject().getSpec().getPostgres().getSsl().setCertificateSecretKeySelector(new SecretKeySelector("test", null));
review.getRequest().getObject().getSpec().getPostgres().getSsl().setPrivateKeySecretKeySelector(new SecretKeySelector("test", "test"));
checkErrorCause(SecretKeySelector.class, "spec.postgres.ssl.certificateSecretKeySelector.name", "isNameNotEmpty", review, AssertTrue.class);
}
use of io.stackgres.operator.common.StackGresClusterReview in project stackgres by ongres.
the class ClusterConstraintValidatorTest method validScript_shouldPass.
@Test
void validScript_shouldPass() throws ValidationFailed {
StackGresClusterReview review = getValidReview();
review.getRequest().getObject().getSpec().setInitData(new StackGresClusterInitData());
review.getRequest().getObject().getSpec().getInitData().setScripts(new ArrayList<>());
review.getRequest().getObject().getSpec().getInitData().getScripts().add(new StackGresClusterScriptEntry());
review.getRequest().getObject().getSpec().getInitData().getScripts().get(0).setScript("SELECT 1");
validator.validate(review);
}
use of io.stackgres.operator.common.StackGresClusterReview in project stackgres by ongres.
the class ClusterConstraintValidatorTest method sslCertificateSecretNull_shouldFail.
@Test
void sslCertificateSecretNull_shouldFail() {
StackGresClusterReview review = getValidReview();
review.getRequest().getObject().getSpec().getPostgres().setSsl(new StackGresClusterSsl());
review.getRequest().getObject().getSpec().getPostgres().getSsl().setEnabled(true);
review.getRequest().getObject().getSpec().getPostgres().getSsl().setPrivateKeySecretKeySelector(new SecretKeySelector("test", "test"));
checkErrorCause(StackGresClusterSsl.class, "spec.postgres.ssl.certificateSecretKeySelector", "isNotEnabledCertificateSecretKeySelectorRequired", review, AssertTrue.class);
}
use of io.stackgres.operator.common.StackGresClusterReview in project stackgres by ongres.
the class ScriptsConfigValidatorTest method givenACreationUsingScriptFromSecret_shouldValidateSecretKeyReference.
@Test
void givenACreationUsingScriptFromSecret_shouldValidateSecretKeyReference() throws ValidationFailed {
final StackGresClusterReview review = getCreationReview();
String randomSecretKey = StringUtil.generateRandom();
String randomSecretName = StringUtil.generateRandom();
final StackGresCluster cluster = review.getRequest().getObject();
prepareForSecret(review, randomSecretName, randomSecretKey);
final String namespace = cluster.getMetadata().getNamespace();
when(secretFinder.findByNameAndNamespace(randomSecretName, namespace)).thenReturn(Optional.of(new SecretBuilder().withNewMetadata().withName(randomSecretName).withNamespace(namespace).endMetadata().withData(ImmutableMap.of(randomSecretKey, "CREATE DATABASE test;")).build()));
validator.validate(review);
final List<StackGresClusterScriptEntry> scripts = cluster.getSpec().getInitData().getScripts();
verify(secretFinder, times(scripts.size())).findByNameAndNamespace(randomSecretName, namespace);
}
Aggregations