Search in sources :

Example 81 with StackGresClusterReview

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

Example 82 with StackGresClusterReview

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

Example 83 with StackGresClusterReview

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

Example 84 with StackGresClusterReview

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

Example 85 with StackGresClusterReview

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");
}
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