use of io.stackgres.common.crd.ConfigMapKeySelector in project stackgres by ongres.
the class ClusterConstraintValidatorTest method validScriptFromConfigMap_shouldPass.
@Test
void validScriptFromConfigMap_shouldPass() throws ValidationFailed {
StackGresClusterReview review = getValidReview();
review.getRequest().getObject().getSpec().setInitData(new StackGresClusterInitData());
review.getRequest().getObject().getSpec().getInitData().setScripts(new ArrayList<>());
review.getRequest().getObject().getSpec().getInitData().getScripts().add(new StackGresClusterScriptEntry());
review.getRequest().getObject().getSpec().getInitData().getScripts().get(0).setScriptFrom(new StackGresClusterScriptFrom());
review.getRequest().getObject().getSpec().getInitData().getScripts().get(0).getScriptFrom().setConfigMapKeyRef(new ConfigMapKeySelector());
review.getRequest().getObject().getSpec().getInitData().getScripts().get(0).getScriptFrom().getConfigMapKeyRef().setName("test");
review.getRequest().getObject().getSpec().getInitData().getScripts().get(0).getScriptFrom().getConfigMapKeyRef().setKey("test");
validator.validate(review);
}
use of io.stackgres.common.crd.ConfigMapKeySelector in project stackgres by ongres.
the class ClusterConstraintValidatorTest method validScriptAndScriptFrom_shouldFail.
@Test
void validScriptAndScriptFrom_shouldFail() {
StackGresClusterReview review = getValidReview();
review.getRequest().getObject().getSpec().setInitData(new StackGresClusterInitData());
review.getRequest().getObject().getSpec().getInitData().setScripts(new ArrayList<>());
review.getRequest().getObject().getSpec().getInitData().getScripts().add(new StackGresClusterScriptEntry());
review.getRequest().getObject().getSpec().getInitData().getScripts().get(0).setScriptFrom(new StackGresClusterScriptFrom());
review.getRequest().getObject().getSpec().getInitData().getScripts().get(0).setScript("SELECT 1");
review.getRequest().getObject().getSpec().getInitData().getScripts().get(0).getScriptFrom().setConfigMapKeyRef(new ConfigMapKeySelector());
review.getRequest().getObject().getSpec().getInitData().getScripts().get(0).getScriptFrom().getConfigMapKeyRef().setName("test");
review.getRequest().getObject().getSpec().getInitData().getScripts().get(0).getScriptFrom().getConfigMapKeyRef().setKey("test");
checkErrorCause(StackGresClusterScriptEntry.class, new String[] { "spec.initData.scripts[0].script", "spec.initData.scripts[0].scriptFrom" }, "isScriptMutuallyExclusiveAndRequired", review, AssertTrue.class);
}
use of io.stackgres.common.crd.ConfigMapKeySelector in project stackgres by ongres.
the class ClusterConstraintValidatorTest method scriptFromConfigMapWithEmptyKey_shouldFail.
@Test
void scriptFromConfigMapWithEmptyKey_shouldFail() {
StackGresClusterReview review = getValidReview();
review.getRequest().getObject().getSpec().setInitData(new StackGresClusterInitData());
review.getRequest().getObject().getSpec().getInitData().setScripts(new ArrayList<>());
review.getRequest().getObject().getSpec().getInitData().getScripts().add(new StackGresClusterScriptEntry());
review.getRequest().getObject().getSpec().getInitData().getScripts().get(0).setScriptFrom(new StackGresClusterScriptFrom());
review.getRequest().getObject().getSpec().getInitData().getScripts().get(0).getScriptFrom().setConfigMapKeyRef(new ConfigMapKeySelector());
review.getRequest().getObject().getSpec().getInitData().getScripts().get(0).getScriptFrom().getConfigMapKeyRef().setName("test");
review.getRequest().getObject().getSpec().getInitData().getScripts().get(0).getScriptFrom().getConfigMapKeyRef().setKey("");
checkErrorCause(SecretKeySelector.class, "spec.initData.scripts[0].scriptFrom.configMapKeyRef.key", "isKeyNotEmpty", review, AssertTrue.class);
}
use of io.stackgres.common.crd.ConfigMapKeySelector in project stackgres by ongres.
the class ScriptsConfigValidatorTest method prepareForConfigMap.
private void prepareForConfigMap(StackGresClusterReview review, String name, String key) {
review.getRequest().getObject().getSpec().getInitData().getScripts().forEach(s -> {
s.setName(null);
s.setScript(null);
s.setDatabase(null);
s.setScriptFrom(new StackGresClusterScriptFrom());
s.getScriptFrom().setConfigMapKeyRef(new ConfigMapKeySelector(key, name));
});
}
use of io.stackgres.common.crd.ConfigMapKeySelector in project stackgres by ongres.
the class ClusterResourceMockedTest method createClusterWithConfigMapScriptReference_shouldNotFail.
@Test
void createClusterWithConfigMapScriptReference_shouldNotFail() {
dto = getClusterInlineScripts();
ClusterScriptEntry entry = buildConfigMapScriptEntry();
dto.getSpec().getInitData().setScripts(Collections.singletonList(entry));
doNothing().when(configMapTransactionHandler).create(any(ConfigMap.class), any(Runnable.class));
super.createShouldNotFail();
ArgumentCaptor<ConfigMap> secretArgument = ArgumentCaptor.forClass(ConfigMap.class);
verify(configMapTransactionHandler).create(secretArgument.capture(), any(Runnable.class));
ConfigMap createdSecret = secretArgument.getValue();
assertEquals(dto.getMetadata().getNamespace(), createdSecret.getMetadata().getNamespace());
final ClusterScriptFrom scriptFrom = entry.getScriptFrom();
final ConfigMapKeySelector configMapKeyRef = scriptFrom.getConfigMapKeyRef();
assertEquals(configMapKeyRef.getName(), createdSecret.getMetadata().getName());
assertTrue(createdSecret.getData().containsKey(configMapKeyRef.getKey()));
assertEquals(scriptFrom.getConfigMapScript(), createdSecret.getData().get(configMapKeyRef.getKey()));
}
Aggregations