use of io.stackgres.operator.common.StackGresClusterReview in project stackgres by ongres.
the class PostgresVersionValidatorTest method givenEmptyPostgresConfigReference_shouldFail.
@Test
void givenEmptyPostgresConfigReference_shouldFail() {
final StackGresClusterReview review = JsonUtil.readFromJson("cluster_allow_requests/valid_creation.json", StackGresClusterReview.class);
StackGresClusterSpec spec = review.getRequest().getObject().getSpec();
spec.getConfiguration().setPostgresConfig("");
ValidationFailed exception = assertThrows(ValidationFailed.class, () -> {
validator.validate(review);
});
String resultMessage = exception.getResult().getMessage();
assertEquals("sgPostgresConfig must be provided", resultMessage);
verify(configFinder, never()).findByNameAndNamespace(anyString(), anyString());
}
use of io.stackgres.operator.common.StackGresClusterReview in project stackgres by ongres.
the class PostgresVersionValidatorTest method givenValidlatestPostgresVersion_shouldNotFail.
@Test
void givenValidlatestPostgresVersion_shouldNotFail() throws ValidationFailed {
final StackGresClusterReview review = JsonUtil.readFromJson("cluster_allow_requests/valid_creation.json", StackGresClusterReview.class);
StackGresClusterSpec spec = review.getRequest().getObject().getSpec();
spec.getPostgres().setVersion(StackGresComponent.LATEST);
String postgresProfile = spec.getConfiguration().getPostgresConfig();
String namespace = review.getRequest().getObject().getMetadata().getNamespace();
when(configFinder.findByNameAndNamespace(eq(postgresProfile), eq(namespace))).thenReturn(Optional.of(postgresConfig));
final String randomVersion = getRandomPostgresVersion();
spec.getPostgres().setVersion(randomVersion);
postgresConfig.getSpec().setPostgresVersion(getMajorPostgresVersion(randomVersion));
validator.validate(review);
verify(configFinder).findByNameAndNamespace(eq(postgresProfile), eq(namespace));
}
use of io.stackgres.operator.common.StackGresClusterReview in project stackgres by ongres.
the class PostgresVersionValidatorTest method givenNoPostgresConfigReference_shouldFail.
@Test
void givenNoPostgresConfigReference_shouldFail() {
final StackGresClusterReview review = JsonUtil.readFromJson("cluster_allow_requests/valid_creation.json", StackGresClusterReview.class);
StackGresClusterSpec spec = review.getRequest().getObject().getSpec();
spec.getConfiguration().setPostgresConfig(null);
ValidationFailed exception = assertThrows(ValidationFailed.class, () -> {
validator.validate(review);
});
String resultMessage = exception.getResult().getMessage();
assertEquals("sgPostgresConfig must be provided", resultMessage);
verify(configFinder, never()).findByNameAndNamespace(anyString(), anyString());
}
use of io.stackgres.operator.common.StackGresClusterReview in project stackgres by ongres.
the class PostgresVersionValidatorTest method givenADeleteUpdate_shouldDoNothing.
@Test
void givenADeleteUpdate_shouldDoNothing() throws ValidationFailed {
final StackGresClusterReview review = JsonUtil.readFromJson("cluster_allow_requests/valid_deletion.json", StackGresClusterReview.class);
review.getRequest().setOperation(Operation.DELETE);
validator.validate(review);
verify(configFinder, never()).findByNameAndNamespace(anyString(), anyString());
}
use of io.stackgres.operator.common.StackGresClusterReview in project stackgres by ongres.
the class PostgresVersionValidatorTest method givenPostgresConfigUpdate_shouldFail.
@Test
void givenPostgresConfigUpdate_shouldFail() throws ValidationFailed {
final StackGresClusterReview review = JsonUtil.readFromJson("cluster_allow_requests/postgres_config_update.json", StackGresClusterReview.class);
StackGresClusterSpec spec = review.getRequest().getObject().getSpec();
String postgresProfile = spec.getConfiguration().getPostgresConfig();
String namespace = review.getRequest().getObject().getMetadata().getNamespace();
review.getRequest().getObject().getSpec().getPostgres().setVersion(getRandomPostgresVersion());
when(configFinder.findByNameAndNamespace(eq(postgresProfile), eq(namespace))).thenReturn(Optional.empty());
ValidationFailed exception = assertThrows(ValidationFailed.class, () -> {
validator.validate(review);
});
String resultMessage = exception.getResult().getMessage();
assertEquals("Invalid sgPostgresConfig value " + postgresProfile, resultMessage);
verify(configFinder).findByNameAndNamespace(eq(postgresProfile), eq(namespace));
}
Aggregations