2014-01-05 03:17:53 -06:00
|
|
|
define([
|
2014-02-08 09:38:17 -06:00
|
|
|
'services/graphite/gfunc'
|
2014-01-05 03:17:53 -06:00
|
|
|
], function(gfunc) {
|
2014-04-06 03:47:14 -05:00
|
|
|
'use strict';
|
2014-01-05 03:17:53 -06:00
|
|
|
|
2014-01-20 07:31:00 -06:00
|
|
|
describe('when creating func instance from func names', function() {
|
2014-01-05 03:17:53 -06:00
|
|
|
|
|
|
|
it('should return func instance', function() {
|
|
|
|
var func = gfunc.createFuncInstance('sumSeries');
|
|
|
|
expect(func).to.be.ok();
|
|
|
|
expect(func.def.name).to.equal('sumSeries');
|
2014-09-03 01:53:08 -05:00
|
|
|
expect(func.def.params.length).to.equal(5);
|
|
|
|
expect(func.def.defaultParams.length).to.equal(1);
|
2014-01-05 03:17:53 -06:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should return func instance with shortName', function() {
|
|
|
|
var func = gfunc.createFuncInstance('sum');
|
|
|
|
expect(func).to.be.ok();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should return func instance from funcDef', function() {
|
2014-04-06 04:07:22 -05:00
|
|
|
var func = gfunc.createFuncInstance('sum');
|
|
|
|
var func2 = gfunc.createFuncInstance(func.def);
|
|
|
|
expect(func2).to.be.ok();
|
2014-01-05 03:17:53 -06:00
|
|
|
});
|
|
|
|
|
|
|
|
it('func instance should have text representation', function() {
|
|
|
|
var func = gfunc.createFuncInstance('groupByNode');
|
|
|
|
func.params[0] = 5;
|
|
|
|
func.params[1] = 'avg';
|
|
|
|
func.updateText();
|
|
|
|
expect(func.text).to.equal("groupByNode(5, avg)");
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
2014-01-20 07:31:00 -06:00
|
|
|
describe('when rendering func instance', function() {
|
|
|
|
|
|
|
|
it('should handle single metric param', function() {
|
|
|
|
var func = gfunc.createFuncInstance('sumSeries');
|
|
|
|
expect(func.render('hello.metric')).to.equal("sumSeries(hello.metric)");
|
|
|
|
});
|
|
|
|
|
2014-09-03 01:53:08 -05:00
|
|
|
it('should include default params if options enable it', function() {
|
|
|
|
var func = gfunc.createFuncInstance('scaleToSeconds', { withDefaultParams: true });
|
|
|
|
expect(func.render('hello')).to.equal("scaleToSeconds(hello, 1)");
|
|
|
|
});
|
|
|
|
|
2014-01-20 07:31:00 -06:00
|
|
|
it('should handle metric param and int param and string param', function() {
|
|
|
|
var func = gfunc.createFuncInstance('groupByNode');
|
|
|
|
func.params[0] = 5;
|
|
|
|
func.params[1] = 'avg';
|
2014-09-03 01:53:08 -05:00
|
|
|
expect(func.render('hello.metric')).to.equal("groupByNode(hello.metric, 5, 'avg')");
|
2014-01-20 07:31:00 -06:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should handle function with no metric param', function() {
|
|
|
|
var func = gfunc.createFuncInstance('randomWalk');
|
|
|
|
func.params[0] = 'test';
|
|
|
|
expect(func.render(undefined)).to.equal("randomWalk('test')");
|
|
|
|
});
|
|
|
|
|
2014-09-02 05:55:45 -05:00
|
|
|
it('should handle function multiple series params', function() {
|
|
|
|
var func = gfunc.createFuncInstance('asPercent');
|
2014-09-03 01:53:08 -05:00
|
|
|
func.params[0] = '#B';
|
|
|
|
expect(func.render('#A')).to.equal("asPercent(#A, #B)");
|
2014-09-02 05:55:45 -05:00
|
|
|
});
|
|
|
|
|
2014-01-20 07:31:00 -06:00
|
|
|
});
|
|
|
|
|
2014-01-05 03:17:53 -06:00
|
|
|
describe('when requesting function categories', function() {
|
|
|
|
it('should return function categories', function() {
|
|
|
|
var catIndex = gfunc.getCategories();
|
2014-02-07 07:07:24 -06:00
|
|
|
expect(catIndex.Special.length).to.be.greaterThan(8);
|
2014-01-05 03:17:53 -06:00
|
|
|
});
|
2014-03-24 03:57:03 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('when updating func param', function() {
|
|
|
|
it('should update param value and update text representation', function() {
|
2014-09-03 01:53:08 -05:00
|
|
|
var func = gfunc.createFuncInstance('summarize', { withDefaultParams: true });
|
2014-03-24 03:57:03 -05:00
|
|
|
func.updateParam('1h', 0);
|
|
|
|
expect(func.params[0]).to.be('1h');
|
|
|
|
expect(func.text).to.be('summarize(1h, sum)');
|
|
|
|
});
|
|
|
|
|
2014-03-24 06:20:28 -05:00
|
|
|
it('should parse numbers as float', function() {
|
|
|
|
var func = gfunc.createFuncInstance('scale');
|
|
|
|
func.updateParam('0.001', 0);
|
2014-09-05 02:11:50 -05:00
|
|
|
expect(func.params[0]).to.be('0.001');
|
2014-03-24 06:20:28 -05:00
|
|
|
});
|
2014-03-24 03:57:03 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('when updating func param with optional second parameter', function() {
|
|
|
|
it('should update value and text', function() {
|
|
|
|
var func = gfunc.createFuncInstance('aliasByNode');
|
|
|
|
func.updateParam('1', 0);
|
2014-09-05 02:11:50 -05:00
|
|
|
expect(func.params[0]).to.be('1');
|
2014-03-24 03:57:03 -05:00
|
|
|
});
|
2014-01-05 03:17:53 -06:00
|
|
|
|
2014-03-24 03:57:03 -05:00
|
|
|
it('should slit text and put value in second param', function() {
|
|
|
|
var func = gfunc.createFuncInstance('aliasByNode');
|
|
|
|
func.updateParam('4,-5', 0);
|
2014-09-05 02:11:50 -05:00
|
|
|
expect(func.params[0]).to.be('4');
|
|
|
|
expect(func.params[1]).to.be('-5');
|
2014-03-24 03:57:03 -05:00
|
|
|
expect(func.text).to.be('aliasByNode(4, -5)');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should remove second param when empty string is set', function() {
|
|
|
|
var func = gfunc.createFuncInstance('aliasByNode');
|
|
|
|
func.updateParam('4,-5', 0);
|
|
|
|
func.updateParam('', 1);
|
2014-09-05 02:11:50 -05:00
|
|
|
expect(func.params[0]).to.be('4');
|
2014-03-24 03:57:03 -05:00
|
|
|
expect(func.params[1]).to.be(undefined);
|
|
|
|
expect(func.text).to.be('aliasByNode(4)');
|
2014-04-06 03:47:14 -05:00
|
|
|
});
|
2014-01-05 03:17:53 -06:00
|
|
|
});
|
|
|
|
|
|
|
|
});
|
2014-03-24 03:57:03 -05:00
|
|
|
|