use of io.stackgres.operator.common.StackGresClusterReview in project stackgres by ongres.
the class ClusterConstraintValidatorTest method sslPrivateKeySecretNull_shouldFail.
@Test
void sslPrivateKeySecretNull_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", "test"));
checkErrorCause(StackGresClusterSsl.class, "spec.postgres.ssl.privateKeySecretKeySelector", "isNotEnabledSecretKeySecretKeySelectorRequired", review, AssertTrue.class);
}
use of io.stackgres.operator.common.StackGresClusterReview in project stackgres by ongres.
the class ClusterConstraintValidatorTest method missingScript_shouldFail.
@Test
void missingScript_shouldFail() {
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());
checkErrorCause(StackGresClusterScriptEntry.class, new String[] { "spec.initData.scripts[0].script", "spec.initData.scripts[0].scriptFrom" }, "isScriptMutuallyExclusiveAndRequired", review, AssertTrue.class);
}
use of io.stackgres.operator.common.StackGresClusterReview in project stackgres by ongres.
the class ClusterConstraintValidatorTest method invalidNames_shouldFail.
@ParameterizedTest
@ValueSource(strings = { "stackgres.io/", "*9stackgres", "1143", "1143a", "-1143a", ".demo", "123-primary", "123-primary", "primary*", "stackgres-demo_1" })
void invalidNames_shouldFail(String name) {
StackGresClusterReview review = getValidReview();
review.getRequest().getObject().getMetadata().setName(name);
ValidationFailed message = assertThrows(ValidationFailed.class, () -> validator.validate(review));
assertEquals("Name must consist of lower case alphanumeric " + "characters or '-', start with an alphabetic character, " + "and end with an alphanumeric character", message.getMessage());
}
use of io.stackgres.operator.common.StackGresClusterReview in project stackgres by ongres.
the class ClusterConstraintValidatorTest method givenTolerationsSetAndEffectOtherThanNoExecute_shouldFail.
@Test
void givenTolerationsSetAndEffectOtherThanNoExecute_shouldFail() {
StackGresClusterReview review = getValidReview();
review.getRequest().getObject().getSpec().getPod().setScheduling(new StackGresClusterPodScheduling());
review.getRequest().getObject().getSpec().getPod().getScheduling().setTolerations(new ArrayList<>());
review.getRequest().getObject().getSpec().getPod().getScheduling().getTolerations().add(new Toleration());
review.getRequest().getObject().getSpec().getPod().getScheduling().getTolerations().get(0).setKey("test");
review.getRequest().getObject().getSpec().getPod().getScheduling().getTolerations().get(0).setTolerationSeconds(100L);
review.getRequest().getObject().getSpec().getPod().getScheduling().getTolerations().get(0).setEffect(new Random().nextBoolean() ? "NoSchedule" : "PreferNoSchedule");
checkErrorCause(Toleration.class, "spec.pod.scheduling.tolerations[0].effect", "isEffectNoExecuteIfTolerationIsSet", review, AssertTrue.class);
}
use of io.stackgres.operator.common.StackGresClusterReview in project stackgres by ongres.
the class SslValidatorTest method givenAnUpdate_shouldPass.
@Test
void givenAnUpdate_shouldPass() throws ValidationFailed {
final StackGresClusterReview review = getUpdateReview();
when(secretFinder.findByNameAndNamespace("secret1", "default")).thenReturn(Optional.of(secret1));
when(secretFinder.findByNameAndNamespace("secret2", "default")).thenReturn(Optional.of(secret2));
validator.validate(review);
verify(secretFinder, times(1)).findByNameAndNamespace("secret1", "default");
verify(secretFinder, times(1)).findByNameAndNamespace("secret2", "default");
}
Aggregations