Search in sources :

Example 1 with StackGresClusterList

use of io.stackgres.common.crd.sgcluster.StackGresClusterList in project stackgres by ongres.

the class DependenciesValidatorTest method givenAReviewDelete_itShouldFailIfAClusterDependsOnIt.

@Test
public void givenAReviewDelete_itShouldFailIfAClusterDependsOnIt() {
    T review = getReview_givenAReviewDelete_itShouldFailIfAClusterDependsOnIt();
    StackGresClusterList clusterList = JsonUtil.readFromJson("stackgres_cluster/list.json", StackGresClusterList.class);
    when(clusterScanner.findResources(review.getRequest().getNamespace())).thenReturn(Optional.of(clusterList.getItems()));
    ValidationFailed ex = ValidationUtils.assertErrorType(ErrorType.FORBIDDEN_CR_DELETION, () -> validator.validate(review));
    assertEquals("Can't delete " + review.getRequest().getResource().getResource() + "." + review.getRequest().getKind().getGroup() + " " + review.getRequest().getName() + " because the " + CustomResource.getCRDName(StackGresCluster.class) + " " + clusterList.getItems().get(0).getMetadata().getName() + " depends on it", ex.getResult().getMessage());
}
Also used : StackGresCluster(io.stackgres.common.crd.sgcluster.StackGresCluster) StackGresClusterList(io.stackgres.common.crd.sgcluster.StackGresClusterList) ValidationFailed(io.stackgres.operatorframework.admissionwebhook.validating.ValidationFailed) Test(org.junit.jupiter.api.Test)

Example 2 with StackGresClusterList

use of io.stackgres.common.crd.sgcluster.StackGresClusterList in project stackgres by ongres.

the class DependenciesValidatorTest method givenAReviewDelete_itShouldNotFailIfNoClusterDependsOnIt.

@Test
public void givenAReviewDelete_itShouldNotFailIfNoClusterDependsOnIt() throws ValidationFailed {
    T review = getReview_givenAReviewDelete_itShouldNotFailIfNoClusterDependsOnIt();
    StackGresClusterList clusterList = JsonUtil.readFromJson("stackgres_cluster/list.json", StackGresClusterList.class);
    clusterList.getItems().stream().forEach(this::makeClusterNotDependant);
    when(clusterScanner.findResources(review.getRequest().getNamespace())).thenReturn(Optional.of(clusterList.getItems()));
    validator.validate(review);
    verify(clusterScanner, never()).findResources();
    verify(clusterScanner).findResources(review.getRequest().getNamespace());
}
Also used : StackGresClusterList(io.stackgres.common.crd.sgcluster.StackGresClusterList) Test(org.junit.jupiter.api.Test)

Aggregations

StackGresClusterList (io.stackgres.common.crd.sgcluster.StackGresClusterList)2 Test (org.junit.jupiter.api.Test)2 StackGresCluster (io.stackgres.common.crd.sgcluster.StackGresCluster)1 ValidationFailed (io.stackgres.operatorframework.admissionwebhook.validating.ValidationFailed)1