How to use contextAttrs method in wpt

Best JavaScript code snippet using wpt

test_parser.js

Source:test_parser.js Github

copy

Full Screen

1/*2 * Copyright 2015-2016 Telefónica I+D3 * All Rights Reserved.4 *5 * Licensed under the Apache License, Version 2.0 (the "License"); you may6 * not use this file except in compliance with the License. You may obtain7 * a copy of the License at8 *9 * http://www.apache.org/licenses/LICENSE-2.010 *11 * Unless required by applicable law or agreed to in writing, software12 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT13 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the14 * License for the specific language governing permissions and limitations15 * under the License.16 */17/**18 * Module that defines unit tests for the Monasca Persister data points parser.19 *20 * @module test_parser21 */22'use strict';23/* jshint sub: true, unused: false */24var util = require('util'),25 assert = require('assert'),26 base = require('../../lib/monasca_persister_data_point'),27 metricsMappingNGSI = base.metricsMappingNGSI,28 regionMetricMetadata = base.regionMetricMetadata,29 parser = base.parser;30suite('parser', function () {31 suiteSetup(function () {32 this.sampleMetricRegion = 'metric_region';33 });34 suiteTeardown(function () {35 });36 setup(function () {37 });38 teardown(function () {39 });40 test('parse_fails_unknown_metric_dimensions', function () {41 var data = require('./sample_data_point_generic.json'),42 reqdomain = {43 body: JSON.stringify(data)44 };45 assert.throws(46 function () {47 parser.parseRequest(reqdomain);48 },49 /unknown metric name or dimensions/50 );51 });52 test('parse_gets_valid_entity_type_of_data_point_host_service', function () {53 var type = 'host_service',54 data = require('./sample_data_point_' + type + '.json'),55 reqdomain = {56 body: JSON.stringify(data)57 };58 parser.parseRequest(reqdomain);59 assert.equal(reqdomain.entityType, type);60 });61 test('parse_gets_valid_entity_id_of_data_point_host_service', function () {62 var type = 'host_service',63 data = require('./sample_data_point_' + type + '.json'),64 region = this.sampleMetricRegion,65 service = data.metric.dimensions['component'],66 expectedIdPattern = util.format('%s:.*:%s', region, service),67 reqdomain = {68 body: JSON.stringify(data)69 };70 parser.parseRequest(reqdomain);71 assert(reqdomain.entityId.match(new RegExp(expectedIdPattern)));72 });73 test('default_controller_hostname_in_entity_id_of_data_point_host_service', function () {74 var type = 'host_service',75 data = require('./sample_data_point_' + type + '.json'),76 region = this.sampleMetricRegion,77 service = data.metric.dimensions['component'],78 expectedIdPattern = util.format('%s:%s:%s', region, 'controller', service),79 reqdomain = {80 body: JSON.stringify(data)81 };82 parser.parseRequest(reqdomain);83 assert.equal(data.metric.dimensions['hostname'], undefined);84 assert(reqdomain.entityId.match(new RegExp(expectedIdPattern)));85 });86 test('explicit_hostname_in_entity_id_of_data_point_host_service', function () {87 var type = 'host_service',88 data = require('./sample_data_point_' + type + '.json'),89 region = this.sampleMetricRegion,90 service = data.metric.dimensions['component'],91 hostname = 'some_hostname',92 expectedIdPattern = util.format('%s:%s:%s', region, hostname, service);93 data.metric.dimensions['hostname'] = hostname;94 var reqdomain = {95 body: JSON.stringify(data)96 };97 parser.parseRequest(reqdomain);98 assert.equal(data.metric.dimensions['hostname'], hostname);99 assert(reqdomain.entityId.match(new RegExp(expectedIdPattern)));100 });101 test('context_attrs_include_service_status_of_data_point_host_service', function () {102 var type = 'host_service',103 data = require('./sample_data_point_' + type + '.json'),104 expectedAttr = data.metric.dimensions['component'].replace('-', '_'),105 expectedValue = data.metric.value,106 reqdomain = {107 body: JSON.stringify(data)108 };109 var entityData = parser.parseRequest(reqdomain),110 contextAttrs = parser.getContextAttrs(entityData);111 assert(contextAttrs[expectedAttr]);112 assert.equal(contextAttrs[expectedAttr], expectedValue);113 });114 test('parse_gets_valid_entity_type_of_data_point_region_ip', function () {115 var type = 'region',116 file = 'region_ip',117 data = require('./sample_data_point_' + file + '.json'),118 reqdomain = {119 body: JSON.stringify(data)120 };121 parser.parseRequest(reqdomain);122 assert.equal(reqdomain.entityType, type);123 });124 test('parse_gets_valid_entity_id_of_data_point_region_ip', function () {125 var type = 'region',126 file = 'region_ip',127 data = require('./sample_data_point_' + file + '.json'),128 region = this.sampleMetricRegion,129 expectedId = region,130 reqdomain = {131 body: JSON.stringify(data)132 };133 parser.parseRequest(reqdomain);134 assert.equal(reqdomain.entityId, expectedId);135 });136 test('context_attrs_include_measurement_of_data_point_region_ip', function () {137 var type = 'region',138 file = 'region_ip',139 data = require('./sample_data_point_' + file + '.json'),140 expectedAttr = metricsMappingNGSI[data.metric.name] || data.metric.name,141 expectedValue = data.metric.value,142 reqdomain = {143 body: JSON.stringify(data)144 };145 var entityData = parser.parseRequest(reqdomain),146 contextAttrs = parser.getContextAttrs(entityData);147 assert(contextAttrs[expectedAttr]);148 assert.equal(contextAttrs[expectedAttr], expectedValue);149 });150 test('context_attrs_include_metadata_of_data_point_region_ip', function () {151 var type = 'region',152 metric = regionMetricMetadata,153 data = require('./sample_data_point_' + metric.replace('.', '_') + '.json'),154 valueMeta = data.metric['value_meta'],155 expectedAttr = metricsMappingNGSI[data.metric.name] || data.metric.name,156 expectedValue = data.metric.value,157 reqdomain = {158 body: JSON.stringify(data)159 };160 var entityData = parser.parseRequest(reqdomain),161 contextAttrs = parser.getContextAttrs(entityData);162 assert.equal(reqdomain.entityType, type);163 assert.equal(data.metric.name, metric);164 assert(contextAttrs[expectedAttr]);165 assert.equal(contextAttrs[expectedAttr], expectedValue);166 for (var item in valueMeta) {167 assert(contextAttrs[item]);168 assert.equal(contextAttrs[item], valueMeta[item]);169 }170 });171 test('context_attrs_include_status_of_data_point_region_sanity_checks', function () {172 var type = 'region',173 metric = 'region.sanity_checks',174 data = require('./sample_data_point_' + metric.replace('.', '_') + '.json'),175 expectedSanityAttrs = ['sanity_status', 'sanity_check_timestamp', 'sanity_check_elapsed_time'],176 reqdomain = {177 body: JSON.stringify(data)178 };179 var entityData = parser.parseRequest(reqdomain),180 contextAttrs = parser.getContextAttrs(entityData);181 assert.equal(reqdomain.entityType, type);182 expectedSanityAttrs.forEach(function (attr) {183 assert(contextAttrs[attr]);184 });185 });186 test('parse_gets_valid_entity_type_of_data_point_image', function () {187 var type = 'image',188 data = require('./sample_data_point_' + type + '.json'),189 reqdomain = {190 body: JSON.stringify(data)191 };192 parser.parseRequest(reqdomain);193 assert.equal(reqdomain.entityType, type);194 });195 test('parse_gets_valid_entity_id_of_data_point_image', function () {196 var type = 'image',197 data = require('./sample_data_point_' + type + '.json'),198 region = this.sampleMetricRegion,199 resource = data.metric.dimensions['resource_id'],200 expectedIdPattern = util.format('%s:%s', region, resource),201 reqdomain = {202 body: JSON.stringify(data)203 };204 parser.parseRequest(reqdomain);205 assert(reqdomain.entityId.match(new RegExp(expectedIdPattern)));206 });207 test('context_attrs_include_standard_metrics_of_data_point_image', function () {208 var type = 'image',209 data = require('./sample_data_point_' + type + '.json'),210 valueMeta = data.metric['value_meta'],211 itemsMeta = ['size', 'status', 'name'],212 reqdomain = {213 body: JSON.stringify(data)214 };215 var entityData = parser.parseRequest(reqdomain),216 contextAttrs = parser.getContextAttrs(entityData);217 for (var i in itemsMeta) {218 var metricName = itemsMeta[i],219 expectedAttr = metricsMappingNGSI[metricName] || metricName,220 expectedValue = valueMeta[metricName];221 assert(contextAttrs[expectedAttr]);222 assert.equal(contextAttrs[expectedAttr], expectedValue);223 }224 });225 test('context_attrs_include_custom_catalogue_id_property_of_data_point_image', function () {226 var type = 'image',227 data = require('./sample_data_point_' + type + '.json'),228 valueMeta = data.metric['value_meta'],229 expectedAttr = metricsMappingNGSI['nid'],230 expectedValue = valueMeta['properties'].replace(/.*"nid":.*"(\w+)".*/, '$1'),231 reqdomain = {232 body: JSON.stringify(data)233 };234 var entityData = parser.parseRequest(reqdomain),235 contextAttrs = parser.getContextAttrs(entityData);236 assert(contextAttrs[expectedAttr]);237 assert.equal(contextAttrs[expectedAttr], expectedValue);238 });239 test('context_attrs_ignore_other_custom_value_meta_property_of_data_point_image', function () {240 var type = 'image',241 data = require('./sample_data_point_' + type + '.json'),242 valueMeta = data.metric['value_meta'],243 attrMeta = 'custom';244 valueMeta['properties'] = util.format('{"%s": "value"}', attrMeta);245 var reqdomain = {246 body: JSON.stringify(data)247 };248 var entityData = parser.parseRequest(reqdomain),249 contextAttrs = parser.getContextAttrs(entityData);250 assert.equal(contextAttrs[attrMeta], undefined);251 });252 test('context_attrs_ignore_invalid_json_in_value_meta_properties_of_data_point_image', function () {253 var type = 'image',254 data = require('./sample_data_point_' + type + '.json'),255 valueMeta = data.metric['value_meta'],256 attrMeta = metricsMappingNGSI['nid'];257 valueMeta['properties'] = '{invalid json, "nid": 123}';258 var reqdomain = {259 body: JSON.stringify(data)260 };261 var entityData = parser.parseRequest(reqdomain),262 contextAttrs = parser.getContextAttrs(entityData);263 assert.equal(contextAttrs[attrMeta], undefined);264 });265 test('parse_gets_valid_entity_type_of_data_point_host', function () {266 var type = 'host',267 data = require('./sample_data_point_' + type + '.json'),268 reqdomain = {269 body: JSON.stringify(data)270 };271 parser.parseRequest(reqdomain);272 assert.equal(reqdomain.entityType, type);273 });274 test('parse_gets_valid_entity_id_of_data_point_host', function () {275 var type = 'host',276 data = require('./sample_data_point_' + type + '.json'),277 region = this.sampleMetricRegion,278 resource = data.metric.dimensions['resource_id'], /* resource == host_nodename (usually same values) */279 host = resource.split('_')[0],280 expectedId = util.format('%s:%s', region, host),281 reqdomain = {282 body: JSON.stringify(data)283 };284 parser.parseRequest(reqdomain);285 assert.equal(reqdomain.entityId, expectedId);286 });287 test('parse_gets_valid_entity_id_with_host_and_nodename_of_data_point_host', function () {288 var type = 'host',289 data = require('./sample_data_point_' + type + '.json'),290 region = this.sampleMetricRegion,291 host = 'myhost',292 nodename = 'mynodename';293 data.metric.dimensions['resource_id'] = util.format('%s_%s', host, nodename);294 var expectedId = util.format('%s:%s_%s', region, host, nodename),295 reqdomain = {296 body: JSON.stringify(data)297 };298 parser.parseRequest(reqdomain);299 assert.equal(reqdomain.entityId, expectedId);300 });301 test('context_attrs_include_standard_metrics_of_data_point_host', function () {302 var type = 'host',303 data = require('./sample_data_point_' + type + '.json'),304 metrics = [305 'compute.node.cpu.percent',306 'compute.node.cpu.now',307 'compute.node.cpu.max',308 'compute.node.cpu.tot',309 'compute.node.ram.now',310 'compute.node.ram.max',311 'compute.node.ram.tot',312 'compute.node.disk.now',313 'compute.node.disk.max',314 'compute.node.disk.tot'315 ];316 for (var i in metrics) {317 data.metric.name = metrics[i];318 var metricName = metrics[i],319 expectedAttr = metricsMappingNGSI[metricName],320 expectedValue = data.metric.value,321 reqdomain = {322 body: JSON.stringify(data)323 };324 var entityData = parser.parseRequest(reqdomain),325 contextAttrs = parser.getContextAttrs(entityData);326 assert(contextAttrs[expectedAttr]);327 assert.equal(contextAttrs[expectedAttr], expectedValue);328 }329 });330 test('parse_gets_valid_entity_type_of_data_point_instance', function () {331 var type = 'vm',332 metric = 'instance',333 data = require('./sample_data_point_' + type + '_' + metric.replace('.', '_') + '.json'),334 reqdomain = {335 body: JSON.stringify(data)336 };337 parser.parseRequest(reqdomain);338 assert.equal(reqdomain.entityType, type);339 });340 test('parse_gets_valid_entity_id_of_data_point_instance', function () {341 var type = 'vm',342 metric = 'instance',343 data = require('./sample_data_point_' + type + '_' + metric.replace('.', '_') + '.json'),344 region = this.sampleMetricRegion,345 resource = data.metric.dimensions['resource_id'],346 expectedIdPattern = util.format('%s:%s', region, resource),347 reqdomain = {348 body: JSON.stringify(data)349 };350 parser.parseRequest(reqdomain);351 assert(reqdomain.entityId.match(new RegExp(expectedIdPattern)));352 });353 test('context_attrs_include_standard_dimensions_of_data_point_instance', function () {354 var type = 'vm',355 metric = 'instance',356 data = require('./sample_data_point_' + type + '_' + metric.replace('.', '_') + '.json'),357 dimensions = data.metric.dimensions,358 metrics = ['user_id', 'project_id'],359 reqdomain = {360 body: JSON.stringify(data)361 };362 var entityData = parser.parseRequest(reqdomain),363 contextAttrs = parser.getContextAttrs(entityData);364 for (var i in metrics) {365 var metricName = metrics[i],366 expectedAttr = metricsMappingNGSI[metricName] || metricName,367 expectedValue = dimensions[metricName];368 assert(contextAttrs[expectedAttr]);369 assert.equal(contextAttrs[expectedAttr], expectedValue);370 }371 });372 test('context_attrs_include_standard_metadata_of_data_point_instance', function () {373 var type = 'vm',374 metric = 'instance',375 data = require('./sample_data_point_' + type + '_' + metric.replace('.', '_') + '.json'),376 valueMeta = data.metric['value_meta'],377 itemsMeta = ['name', 'host', 'status', 'instance_type', 'image_ref'],378 reqdomain = {379 body: JSON.stringify(data)380 };381 var entityData = parser.parseRequest(reqdomain),382 contextAttrs = parser.getContextAttrs(entityData);383 for (var i in itemsMeta) {384 var metricName = itemsMeta[i],385 expectedAttr = metricsMappingNGSI[metricName] || metricName,386 expectedValue = valueMeta[metricName];387 assert(contextAttrs[expectedAttr]);388 assert.equal(contextAttrs[expectedAttr], expectedValue);389 }390 });391 test('context_attrs_include_custom_catalogue_id_of_data_point_instance', function () {392 var type = 'vm',393 metric = 'instance',394 data = require('./sample_data_point_' + type + '_' + metric.replace('.', '_') + '.json'),395 valueMeta = data.metric['value_meta'],396 expectedAttr = metricsMappingNGSI['nid'],397 expectedValue = valueMeta['properties'].replace(/.*"nid":.*"(\w+)".*/, '$1'),398 reqdomain = {399 body: JSON.stringify(data)400 };401 var entityData = parser.parseRequest(reqdomain),402 contextAttrs = parser.getContextAttrs(entityData);403 assert(contextAttrs[expectedAttr]);404 assert.equal(contextAttrs[expectedAttr], expectedValue);405 });406 test('context_attrs_ignore_other_custom_value_meta_property_of_data_point_instance', function () {407 var type = 'vm',408 metric = 'instance',409 data = require('./sample_data_point_' + type + '_' + metric.replace('.', '_') + '.json'),410 valueMeta = data.metric['value_meta'],411 attrMeta = 'custom';412 valueMeta['properties'] = util.format('{"%s": "value"}', attrMeta);413 var reqdomain = {414 body: JSON.stringify(data)415 };416 var entityData = parser.parseRequest(reqdomain),417 contextAttrs = parser.getContextAttrs(entityData);418 assert.equal(contextAttrs[attrMeta], undefined);419 });420 test('parse_gets_valid_entity_type_of_data_point_memory', function () {421 var type = 'vm',422 metric = 'memory',423 data = require('./sample_data_point_' + type + '_' + metric.replace('.', '_') + '.json'),424 reqdomain = {425 body: JSON.stringify(data)426 };427 parser.parseRequest(reqdomain);428 assert.equal(reqdomain.entityType, type);429 });430 test('parse_gets_valid_entity_id_of_data_point_memory', function () {431 var type = 'vm',432 metric = 'memory',433 data = require('./sample_data_point_' + type + '_' + metric.replace('.', '_') + '.json'),434 region = this.sampleMetricRegion,435 resource = data.metric.dimensions['resource_id'],436 expectedIdPattern = util.format('%s:%s', region, resource),437 reqdomain = {438 body: JSON.stringify(data)439 };440 parser.parseRequest(reqdomain);441 assert(reqdomain.entityId.match(new RegExp(expectedIdPattern)));442 });443 test('context_attr_is_single_value_of_data_point_memory', function () {444 var type = 'vm',445 metric = 'memory',446 data = require('./sample_data_point_' + type + '_' + metric.replace('.', '_') + '.json'),447 expectedAttr = metricsMappingNGSI[metric],448 expectedValue = data.metric.value,449 reqdomain = {450 body: JSON.stringify(data)451 };452 var entityData = parser.parseRequest(reqdomain),453 contextAttrs = parser.getContextAttrs(entityData);454 assert(contextAttrs[expectedAttr]);455 assert.equal(contextAttrs[expectedAttr], expectedValue);456 assert.equal(Object.keys(contextAttrs).length, 1);457 });458 test('parse_gets_valid_entity_type_of_data_point_memory_usage', function () {459 var type = 'vm',460 metric = 'memory.usage',461 data = require('./sample_data_point_' + type + '_' + metric.replace('.', '_') + '.json'),462 reqdomain = {463 body: JSON.stringify(data)464 };465 parser.parseRequest(reqdomain);466 assert.equal(reqdomain.entityType, type);467 });468 test('parse_gets_valid_entity_id_of_data_point_memory_usage', function () {469 var type = 'vm',470 metric = 'memory.usage',471 data = require('./sample_data_point_' + type + '_' + metric.replace('.', '_') + '.json'),472 region = this.sampleMetricRegion,473 resource = data.metric.dimensions['resource_id'],474 expectedIdPattern = util.format('%s:%s', region, resource),475 reqdomain = {476 body: JSON.stringify(data)477 };478 parser.parseRequest(reqdomain);479 assert(reqdomain.entityId.match(new RegExp(expectedIdPattern)));480 });481 test('context_attr_is_single_value_of_data_point_memory_usage', function () {482 var type = 'vm',483 metric = 'memory.usage',484 data = require('./sample_data_point_' + type + '_' + metric.replace('.', '_') + '.json'),485 expectedAttr = metricsMappingNGSI[metric],486 expectedValue = data.metric.value,487 reqdomain = {488 body: JSON.stringify(data)489 };490 var entityData = parser.parseRequest(reqdomain),491 contextAttrs = parser.getContextAttrs(entityData);492 assert(contextAttrs[expectedAttr]);493 assert.equal(contextAttrs[expectedAttr], expectedValue);494 assert.equal(Object.keys(contextAttrs).length, 1);495 });496 test('parse_gets_valid_entity_type_of_data_point_disk_capacity', function () {497 var type = 'vm',498 metric = 'disk.capacity',499 data = require('./sample_data_point_' + type + '_' + metric.replace('.', '_') + '.json'),500 reqdomain = {501 body: JSON.stringify(data)502 };503 parser.parseRequest(reqdomain);504 assert.equal(reqdomain.entityType, type);505 });506 test('parse_gets_valid_entity_id_of_data_point_disk_capacity', function () {507 var type = 'vm',508 metric = 'disk.capacity',509 data = require('./sample_data_point_' + type + '_' + metric.replace('.', '_') + '.json'),510 region = this.sampleMetricRegion,511 resource = data.metric.dimensions['resource_id'],512 expectedIdPattern = util.format('%s:%s', region, resource),513 reqdomain = {514 body: JSON.stringify(data)515 };516 parser.parseRequest(reqdomain);517 assert(reqdomain.entityId.match(new RegExp(expectedIdPattern)));518 });519 test('context_attr_is_single_value_of_data_point_disk_capacity', function () {520 var type = 'vm',521 metric = 'disk.capacity',522 data = require('./sample_data_point_' + type + '_' + metric.replace('.', '_') + '.json'),523 expectedAttr = metricsMappingNGSI[metric],524 expectedValue = data.metric.value,525 reqdomain = {526 body: JSON.stringify(data)527 };528 var entityData = parser.parseRequest(reqdomain),529 contextAttrs = parser.getContextAttrs(entityData);530 assert(contextAttrs[expectedAttr]);531 assert.equal(contextAttrs[expectedAttr], expectedValue);532 assert.equal(Object.keys(contextAttrs).length, 1);533 });534 test('parse_gets_valid_entity_type_of_data_point_disk_usage', function () {535 var type = 'vm',536 metric = 'disk.usage',537 data = require('./sample_data_point_' + type + '_' + metric.replace('.', '_') + '.json'),538 reqdomain = {539 body: JSON.stringify(data)540 };541 parser.parseRequest(reqdomain);542 assert.equal(reqdomain.entityType, type);543 });544 test('parse_gets_valid_entity_id_of_data_point_disk_usage', function () {545 var type = 'vm',546 metric = 'disk.usage',547 data = require('./sample_data_point_' + type + '_' + metric.replace('.', '_') + '.json'),548 region = this.sampleMetricRegion,549 resource = data.metric.dimensions['resource_id'],550 expectedIdPattern = util.format('%s:%s', region, resource),551 reqdomain = {552 body: JSON.stringify(data)553 };554 parser.parseRequest(reqdomain);555 assert(reqdomain.entityId.match(new RegExp(expectedIdPattern)));556 });557 test('context_attr_is_single_value_of_data_point_disk_usage', function () {558 var type = 'vm',559 metric = 'disk.usage',560 data = require('./sample_data_point_' + type + '_' + metric.replace('.', '_') + '.json'),561 expectedAttr = metricsMappingNGSI[metric],562 expectedValue = data.metric.value,563 reqdomain = {564 body: JSON.stringify(data)565 };566 var entityData = parser.parseRequest(reqdomain),567 contextAttrs = parser.getContextAttrs(entityData);568 assert(contextAttrs[expectedAttr]);569 assert.equal(contextAttrs[expectedAttr], expectedValue);570 assert.equal(Object.keys(contextAttrs).length, 1);571 });572 test('parse_gets_valid_entity_type_of_data_point_memory_util', function () {573 var type = 'vm',574 metric = 'memory_util',575 data = require('./sample_data_point_' + type + '_' + metric.replace('.', '_') + '.json'),576 reqdomain = {577 body: JSON.stringify(data)578 };579 parser.parseRequest(reqdomain);580 assert.equal(reqdomain.entityType, type);581 });582 test('parse_gets_valid_entity_id_of_data_point_memory_util', function () {583 var type = 'vm',584 metric = 'memory_util',585 data = require('./sample_data_point_' + type + '_' + metric.replace('.', '_') + '.json'),586 region = this.sampleMetricRegion,587 resource = data.metric.dimensions['resource_id'],588 expectedIdPattern = util.format('%s:%s', region, resource),589 reqdomain = {590 body: JSON.stringify(data)591 };592 parser.parseRequest(reqdomain);593 assert(reqdomain.entityId.match(new RegExp(expectedIdPattern)));594 });595 test('context_attr_is_single_value_of_data_point_memory_util', function () {596 var type = 'vm',597 metric = 'cpu_util',598 data = require('./sample_data_point_' + type + '_' + metric.replace('.', '_') + '.json'),599 expectedAttr = metricsMappingNGSI[metric] || metric,600 expectedValue = data.metric.value,601 reqdomain = {602 body: JSON.stringify(data)603 };604 var entityData = parser.parseRequest(reqdomain),605 contextAttrs = parser.getContextAttrs(entityData);606 assert(contextAttrs[expectedAttr]);607 assert.equal(contextAttrs[expectedAttr], expectedValue);608 assert.equal(Object.keys(contextAttrs).length, 1);609 });610 test('parse_gets_valid_entity_type_of_data_point_cpu_util', function () {611 var type = 'vm',612 metric = 'cpu_util',613 data = require('./sample_data_point_' + type + '_' + metric.replace('.', '_') + '.json'),614 reqdomain = {615 body: JSON.stringify(data)616 };617 parser.parseRequest(reqdomain);618 assert.equal(reqdomain.entityType, type);619 });620 test('parse_gets_valid_entity_id_of_data_point_cpu_util', function () {621 var type = 'vm',622 metric = 'cpu_util',623 data = require('./sample_data_point_' + type + '_' + metric.replace('.', '_') + '.json'),624 region = this.sampleMetricRegion,625 resource = data.metric.dimensions['resource_id'],626 expectedIdPattern = util.format('%s:%s', region, resource),627 reqdomain = {628 body: JSON.stringify(data)629 };630 parser.parseRequest(reqdomain);631 assert(reqdomain.entityId.match(new RegExp(expectedIdPattern)));632 });633 test('context_attr_is_single_value_of_data_point_cpu_util', function () {634 var type = 'vm',635 metric = 'cpu_util',636 data = require('./sample_data_point_' + type + '_' + metric.replace('.', '_') + '.json'),637 expectedAttr = metricsMappingNGSI[metric] || metric,638 expectedValue = data.metric.value,639 reqdomain = {640 body: JSON.stringify(data)641 };642 var entityData = parser.parseRequest(reqdomain),643 contextAttrs = parser.getContextAttrs(entityData);644 assert(contextAttrs[expectedAttr]);645 assert.equal(contextAttrs[expectedAttr], expectedValue);646 assert.equal(Object.keys(contextAttrs).length, 1);647 });648 test('parse_gets_valid_entity_type_of_data_point_vcpus', function () {649 var type = 'vm',650 metric = 'vcpus',651 data = require('./sample_data_point_' + type + '_' + metric.replace('.', '_') + '.json'),652 reqdomain = {653 body: JSON.stringify(data)654 };655 parser.parseRequest(reqdomain);656 assert.equal(reqdomain.entityType, type);657 });658 test('parse_gets_valid_entity_id_of_data_point_vcpus', function () {659 var type = 'vm',660 metric = 'vcpus',661 data = require('./sample_data_point_' + type + '_' + metric.replace('.', '_') + '.json'),662 region = this.sampleMetricRegion,663 resource = data.metric.dimensions['resource_id'],664 expectedIdPattern = util.format('%s:%s', region, resource),665 reqdomain = {666 body: JSON.stringify(data)667 };668 parser.parseRequest(reqdomain);669 assert(reqdomain.entityId.match(new RegExp(expectedIdPattern)));670 });671 test('context_attr_is_single_value_of_data_point_vcpus', function () {672 var type = 'vm',673 metric = 'vcpus',674 data = require('./sample_data_point_' + type + '_' + metric.replace('.', '_') + '.json'),675 expectedAttr = metricsMappingNGSI[metric] || metric,676 expectedValue = data.metric.value,677 reqdomain = {678 body: JSON.stringify(data)679 };680 var entityData = parser.parseRequest(reqdomain),681 contextAttrs = parser.getContextAttrs(entityData);682 assert(contextAttrs[expectedAttr]);683 assert.equal(contextAttrs[expectedAttr], expectedValue);684 assert.equal(Object.keys(contextAttrs).length, 1);685 });...

Full Screen

Full Screen

test_check_http.js

Source:test_check_http.js Github

copy

Full Screen

1/*2 * Copyright 2016 Telefónica I+D3 * All Rights Reserved.4 *5 * Licensed under the Apache License, Version 2.0 (the "License"); you may6 * not use this file except in compliance with the License. You may obtain7 * a copy of the License at8 *9 * http://www.apache.org/licenses/LICENSE-2.010 *11 * Unless required by applicable law or agreed to in writing, software12 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT13 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the14 * License for the specific language governing permissions and limitations15 * under the License.16 */17/**18 * Module that defines unit tests for the Nagios 'check_http' plugin parser.19 *20 * @module test_check_http21 */22'use strict';23var fs = require('fs'),24 assert = require('assert'),25 parser = require('../../lib/check_http').parser;26suite('parser', function () {27 suiteSetup(function () {28 this.expectedAttr = 'status';29 });30 suiteTeardown(function () {31 });32 setup(function () {33 });34 teardown(function () {35 });36 test('context_attrs_include_status_ok', function () {37 var status = 'OK',38 data = fs.readFileSync('./test/unit/sample_data_check_http_' + status.toLowerCase() + '.txt'),39 expectedValue = status,40 reqdomain = {41 body: data.toString()42 };43 var entityData = parser.parseRequest(reqdomain),44 contextAttrs = parser.getContextAttrs(entityData);45 assert(contextAttrs[this.expectedAttr]);46 assert.equal(contextAttrs[this.expectedAttr], expectedValue);47 });48 test('context_attrs_include_status_ok_2', function () {49 var status = 'OK',50 data = fs.readFileSync('./test/unit/sample_data_check_http_' + status.toLowerCase() + '_2.txt'),51 expectedValue = status,52 reqdomain = {53 body: data.toString()54 };55 var entityData = parser.parseRequest(reqdomain),56 contextAttrs = parser.getContextAttrs(entityData);57 assert(contextAttrs[this.expectedAttr]);58 assert.equal(contextAttrs[this.expectedAttr], expectedValue);59 });60 test('context_attrs_include_status_warning', function () {61 var status = 'WARNING',62 data = fs.readFileSync('./test/unit/sample_data_check_http_' + status.toLowerCase() + '.txt'),63 expectedValue = status,64 reqdomain = {65 body: data.toString()66 };67 var entityData = parser.parseRequest(reqdomain),68 contextAttrs = parser.getContextAttrs(entityData);69 assert(contextAttrs[this.expectedAttr]);70 assert.equal(contextAttrs[this.expectedAttr], expectedValue);71 });72 test('context_attrs_include_status_critical', function () {73 var status = 'CRITICAL',74 data = fs.readFileSync('./test/unit/sample_data_check_http_' + status.toLowerCase() + '.txt'),75 expectedValue = status,76 reqdomain = {77 body: data.toString()78 };79 var entityData = parser.parseRequest(reqdomain),80 contextAttrs = parser.getContextAttrs(entityData);81 assert(contextAttrs[this.expectedAttr]);82 assert.equal(contextAttrs[this.expectedAttr], expectedValue);83 });84 test('context_attrs_include_status_no_route_to_hosts', function () {85 var status = 'CRITICAL',86 data = fs.readFileSync('./test/unit/sample_data_check_http_no_route_to_host.txt'),87 expectedValue = status,88 reqdomain = {89 body: data.toString()90 };91 var entityData = parser.parseRequest(reqdomain),92 contextAttrs = parser.getContextAttrs(entityData);93 assert(contextAttrs[this.expectedAttr]);94 assert.equal(contextAttrs[this.expectedAttr], expectedValue);95 });96 test('context_attrs_include_status_no_route_to_hosts_2', function () {97 var status = 'CRITICAL',98 data = fs.readFileSync('./test/unit/sample_data_check_http_no_route_to_host_2.txt'),99 expectedValue = status,100 reqdomain = {101 body: data.toString()102 };103 var entityData = parser.parseRequest(reqdomain),104 contextAttrs = parser.getContextAttrs(entityData);105 assert(contextAttrs[this.expectedAttr]);106 assert.equal(contextAttrs[this.expectedAttr], expectedValue);107 });...

Full Screen

Full Screen

test_check_tcp.js

Source:test_check_tcp.js Github

copy

Full Screen

1/*2 * Copyright 2017 FIWARE Foundation, e.V.3 * All Rights Reserved.4 *5 * Licensed under the Apache License, Version 2.0 (the "License"); you may6 * not use this file except in compliance with the License. You may obtain7 * a copy of the License at8 *9 * http://www.apache.org/licenses/LICENSE-2.010 *11 * Unless required by applicable law or agreed to in writing, software12 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT13 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the14 * License for the specific language governing permissions and limitations15 * under the License.16 */17/**18 * Module that defines unit tests for the Nagios 'check_tcp' plugin parser.19 *20 * @module test_check_tcp21 */22'use strict';23var fs = require('fs'),24 assert = require('assert'),25 parser = require('../../lib/check_tcp').parser;26suite('parser', function () {27 suiteSetup(function () {28 this.expectedAttr = 'status';29 });30 suiteTeardown(function () {31 });32 setup(function () {33 });34 teardown(function () {35 });36 test('context_attrs_include_status_ok', function () {37 var status = 'OK',38 data = fs.readFileSync('./test/unit/sample_data_check_tcp_' + status.toLowerCase() + '.txt'),39 expectedValue = status,40 reqdomain = {41 body: data.toString()42 };43 var entityData = parser.parseRequest(reqdomain),44 contextAttrs = parser.getContextAttrs(entityData);45 assert(contextAttrs[this.expectedAttr]);46 assert.equal(contextAttrs[this.expectedAttr], expectedValue);47 });48 test('context_attrs_include_status_warning', function () {49 var status = 'WARNING',50 data = fs.readFileSync('./test/unit/sample_data_check_tcp_' + status.toLowerCase() + '.txt'),51 expectedValue = status,52 reqdomain = {53 body: data.toString()54 };55 var entityData = parser.parseRequest(reqdomain),56 contextAttrs = parser.getContextAttrs(entityData);57 assert(contextAttrs[this.expectedAttr]);58 assert.equal(contextAttrs[this.expectedAttr], expectedValue);59 });60 test('context_attrs_include_status_critical', function () {61 var status = 'CRITICAL',62 data = fs.readFileSync('./test/unit/sample_data_check_tcp_' + status.toLowerCase() + '.txt'),63 expectedValue = status,64 reqdomain = {65 body: data.toString()66 };67 var entityData = parser.parseRequest(reqdomain),68 contextAttrs = parser.getContextAttrs(entityData);69 assert(contextAttrs[this.expectedAttr]);70 assert.equal(contextAttrs[this.expectedAttr], expectedValue);71 });72 test('context_attrs_include_status_no_route_to_host', function () {73 var status = 'CRITICAL',74 data = fs.readFileSync('./test/unit/sample_data_check_tcp_no_route_to_host.txt'),75 expectedValue = status,76 reqdomain = {77 body: data.toString()78 };79 var entityData = parser.parseRequest(reqdomain),80 contextAttrs = parser.getContextAttrs(entityData);81 assert(contextAttrs[this.expectedAttr]);82 assert.equal(contextAttrs[this.expectedAttr], expectedValue);83 });...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('webpagetest');2var webPageTest = new wpt('API_KEY');3}, function(err, data) {4 console.log(data);5});6I’m happy to inform you that we’ve just released a new version of the library (v2.0.0) which includes a fix for this issue. You can update the library by running the following command:

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptoolkit = require('wptoolkit');2var contextAttrs = wptoolkit.contextAttrs;3var wp = new wptoolkit.WPToolKit();4 if (err) {5 }6 console.log(data);7});8var wptoolkit = require('wptoolkit');9var wp = new wptoolkit.WPToolKit();10 if (err) {11 }12 console.log(data);13});14var wptoolkit = require('wptoolkit');15var wp = new wptoolkit.WPToolKit();16 if (err) {17 }18 console.log(data);19});20var wptoolkit = require('wptoolkit');21var wp = new wptoolkit.WPToolKit();22 if (err) {23 }24 console.log(data);25});26var wptoolkit = require('wptoolkit');27var wp = new wptoolkit.WPToolKit();28 if (err) {29 }30 console.log(data);31});32var wptoolkit = require('wptoolkit');33var wp = new wptoolkit.WPToolKit();34 if (err) {35 }36 console.log(data);37});

