From 944b946e05a0e0acbcfc29b15e53dc76e7b05581 Mon Sep 17 00:00:00 2001 From: Alex Shatov Date: Thu, 28 Sep 2017 09:20:14 -0400 Subject: 4.2.2. fixed starting up of deployment-handler * start of dh was broken by coding for unit-test * Coverage summary Statements : 50.84% ( 514/1011 ) Branches : 26.11% ( 100/383 ) Functions : 30.11% ( 56/186 ) Lines : 51.35% ( 513/999 ) Change-Id: Ibb59f1ddd25a37a7bd58f4017837a622b04381e3 Issue-Id: DCAEGEN2-62 Signed-off-by: Alex Shatov --- Dockerfile_UT | 4 ++-- deployment-handler.js | 35 ++++++++++++++++++++--------------- package.json | 5 +++-- tests/test_policy.js | 7 +++++-- 4 files changed, 30 insertions(+), 21 deletions(-) diff --git a/Dockerfile_UT b/Dockerfile_UT index 3665bf2..265e1bd 100644 --- a/Dockerfile_UT +++ b/Dockerfile_UT @@ -30,5 +30,5 @@ RUN npm install \ USER ${APPUSER} VOLUME ${APPDIR}/log EXPOSE 8443 -# ENTRYPOINT ["/usr/local/bin/npm", "test"] -ENTRYPOINT ["/usr/local/bin/npm", "run", "test-cov"] +ENTRYPOINT ["/usr/local/bin/npm", "test"] +# ENTRYPOINT ["/usr/local/bin/npm", "run", "test-only"] diff --git a/deployment-handler.js b/deployment-handler.js index 171f73c..1d59733 100644 --- a/deployment-handler.js +++ b/deployment-handler.js @@ -36,24 +36,26 @@ const SWAGGER_UI_PATH = "/swagger-ui"; const app = express(); -/* Set up the application */ -app.set('x-powered-by', false); -app.set('etag', false); +const set_app = function() { + /* Set up the application */ + app.set('x-powered-by', false); + app.set('etag', false); -/* Give each request a unique request ID */ -app.use(require('./lib/middleware').assignId); + /* Give each request a unique request ID */ + app.use(require('./lib/middleware').assignId); -/* If authentication is set up, check it */ -app.use(require('./lib/auth').checkAuth); + /* If authentication is set up, check it */ + app.use(require('./lib/auth').checkAuth); -/* Set up API routes */ -app.use(INFO_PATH, require('./lib/info')); -app.use(DEPLOYMENTS_PATH, require('./lib/dcae-deployments')); -app.use(POLICY_PATH, require('./lib/policy')); -app.use(SWAGGER_UI_PATH, require('./lib/swagger-ui')); + /* Set up API routes */ + app.use(INFO_PATH, require('./lib/info')); + app.use(DEPLOYMENTS_PATH, require('./lib/dcae-deployments')); + app.use(POLICY_PATH, require('./lib/policy')); + app.use(SWAGGER_UI_PATH, require('./lib/swagger-ui')); -/* Set up error handling */ -app.use(require('./lib/middleware').handleErrors); + /* Set up error handling */ + app.use(require('./lib/middleware').handleErrors); +} const start = function(config) { @@ -77,6 +79,8 @@ const start = function(config) { log.debug(null, "Configuration: " + JSON.stringify(config)); + set_app(); + /* Start the server */ var server = null; var usingTLS = false; @@ -149,4 +153,5 @@ conf.configure() console.error("Deployment-handler exiting due to startup problem: " + e.message); }); -module.exports = app; \ No newline at end of file +module.exports.app = app; +module.exports.set_app = set_app; diff --git a/package.json b/package.json index b6215cf..2a4f7e5 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "onap-dcae-deployment-handler", - "version": "4.2.1", + "version": "4.2.2", "description": "ONAP DCAE Deployment Handler", "main": "deployment-handler.js", "dependencies": { @@ -20,7 +20,8 @@ "nock": "^9.0.21" }, "scripts": { - "test": "mocha --reporter spec tests/", + "test": "istanbul cover node_modules/mocha/bin/_mocha -- --reporter spec tests/", + "test-only": "mocha --reporter spec tests/", "test-ci": "istanbul cover node_modules/mocha/bin/_mocha --report lcovonly -- --reporter spec tests/", "test-cov": "istanbul cover node_modules/mocha/bin/_mocha -- --reporter dot tests/" }, diff --git a/tests/test_policy.js b/tests/test_policy.js index 3c1a5da..c0ad243 100644 --- a/tests/test_policy.js +++ b/tests/test_policy.js @@ -189,8 +189,11 @@ describe('test policy on deployment-handler', () => { console.log("got configuration:", JSON.stringify(config)); log.debug(REQ_ID, "Configuration: " + JSON.stringify(config)); + const main_app = require('./../deployment-handler'); - console.log("loaded main_app"); + console.log("setting main_app..."); + main_app.set_app(); + console.log("set main_app"); const req_path = "/policy/components"; const test_txt = "GET " + req_path; @@ -198,7 +201,7 @@ describe('test policy on deployment-handler', () => { console.log(test_txt); it('GET all the components with policy from cloudify', function() { console.log("chai", test_txt); - return chai.request(main_app).get(req_path) + return chai.request(main_app.app).get(req_path) .then(function(res) { console.log("res for", test_txt, JSON.stringify(res.body)); log.debug(REQ_ID, "received " + JSON.stringify(res.body)); -- cgit 1.2.3-korg