use of io.stackgres.operator.common.StackGresClusterReview in project stackgres by ongres.
the class PostgresVersionValidatorTest method givenAnEmptyPostgresVersion_shouldFail.
@Test
void givenAnEmptyPostgresVersion_shouldFail() {
final StackGresClusterReview review = JsonUtil.readFromJson("cluster_allow_requests/invalid_creation_empty_pg_version.json", StackGresClusterReview.class);
ValidationFailed exception = assertThrows(ValidationFailed.class, () -> {
validator.validate(review);
});
String resultMessage = exception.getResult().getMessage();
assertEquals("postgres version 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 givenMajorPostgresVersionUpdate_shouldPass.
@Test
void givenMajorPostgresVersionUpdate_shouldPass() throws ValidationFailed {
final StackGresClusterReview review = JsonUtil.readFromJson("cluster_allow_requests/major_postgres_version_update.json", StackGresClusterReview.class);
review.getRequest().getObject().getSpec().getPostgres().setVersion(firstPgMajorVersion);
review.getRequest().getOldObject().getSpec().getPostgres().setVersion(secondPgMajorVersion);
validator.validate(review);
}
use of io.stackgres.operator.common.StackGresClusterReview in project stackgres by ongres.
the class PostgresVersionValidatorTest method givenWrongMajorPostgresVersionUpdate_shouldFail.
@Test
void givenWrongMajorPostgresVersionUpdate_shouldFail() {
final StackGresClusterReview review = JsonUtil.readFromJson("cluster_allow_requests/wrong_major_postgres_version_update.json", StackGresClusterReview.class);
review.getRequest().getObject().getSpec().getPostgres().setVersion(secondPgMajorVersion);
review.getRequest().getOldObject().getSpec().getPostgres().setVersion(firstPgMajorVersion);
ValidationFailed exception = assertThrows(ValidationFailed.class, () -> {
validator.validate(review);
});
String resultMessage = exception.getResult().getMessage();
assertEquals("postgres version can not be changed to a previous major version", resultMessage);
}
use of io.stackgres.operator.common.StackGresClusterReview in project stackgres by ongres.
the class PostgresVersionValidatorTest method givenMinorPostgresVersionUpdate_shouldPass.
@Test
void givenMinorPostgresVersionUpdate_shouldPass() throws ValidationFailed {
final StackGresClusterReview review = JsonUtil.readFromJson("cluster_allow_requests/minor_postgres_version_update.json", StackGresClusterReview.class);
review.getRequest().getObject().getSpec().getPostgres().setVersion(firstPgMinorVersion);
review.getRequest().getOldObject().getSpec().getPostgres().setVersion(secondPgMinorVersion);
validator.validate(review);
}
use of io.stackgres.operator.common.StackGresClusterReview in project stackgres by ongres.
the class PostgresVersionValidatorTest method givenValidPostgresVersion_shouldNotFail.
@Test
void givenValidPostgresVersion_shouldNotFail() throws ValidationFailed {
final StackGresClusterReview review = JsonUtil.readFromJson("cluster_allow_requests/valid_creation.json", StackGresClusterReview.class);
StackGresClusterSpec spec = review.getRequest().getObject().getSpec();
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));
}
Aggregations