Search in sources :

Example 41 with StackGresClusterReview

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

the class BackupConfigValidatorTest 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 42 with StackGresClusterReview

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

the class BackupConfigValidatorTest 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 43 with StackGresClusterReview

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

the class BackupConfigValidatorTest method givenValidStackGresBackupOnCreation_shouldNotFail.

@Test
void givenValidStackGresBackupOnCreation_shouldNotFail() throws ValidationFailed {
    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.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 44 with StackGresClusterReview

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

the class BackupSourceValidatorTest method givenValidStackGresBackupOnCreation_shouldNotFail.

@Test
void givenValidStackGresBackupOnCreation_shouldNotFail() throws ValidationFailed {
    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.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 45 with StackGresClusterReview

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

the class ClusterConstraintValidatorTest method givenTolerationsSetAndEffectNoExecute_shouldPass.

@Test
void givenTolerationsSetAndEffectNoExecute_shouldPass() throws ValidationFailed {
    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("NoExecute");
    validator.validate(review);
}
Also used : StackGresClusterReview(io.stackgres.operator.common.StackGresClusterReview) StackGresClusterPodScheduling(io.stackgres.common.crd.sgcluster.StackGresClusterPodScheduling) Toleration(io.stackgres.common.crd.Toleration) 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