Skip to content

Commit 2c6ea27

Browse files
committed
Fixed small bug in graphite target controller when having variable for single parameter function
1 parent 5a3db05 commit 2c6ea27

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

src/app/controllers/graphiteTarget.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ function (angular, _, config, gfunc, Parser) {
9090
break;
9191
case 'metric':
9292
if ($scope.segments.length > 0) {
93-
if ($scope.segments[0].length !== 1) {
93+
if (astNode.segments.length !== 1) {
9494
throw { message: 'Multiple metric params not supported, use text editor.' };
9595
}
9696
addFunctionParameter(func, astNode.segments[0].value, index, true);

src/test/specs/graphiteTargetCtrl-specs.js

+19
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,25 @@ define([
9999

100100
});
101101

102+
describe('when initializing a target with single param func using variable', function() {
103+
beforeEach(function() {
104+
ctx.scope.target.target = 'movingAverage(prod.count, $var)';
105+
ctx.scope.datasource.metricFindQuery.returns(ctx.$q.when([]));
106+
ctx.scope.init();
107+
ctx.scope.$digest();
108+
ctx.scope.$parent = { get_data: sinon.spy() };
109+
});
110+
111+
it('should add 2 segments', function() {
112+
expect(ctx.scope.segments.length).to.be(2);
113+
});
114+
115+
it('should add function param', function() {
116+
expect(ctx.scope.functions[0].params.length).to.be(1);
117+
});
118+
119+
});
120+
102121
describe('when initalizing target without metric expression and function with series-ref', function() {
103122
beforeEach(function() {
104123
ctx.scope.target.target = 'asPercent(metric.node.count, #A)';

0 commit comments

Comments
 (0)