UNPKG

artillery-plugin-datadog

Version:

Datadog output plugin for Artillery

96 lines (83 loc) 2.77 kB
// Generated by CoffeeScript 2.0.1 (function() { var EventEmitter, chai, config, datadog, datadogPlugin, eventEmitter, expect; chai = require('chai'); datadog = require('datadog-metrics'); expect = chai.expect; EventEmitter = require('events'); // Setup datadogPlugin = null; config = { plugins: { datadog: { tags: -'team:sre' } } }; eventEmitter = new EventEmitter; // Force-reload the module before every test so we // can realistically test all the scenarios. beforeEach(function() { var DatadogPlugin, sourceFile; sourceFile = '../src/index.js'; delete require.cache[require.resolve(sourceFile)]; DatadogPlugin = require(sourceFile); return datadogPlugin = new DatadogPlugin(config, eventEmitter); }); describe('#getDatadogConfig', function() { it('should return default config when user did not override anything', function() { return expect(datadogPlugin.getDatadogConfig()).to.deep.equal({ // flushIntervalSeconds: 0 host: '', prefix: 'artillery.' }); }); return it('should use user-defined values from config', function() { datadogPlugin.config = { plugins: { datadog: { host: 'artillery.local', prefix: 'artillery.platoon.' } } }; return expect(datadogPlugin.getDatadogConfig()).to.deep.equal({ host: 'artillery.local', prefix: 'artillery.platoon.' }); }); }); describe('#getTags', function() { return it('should concat user-provided and automatically added tags', function() { datadogPlugin.config = { plugins: { datadog: { tags: ['team:sre'] } }, target: 'https://twitter.com/Stranger_Things' }; return expect(datadogPlugin.getTags()).to.deep.equal(['target:https://twitter.com/Stranger_Things', 'team:sre']); }); }); describe('#getOkPercentage', function() { it('should return 0 when no queries were made', function() { var metrics; metrics = { 'response.2xx': [0, datadog.increment], 'response.3xx': [0, datadog.increment], 'requests.completed': [0, datadog.increment] }; return expect(datadogPlugin.getOkPercentage(metrics)).to.equal(0); }); return it('should return a correct percentage value based on response code counts', function() { var metrics; metrics = { 'response.2xx': [8, datadog.increment], 'response.3xx': [3, datadog.increment], 'requests.completed': [101, datadog.increment] }; return expect(datadogPlugin.getOkPercentage(metrics)).to.be.a('Number').and.to.equal(10.89); }); }); }).call(this);