Search in sources :

Example 71 with StackGresClusterReview

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

the class BackupSourceValidatorTest method giveAnAttemptToUpdateToAnKnownBackup_shouldNotFail.

@Test
void giveAnAttemptToUpdateToAnKnownBackup_shouldNotFail() throws ValidationFailed {
    final StackGresClusterReview review = JsonUtil.readFromJson("cluster_allow_requests/backup_config_update.json", StackGresClusterReview.class);
    String backupConfig = review.getRequest().getObject().getSpec().getConfiguration().getBackupConfig();
    String namespace = review.getRequest().getObject().getMetadata().getNamespace();
    when(configFinder.findByNameAndNamespace(backupConfig, namespace)).thenReturn(Optional.of(this.backupConfig));
    validator.validate(review);
    verify(configFinder).findByNameAndNamespace(eq(backupConfig), eq(namespace));
}
Also used : StackGresClusterReview(io.stackgres.operator.common.StackGresClusterReview) Test(org.junit.jupiter.api.Test)

Example 72 with StackGresClusterReview

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

the class BackupSourceValidatorTest method giveInvalidStackGresBackupOnCreation_shouldFail.

@Test
void giveInvalidStackGresBackupOnCreation_shouldFail() {
    final StackGresClusterReview review = JsonUtil.readFromJson("cluster_allow_requests/valid_creation.json", StackGresClusterReview.class);
    String backupConfig = review.getRequest().getObject().getSpec().getConfiguration().getBackupConfig();
    String namespace = review.getRequest().getObject().getMetadata().getNamespace();
    when(configFinder.findByNameAndNamespace(backupConfig, namespace)).thenReturn(Optional.empty());
    ValidationFailed ex = assertThrows(ValidationFailed.class, () -> {
        validator.validate(review);
    });
    String resultMessage = ex.getMessage();
    assertEquals("Backup config " + backupConfig + " not found", resultMessage);
}
Also used : StackGresClusterReview(io.stackgres.operator.common.StackGresClusterReview) ValidationFailed(io.stackgres.operatorframework.admissionwebhook.validating.ValidationFailed) Test(org.junit.jupiter.api.Test)

Example 73 with StackGresClusterReview

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

the class BackupSourceValidatorTest method giveAnAttemptToUpdateToAnUnknownBackupConfig_shouldFail.

@Test
void giveAnAttemptToUpdateToAnUnknownBackupConfig_shouldFail() {
    final StackGresClusterReview review = JsonUtil.readFromJson("cluster_allow_requests/backup_config_update.json", StackGresClusterReview.class);
    String backupConfig = review.getRequest().getObject().getSpec().getConfiguration().getBackupConfig();
    String namespace = review.getRequest().getObject().getMetadata().getNamespace();
    when(configFinder.findByNameAndNamespace(backupConfig, namespace)).thenReturn(Optional.empty());
    ValidationFailed ex = assertThrows(ValidationFailed.class, () -> {
        validator.validate(review);
    });
    String resultMessage = ex.getMessage();
    assertEquals("Cannot update to backup config " + backupConfig + " because it doesn't exists", resultMessage);
    verify(configFinder).findByNameAndNamespace(eq(backupConfig), eq(namespace));
}
Also used : StackGresClusterReview(io.stackgres.operator.common.StackGresClusterReview) ValidationFailed(io.stackgres.operatorframework.admissionwebhook.validating.ValidationFailed) Test(org.junit.jupiter.api.Test)

Example 74 with StackGresClusterReview

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

the class BackupSourceValidatorTest method giveAnAttemptToDelete_shouldNotFail.

@Test
void giveAnAttemptToDelete_shouldNotFail() throws ValidationFailed {
    final StackGresClusterReview review = JsonUtil.readFromJson("cluster_allow_requests/backup_config_update.json", StackGresClusterReview.class);
    review.getRequest().setOperation(Operation.DELETE);
    String backupConfig = review.getRequest().getObject().getSpec().getConfiguration().getBackupConfig();
    String namespace = review.getRequest().getObject().getMetadata().getNamespace();
    validator.validate(review);
    verify(configFinder, never()).findByNameAndNamespace(eq(backupConfig), eq(namespace));
}
Also used : StackGresClusterReview(io.stackgres.operator.common.StackGresClusterReview) Test(org.junit.jupiter.api.Test)

Example 75 with StackGresClusterReview

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

the class ClusterConstraintValidatorTest method scriptFromConfigMapWithEmptyKey_shouldFail.

@Test
void scriptFromConfigMapWithEmptyKey_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());
    review.getRequest().getObject().getSpec().getInitData().getScripts().get(0).setScriptFrom(new StackGresClusterScriptFrom());
    review.getRequest().getObject().getSpec().getInitData().getScripts().get(0).getScriptFrom().setConfigMapKeyRef(new ConfigMapKeySelector());
    review.getRequest().getObject().getSpec().getInitData().getScripts().get(0).getScriptFrom().getConfigMapKeyRef().setName("test");
    review.getRequest().getObject().getSpec().getInitData().getScripts().get(0).getScriptFrom().getConfigMapKeyRef().setKey("");
    checkErrorCause(SecretKeySelector.class, "spec.initData.scripts[0].scriptFrom.configMapKeyRef.key", "isKeyNotEmpty", 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) StackGresClusterScriptFrom(io.stackgres.common.crd.sgcluster.StackGresClusterScriptFrom) ConfigMapKeySelector(io.stackgres.common.crd.ConfigMapKeySelector) ConstraintValidationTest(io.stackgres.operator.validation.ConstraintValidationTest) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

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