UNPKG

nsolid-graphite

Version:

a daemon that sends N|Solid metrics to graphite

28 lines (24 loc) 1.74 kB
'use strict' const test = require('tape') const getParams = require('../params') test('ping', (t) => { t.equal(getParams('ping', {foo: 'bar'}), '', 'Ignore unknown param') t.equal(getParams('ping', {field: ['cpu', 'heapUsed'], start: '-1d', duration: 30}), '', 'Ignore params not valid for this command') t.equal(getParams('ping', {id: 'abc1232'}), 'id=abc1232', 'set id if present') t.equal(getParams('ping', {foo: 'bar', id: 'abc1232'}), 'id=abc1232', 'set valid params and ignore others') t.equal(getParams('ping', {id: 'abc1232', hostname: 'hostA.foo'}), 'id=abc1232&hostname=hostA.foo', 'set multiple filters') t.equal(getParams('ping', {hostname: 'hostA.foo'}), 'hostname=hostA.foo', 'another filter combo') t.equal(getParams('ping', {tag: ['abc', 'def']}), 'tag=abc&tag=def', 'multiple tags') t.end() }) test('metrics', (t) => { t.equal(getParams('metrics', {foo: 'bar'}), '', 'Ignore unknown param') t.equal(getParams('metrics', {asset: 'abcdefg.cpuprofile', duration: 30}), '', 'Ignore params not valid for this command') t.equal(getParams('metrics', {id: 'abc1232'}), 'id=abc1232', 'set id if present') t.equal(getParams('metrics', {foo: 'bar', id: 'abc1232'}), 'id=abc1232', 'set valid params and ignore others') t.equal(getParams('metrics', {id: 'abc1232', hostname: 'hostA.foo'}), 'id=abc1232&hostname=hostA.foo', 'set multiple filters') t.equal(getParams('metrics', {hostname: 'hostA.foo'}), 'hostname=hostA.foo', 'another filter combo') t.equal(getParams('metrics', {tag: ['abc', 'def']}), 'tag=abc&tag=def', 'multiple tags') t.equal(getParams('metrics', {field: ['cpu', 'heapUsed'], start: '-1d', duration: 30}), 'field=cpu&field=heapUsed&start=-1d', 'additional params') t.end() })