use of io.stackgres.operator.common.BackupConfigReview in project stackgres by ongres.
the class BackupConfigSourceValidatorTest method givenNonExistentSecretAccountSecretForAzureBlobStorageCredentialsOnCreation_shouldFail.
@Test
void givenNonExistentSecretAccountSecretForAzureBlobStorageCredentialsOnCreation_shouldFail() throws ValidationFailed {
final BackupConfigReview review = getEmptyReview();
String namespace = review.getRequest().getObject().getMetadata().getNamespace();
String accountName = "secret1";
String accountKey = "key1";
String accessKeyName = "secret2";
String accessKeyKey = "key2";
setAzureBlobCredentials(review, accountName, accountKey, accessKeyName, accessKeyKey);
when(secretFinder.findByNameAndNamespace(accountName, namespace)).thenReturn(Optional.of(new SecretBuilder(secret).withData(ImmutableMap.of(accountKey, ResourceUtil.encodeSecret("account"))).build()));
ValidationFailed ex = ValidationUtils.assertErrorType(ErrorType.INVALID_SECRET, () -> validator.validate(review));
assertEquals("Invalid backup configuration, secret " + accessKeyName + " for accessKey of azureblob credentials not found", ex.getResult().getMessage());
verify(secretFinder).findByNameAndNamespace(eq(accountName), eq(namespace));
}
use of io.stackgres.operator.common.BackupConfigReview in project stackgres by ongres.
the class BackupConfigSourceValidatorTest method givenExistentSecretsAndKeysForGcsStorageCredentialsOnCreation_shouldNotFail.
@Test
void givenExistentSecretsAndKeysForGcsStorageCredentialsOnCreation_shouldNotFail() throws ValidationFailed {
final BackupConfigReview review = getEmptyReview();
String namespace = review.getRequest().getObject().getMetadata().getNamespace();
String serviceAccountJsonKeyName = "secret1";
String serviceAccountJsonKeyKey = "key1";
setGcsCredentials(review, serviceAccountJsonKeyName, serviceAccountJsonKeyKey);
when(secretFinder.findByNameAndNamespace(serviceAccountJsonKeyName, namespace)).thenReturn(Optional.of(new SecretBuilder(secret).withData(ImmutableMap.of(serviceAccountJsonKeyKey, ResourceUtil.encodeSecret("serviceAccountJsonKey"))).build()));
validator.validate(review);
verify(secretFinder).findByNameAndNamespace(eq(serviceAccountJsonKeyName), eq(namespace));
}
use of io.stackgres.operator.common.BackupConfigReview in project stackgres by ongres.
the class BackupConfigDefaultValuesMutatorTest method givenConfWithAllDefaultsValuesSettledButNotDefaultStorage_shouldNotReturnAnyPatch.
@Test
public void givenConfWithAllDefaultsValuesSettledButNotDefaultStorage_shouldNotReturnAnyPatch() {
BackupConfigReview review = getDefaultReview();
review.getRequest().getObject().getSpec().getStorage().setType("s3");
AwsS3Storage s3 = new AwsS3Storage();
s3.setBucket(review.getRequest().getObject().getSpec().getStorage().getS3Compatible().getBucket());
s3.setPath(review.getRequest().getObject().getSpec().getStorage().getS3Compatible().getPath());
s3.setRegion(review.getRequest().getObject().getSpec().getStorage().getS3Compatible().getRegion());
s3.setStorageClass(review.getRequest().getObject().getSpec().getStorage().getS3Compatible().getStorageClass());
s3.setAwsCredentials(review.getRequest().getObject().getSpec().getStorage().getS3Compatible().getAwsCredentials());
review.getRequest().getObject().getSpec().getStorage().setS3(s3);
review.getRequest().getObject().getSpec().getStorage().setS3Compatible(null);
List<JsonPatchOperation> operators = mutator.mutate(review);
assertEquals(0, operators.size());
}
use of io.stackgres.operator.common.BackupConfigReview in project stackgres by ongres.
the class BackupConfigDefaultValuesMutatorTest method getEmptyReview.
@Override
protected BackupConfigReview getEmptyReview() {
BackupConfigReview backupConfigReview = JsonUtil.readFromJson("backupconfig_allow_request/create.json", BackupConfigReview.class);
backupConfigReview.getRequest().getObject().setSpec(new StackGresBackupConfigSpec());
return backupConfigReview;
}
use of io.stackgres.operator.common.BackupConfigReview in project stackgres by ongres.
the class StorageValidatorTest method givenCreationWithoutVolumeProperties_shouldFail.
@Test
void givenCreationWithoutVolumeProperties_shouldFail() {
BackupConfigReview review = JsonUtil.readFromJson("backupconfig_allow_request/invalid_creation_no_s3.json", BackupConfigReview.class);
ValidationFailed ex = assertThrows(ValidationFailed.class, () -> {
validator.validate(review);
});
String errorMessage = ex.getResult().getMessage();
assertEquals("Invalid backup configuration," + " source s3 must be set when source type is s3", errorMessage);
}
Aggregations