Search in sources :

Example 46 with StackGresClusterReview

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);
}
Also used : StackGresClusterReview(io.stackgres.operator.common.StackGresClusterReview) StackGresClusterSsl(io.stackgres.common.crd.sgcluster.StackGresClusterSsl) SecretKeySelector(io.stackgres.common.crd.SecretKeySelector) ConstraintValidationTest(io.stackgres.operator.validation.ConstraintValidationTest) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 47 with StackGresClusterReview

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);
}
Also used : StackGresClusterReview(io.stackgres.operator.common.StackGresClusterReview) StackGresClusterScriptEntry(io.stackgres.common.crd.sgcluster.StackGresClusterScriptEntry) StackGresClusterInitData(io.stackgres.common.crd.sgcluster.StackGresClusterInitData) ConstraintValidationTest(io.stackgres.operator.validation.ConstraintValidationTest) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 48 with StackGresClusterReview

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());
}
Also used : StackGresClusterReview(io.stackgres.operator.common.StackGresClusterReview) ValidationFailed(io.stackgres.operatorframework.admissionwebhook.validating.ValidationFailed) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 49 with StackGresClusterReview

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);
}
Also used : StackGresClusterReview(io.stackgres.operator.common.StackGresClusterReview) StackGresClusterPodScheduling(io.stackgres.common.crd.sgcluster.StackGresClusterPodScheduling) Random(java.util.Random) Toleration(io.stackgres.common.crd.Toleration) ConstraintValidationTest(io.stackgres.operator.validation.ConstraintValidationTest) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 50 with StackGresClusterReview

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");
}
Also used : StackGresClusterReview(io.stackgres.operator.common.StackGresClusterReview) Test(org.junit.jupiter.api.Test)

Aggregations

StackGresClusterReview (io.stackgres.operator.common.StackGresClusterReview)109 Test (org.junit.jupiter.api.Test)103 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)31 ConstraintValidationTest (io.stackgres.operator.validation.ConstraintValidationTest)29 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)26 ValidationFailed (io.stackgres.operatorframework.admissionwebhook.validating.ValidationFailed)24 StackGresClusterScriptEntry (io.stackgres.common.crd.sgcluster.StackGresClusterScriptEntry)15 StackGresCluster (io.stackgres.common.crd.sgcluster.StackGresCluster)13 StackGresClusterInitData (io.stackgres.common.crd.sgcluster.StackGresClusterInitData)12 StackGresClusterPodScheduling (io.stackgres.common.crd.sgcluster.StackGresClusterPodScheduling)9 StackGresClusterScriptFrom (io.stackgres.common.crd.sgcluster.StackGresClusterScriptFrom)9 StackGresClusterSpec (io.stackgres.common.crd.sgcluster.StackGresClusterSpec)9 SecretKeySelector (io.stackgres.common.crd.SecretKeySelector)8 Toleration (io.stackgres.common.crd.Toleration)7 QuarkusTest (io.quarkus.test.junit.QuarkusTest)5 ConfigMapKeySelector (io.stackgres.common.crd.ConfigMapKeySelector)5 StackGresClusterSsl (io.stackgres.common.crd.sgcluster.StackGresClusterSsl)4 ConfigMapBuilder (io.fabric8.kubernetes.api.model.ConfigMapBuilder)3 SecretBuilder (io.fabric8.kubernetes.api.model.SecretBuilder)2 List (java.util.List)2