Search in sources :

Example 76 with StackGresClusterReview

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

Example 77 with StackGresClusterReview

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);
}
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 78 with StackGresClusterReview

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);
}
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 79 with StackGresClusterReview

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);
}
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 80 with StackGresClusterReview

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);
}
Also used : StackGresClusterReview(io.stackgres.operator.common.StackGresClusterReview) SecretBuilder(io.fabric8.kubernetes.api.model.SecretBuilder) StackGresCluster(io.stackgres.common.crd.sgcluster.StackGresCluster) StackGresClusterScriptEntry(io.stackgres.common.crd.sgcluster.StackGresClusterScriptEntry) 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