Full Screen

Using AI Code Generation

copy

Full Screen

1var table = document.createElement('table');2table.id = 'table';3document.body.appendChild(table);4var thead = document.createElement('thead');5thead.id = 'thead';6table.appendChild(thead);7var tbody = document.createElement('tbody');8tbody.id = 'tbody';9table.appendChild(tbody);10var tr = document.createElement('tr');11tr.id = 'tr';12thead.appendChild(tr);13var th1 = document.createElement('th');14th1.id = 'th1';15th1.innerHTML = 'Attribute';16tr.appendChild(th1);17var th2 = document.createElement('th');18th2.id = 'th2';19th2.innerHTML = 'Value';20tr.appendChild(th2);21var tr1 = document.createElement('tr');22tr1.id = 'tr1';23tbody.appendChild(tr1);24var td1 = document.createElement('td');25td1.id = 'td1';26td1.innerHTML = 'id';27tr1.appendChild(td1);28var td2 = document.createElement('td');29td2.id = 'td2';30td2.innerHTML = wpt.contextAttrs().id;31tr1.appendChild(td2);32var tr2 = document.createElement('tr');33tr2.id = 'tr2';34tbody.appendChild(tr2);35var td3 = document.createElement('td');36td3.id = 'td3';37td3.innerHTML = 'class';38tr2.appendChild(td3);39var td4 = document.createElement('td');40td4.id = 'td4';41td4.innerHTML = wpt.contextAttrs().class;42tr2.appendChild(td4);43var tr3 = document.createElement('tr');44tr3.id = 'tr3';45tbody.appendChild(tr3);46var td5 = document.createElement('td');47td5.id = 'td5';48td5.innerHTML = 'style';49tr3.appendChild(td5);50var td6 = document.createElement('td');51td6.id = 'td6';52td6.innerHTML = wpt.contextAttrs().style;53tr3.appendChild(td6);54var tr4 = document.createElement('tr');55tr4.id = 'tr4';56tbody.appendChild(tr4);57var td7 = document.createElement('td');

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run wpt automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful