Skip to content

Commit

Permalink
Added validations for openshift-related deployments
Browse files Browse the repository at this point in the history
  • Loading branch information
MathieuAA committed Jun 1, 2021
1 parent deb9a7b commit ebbae42
Show file tree
Hide file tree
Showing 2 changed files with 127 additions and 1 deletion.
20 changes: 19 additions & 1 deletion jdl/validators/deployment-validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
*/

const { MICROSERVICE } = require('../jhipster/application-types');
const { NO } = require('../jhipster/database-types');
const { ELASTICSEARCH } = require('../jhipster/search-engine-types');
const { Options } = require('../jhipster/deployment-options');
const Validator = require('./validator');

Expand All @@ -37,7 +39,7 @@ module.exports = class DeploymentValidator extends Validator {
validateKubernetesRelatedDeployment(jdlDeployment);
break;
case Options.deploymentType.openshift:
// TODO
validateOpenshiftRelatedDeployment(jdlDeployment, options);
break;
default:
throw new Error(`The deployment type ${jdlDeployment.deploymentType} isn't supported.`);
Expand All @@ -64,3 +66,19 @@ function validateKubernetesRelatedDeployment(jdlDeployment) {
throw new Error('An ingress type is required when dealing with kubernetes-related deployments and when the service type is ingress.');
}
}

function validateOpenshiftRelatedDeployment(jdlDeployment, options) {
if (jdlDeployment.storageType) {
if (options.prodDatabaseType === NO) {
throw new Error("Can't have the storageType option set when there is no prodDatabaseType.");
}

if (options.searchEngine === ELASTICSEARCH) {
throw new Error("Can't have the storageType option set when elasticsearch is the search engine.");
}

if (jdlDeployment.monitoring === Options.monitoring.prometheus) {
throw new Error("Can't have the storageType option set when the monitoring is done with prometheus.");
}
}
}
108 changes: 108 additions & 0 deletions test/jdl/validators/deployment-validator.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
const { expect } = require('chai');
const { Options } = require('../../../jdl/jhipster/deployment-options');
const { MICROSERVICE } = require('../../../jdl/jhipster/application-types');
const { MONGODB, NO } = require('../../../jdl/jhipster/database-types');
const SearchEngineTypes = require('../../../jdl/jhipster/search-engine-types');
const DeploymentValidator = require('../../../jdl/validators/deployment-validator');

describe('DeploymentValidator', () => {
Expand Down Expand Up @@ -200,6 +202,112 @@ describe('DeploymentValidator', () => {
});
});
});
context('when having an openshift-related deployment', () => {
context('without appFolders', () => {
it('should fail', () => {
expect(() =>
validator.validate({
deploymentType: Options.deploymentType.openshift,
directoryPath: '../',
gatewayType: Options.gatewayType.springCloudGateway,
openshiftNamespace: 'default',
})
).to.throw(/^The deployment attribute appsFolders was not found.$/);
});
});
context('without directoryPath', () => {
it('should fail', () => {
expect(() =>
validator.validate({
deploymentType: Options.deploymentType.openshift,
appsFolders: ['beers', 'burgers'],
monitoring: 'no',
openshiftNamespace: 'default',
})
).to.throw(/^The deployment attribute directoryPath was not found.$/);
});
});
context('without monitoring', () => {
it('should not fail', () => {
expect(() =>
validator.validate({
deploymentType: Options.deploymentType.openshift,
appsFolders: ['beers', 'burgers'],
directoryPath: '../',
openshiftNamespace: 'default',
})
).not.to.throw();
});
});
context('without openshiftNamespace', () => {
it('should not fail', () => {
expect(() =>
validator.validate({
deploymentType: Options.deploymentType.openshift,
appsFolders: ['beers', 'burgers'],
directoryPath: '../',
})
).not.to.throw();
});
});
context('when there is no prodDatabaseType', () => {
it('should fail if there is a storageType', () => {
expect(() =>
validator.validate(
{
deploymentType: Options.deploymentType.openshift,
appsFolders: ['beers', 'burgers'],
directoryPath: '../',
storageType: Options.storageType.ephemeral,
},
{ prodDatabaseType: NO }
)
).to.throw(/^Can't have the storageType option set when there is no prodDatabaseType.$/);
});
});
context('when the search engine is elasticsearch', () => {
it('should fail if there is a storageType', () => {
expect(() =>
validator.validate(
{
deploymentType: Options.deploymentType.openshift,
appsFolders: ['beers', 'burgers'],
directoryPath: '../',
storageType: Options.storageType.ephemeral,
},
{ searchEngine: SearchEngineTypes.ELASTICSEARCH }
)
).to.throw(/^Can't have the storageType option set when elasticsearch is the search engine.$/);
});
});
context('when the monitoring is done with prometheus', () => {
it('should fail if there is a storageType', () => {
expect(() =>
validator.validate({
deploymentType: Options.deploymentType.openshift,
appsFolders: ['beers', 'burgers'],
directoryPath: '../',
storageType: Options.storageType.ephemeral,
monitoring: Options.monitoring.prometheus,
})
).to.throw(/^Can't have the storageType option set when the monitoring is done with prometheus.$/);
});
});
context('when the prodDatabaseType is set and the storageType is not set', () => {
it('should not fail', () => {
expect(() =>
validator.validate(
{
deploymentType: Options.deploymentType.openshift,
appsFolders: ['beers', 'burgers'],
directoryPath: '../',
},
{ prodDatabaseType: MONGODB }
)
).not.to.throw();
});
});
});
});
context('when passing an unknown deployment type', () => {
it('should fail', () => {
Expand Down

0 comments on commit ebbae42

Please sign in to comment.