Search in sources :

Example 11 with StackGresClusterReview

use of io.stackgres.operator.common.StackGresClusterReview in project stackgres by ongres.

the class RestoreConfigValidatorTest method givenAnUpdate_shouldFail.

@Test
void givenAnUpdate_shouldFail() {
    final StackGresClusterReview review = getUpdateReview();
    ValidationUtils.assertValidationFailed(() -> validator.validate(review), "Cannot update cluster's restore configuration");
    verify(scanner, never()).findResources();
}
Also used : StackGresClusterReview(io.stackgres.operator.common.StackGresClusterReview) Test(org.junit.jupiter.api.Test)

Example 12 with StackGresClusterReview

use of io.stackgres.operator.common.StackGresClusterReview in project stackgres by ongres.

the class RestoreConfigValidatorTest method givenAInvalidCreation_shouldFail.

@Test
void givenAInvalidCreation_shouldFail() {
    final StackGresClusterReview review = getCreationReview();
    StackGresCluster cluster = review.getRequest().getObject();
    StackGresClusterRestore restoreConfig = cluster.getSpec().getInitData().getRestore();
    String stackgresBackup = restoreConfig.getFromBackup().getUid();
    when(scanner.findResources()).thenReturn(Optional.empty());
    ValidationUtils.assertValidationFailed(() -> validator.validate(review), "Backup uid " + stackgresBackup + " not found");
    verify(scanner).findResources();
}
Also used : StackGresClusterReview(io.stackgres.operator.common.StackGresClusterReview) StackGresCluster(io.stackgres.common.crd.sgcluster.StackGresCluster) StackGresClusterRestore(io.stackgres.common.crd.sgcluster.StackGresClusterRestore) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.jupiter.api.Test)

Example 13 with StackGresClusterReview

use of io.stackgres.operator.common.StackGresClusterReview in project stackgres by ongres.

the class RestoreConfigValidatorTest method givenACreationWithBackupFromDifferentPgVersion_shouldFail.

@Test
void givenACreationWithBackupFromDifferentPgVersion_shouldFail() {
    final StackGresClusterReview review = getCreationReview();
    review.getRequest().getObject().getSpec().getPostgres().setVersion(secondPgMajorVersion);
    String stackgresBackup = review.getRequest().getObject().getSpec().getInitData().getRestore().getFromBackup().getUid();
    StackGresBackup backup = backupList.getItems().stream().filter(b -> b.getMetadata().getUid().equals(stackgresBackup)).findFirst().orElseThrow(AssertionError::new);
    backup.getStatus().getBackupInformation().setPostgresVersion(firstPgMajorVersionNumber);
    when(scanner.findResources()).thenReturn(Optional.of(backupList.getItems()));
    ValidationUtils.assertValidationFailed(() -> validator.validate(review), "Cannot restore from backup " + stackgresBackup + " because it comes from an incompatible postgres version");
    verify(scanner).findResources();
}
Also used : StackGresClusterReview(io.stackgres.operator.common.StackGresClusterReview) StackGresBackup(io.stackgres.common.crd.sgbackup.StackGresBackup) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.jupiter.api.Test)

Example 14 with StackGresClusterReview

use of io.stackgres.operator.common.StackGresClusterReview in project stackgres by ongres.

the class ScriptsConfigValidatorTest method givenACreationUsingScriptFromNonexistentSecretKey_shouldFail.

@Test
void givenACreationUsingScriptFromNonexistentSecretKey_shouldFail() {
    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()).build()));
    ValidationUtils.assertValidationFailed(() -> validator.validate(review), ErrorType.INVALID_CR_REFERENCE, "Key " + randomSecretKey + " does not exists in Secret " + randomSecretName);
    verify(secretFinder).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) Test(org.junit.jupiter.api.Test)

Example 15 with StackGresClusterReview

use of io.stackgres.operator.common.StackGresClusterReview in project stackgres by ongres.

the class ScriptsConfigValidatorTest method givenACreationUsingScriptFromNonexistentSecret_shouldFail.

@Test
void givenACreationUsingScriptFromNonexistentSecret_shouldFail() {
    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.empty());
    ValidationUtils.assertValidationFailed(() -> validator.validate(review), ErrorType.INVALID_CR_REFERENCE, "Referenced Secret " + randomSecretName + " does not exists in namespace " + namespace);
    verify(secretFinder).findByNameAndNamespace(randomSecretName, namespace);
}
Also used : StackGresClusterReview(io.stackgres.operator.common.StackGresClusterReview) StackGresCluster(io.stackgres.common.crd.sgcluster.StackGresCluster) 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