summaryrefslogtreecommitdiffstats
path: root/tests/mock_deployment_handler.js
diff options
context:
space:
mode:
authorAlex Shatov <alexs@att.com>2018-01-24 13:35:28 -0500
committerAlex Shatov <alexs@att.com>2018-01-24 13:35:28 -0500
commit4e30c82b172cf422ab5179e3c566ef01ca14cb3a (patch)
tree0efa3043daeb8001516d671df5d8e1b81ca4b798 /tests/mock_deployment_handler.js
parent70253f7088be04125d9fac8f9bddfaa63778608e (diff)
unit tests coverage 68% and more info in audit
* refactored the unit test - simpler dh server initialization * new unit tests for the dcae-deployments * new unit tests for healthcheck - info * new server_instance_uuid - unique per deployment-handler instance for logging and info * dragging req object over the stack to show req data in logging and audit and metrics * new feature variable collection of policies per component in DCAE Change-Id: I8388d7e5e11e3a6c871cf3d507bd8a07b09add29 Issue-ID: DCAEGEN2-249 Signed-off-by: Alex Shatov <alexs@att.com>
Diffstat (limited to 'tests/mock_deployment_handler.js')
-rw-r--r--tests/mock_deployment_handler.js102
1 files changed, 102 insertions, 0 deletions
diff --git a/tests/mock_deployment_handler.js b/tests/mock_deployment_handler.js
new file mode 100644
index 0000000..ed0468f
--- /dev/null
+++ b/tests/mock_deployment_handler.js
@@ -0,0 +1,102 @@
+/*
+Copyright(c) 2018 AT&T Intellectual Property. All rights reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
+CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and limitations under the License.
+*/
+
+/**
+ * mock-deployment_handler - base server for all other tests
+ */
+
+"use strict";
+
+const nock = require('nock');
+const utils = require('./mock_utils');
+
+const MAIN_PATH = './../';
+
+const CONSUL_URL = 'http://consul:8500';
+const MOCK_CLOUDIFY_MANAGER = "mock_cloudify_manager";
+const CLOUDIFY_URL = "http://" + MOCK_CLOUDIFY_MANAGER + ":80";
+
+const MOCK_INVENTORY = "mock_inventory";
+const INVENTORY_URL = "https://" + MOCK_INVENTORY + ":8080";
+
+nock(CONSUL_URL).persist().get('/v1/kv/deployment_handler?raw')
+ .reply(200, {"logLevel": "DEBUG", "cloudify": {"protocol": "http"}});
+
+nock(CONSUL_URL).persist().get('/v1/catalog/service/cloudify_manager')
+ .reply(200, [{
+ "ID":"deadbeef-dead-beef-dead-beefdeadbeef",
+ "Node":"devorcl00",
+ "Address": MOCK_CLOUDIFY_MANAGER,
+ "Datacenter":"rework-central",
+ "TaggedAddresses":{"lan": MOCK_CLOUDIFY_MANAGER,"wan": MOCK_CLOUDIFY_MANAGER},
+ "NodeMeta":{},
+ "ServiceID":"cloudify_manager",
+ "ServiceName":"cloudify_manager",
+ "ServiceTags":["http://" + MOCK_CLOUDIFY_MANAGER + "/api/v2.1"],
+ "ServiceAddress": MOCK_CLOUDIFY_MANAGER,
+ "ServicePort":80,
+ "ServiceEnableTagOverride":false,
+ "CreateIndex":16,
+ "ModifyIndex":16
+ }]);
+
+nock(CONSUL_URL).persist().get('/v1/catalog/service/inventory')
+ .reply(200, [{
+ "ID": "",
+ "Node": "inventory_mock_node",
+ "Address": MOCK_INVENTORY,
+ "Datacenter": "rework-central",
+ "TaggedAddresses": null,
+ "NodeMeta": null,
+ "ServiceID": "inventory",
+ "ServiceName": "inventory",
+ "ServiceTags": [],
+ "ServiceAddress": "",
+ "ServicePort": 8080,
+ "ServiceEnableTagOverride": false,
+ "CreateIndex": 8068,
+ "ModifyIndex": 8068
+ }]);
+
+const tests = [];
+
+const run_dh = function() {
+ describe('run deployment-handler', () => {
+ it('starting deployment-handler server', function() {
+ console.log("starting deployment-handler server");
+ const dh_server = require(MAIN_PATH + 'deployment-handler');
+
+ return utils.sleep(5000).then(function() {
+ console.log("starting tests: count =", tests.length);
+ if (Array.isArray(tests)) {
+ tests.forEach(test => {
+ test(dh_server);
+ });
+ }
+ })
+ .catch(function(e) {
+ const error = "test of deployment-handler exiting due to test problem: " + e.message;
+ console.error(error);
+ throw e;
+ });
+ }).timeout(10000);
+ });
+};
+
+module.exports.INVENTORY_URL = INVENTORY_URL;
+module.exports.CLOUDIFY_URL = CLOUDIFY_URL;
+module.exports.add_tests = function(new_tests) {Array.prototype.push.apply(tests, new_tests);};
+module.exports.run_dh = run_dh; \ No newline at end of file