@contract-case/case-core
Version:
Core functionality for the ContractCase contract testing suite
50 lines • 2.52 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.DeployChecker = void 0;
const case_plugin_base_1 = require("@contract-case/case-plugin-base");
const config_1 = require("../../core/config");
const dependencies_1 = require("../dependencies");
class DeployChecker {
context;
broker;
resultPrinter;
constructor(config, printer, parentVersions, dependencies = (0, dependencies_1.writerDependencies)(printer)) {
this.context = (0, case_plugin_base_1.constructDataContext)(dependencies.makeLogger, dependencies.resultFormatter, {
...(0, config_1.configToRunContext)({
...dependencies.defaultConfig,
...(0, config_1.configFromEnv)(),
...config,
}),
}, dependencies.defaultConfig, parentVersions);
this.broker = dependencies.makeBrokerService(this.context);
this.resultPrinter = dependencies.resultFormatter;
}
/**
* Checks whether it's safe to deploy to a particular environment
*
* @param serviceName - The name of the service to check
* @param environment - The environment to see if it's safe to deploy to$a
* @param versionOverride - Optionally, an override for the version to check
* @returns Promise that resolves to true if it is safe to deploy, false otherwise.
*/
async check(serviceName, environment, versionOverride) {
if (serviceName === '' || serviceName == null) {
throw new case_plugin_base_1.CaseConfigurationError('Must provide a service name in order to check can-deploy', 'DONT_ADD_LOCATION', 'INVALID_CONFIG');
}
if (environment === '' || environment == null) {
throw new case_plugin_base_1.CaseConfigurationError('Must provide an environment to deploy to in order to check can-deploy', 'DONT_ADD_LOCATION', 'INVALID_CONFIG');
}
return this.broker
.canDeploy(serviceName, environment, this.context, versionOverride)
.then((result) => {
if (result.deployable) {
this.resultPrinter.printDownloadedContract(`Safe to deploy '${serviceName}' to '${environment}'`, this.context);
return true;
}
this.resultPrinter.printDownloadedContract(`Not safe to deploy '${serviceName}' to '${environment}': ${result.reason}`, this.context);
return false;
});
}
}
exports.DeployChecker = DeployChecker;
//# sourceMappingURL=DeployChecker.js.map