|
@@ -1,37 +1,22 @@
|
|
|
define([
|
|
define([
|
|
|
'mocks/dashboard-mock',
|
|
'mocks/dashboard-mock',
|
|
|
- 'lodash',
|
|
|
|
|
|
|
+ './helpers',
|
|
|
'services/templateValuesSrv'
|
|
'services/templateValuesSrv'
|
|
|
-], function(dashboardMock) {
|
|
|
|
|
|
|
+], function(dashboardMock, helpers) {
|
|
|
'use strict';
|
|
'use strict';
|
|
|
|
|
|
|
|
describe('templateValuesSrv', function() {
|
|
describe('templateValuesSrv', function() {
|
|
|
- var _templateValuesSrv;
|
|
|
|
|
- var _dashboard;
|
|
|
|
|
- var _datasourceSrv = {};
|
|
|
|
|
- var _q;
|
|
|
|
|
- var _rootScope;
|
|
|
|
|
|
|
+ var ctx = new helpers.ServiceTestContext();
|
|
|
|
|
|
|
|
beforeEach(module('grafana.services'));
|
|
beforeEach(module('grafana.services'));
|
|
|
- beforeEach(module(function($provide) {
|
|
|
|
|
- $provide.value('datasourceSrv', _datasourceSrv);
|
|
|
|
|
- $provide.value('templateSrv', {
|
|
|
|
|
- updateTemplateData: function() {}
|
|
|
|
|
- });
|
|
|
|
|
- _dashboard = dashboardMock.create();
|
|
|
|
|
- }));
|
|
|
|
|
-
|
|
|
|
|
- beforeEach(inject(function(templateValuesSrv, $rootScope, $q) {
|
|
|
|
|
- _templateValuesSrv = templateValuesSrv;
|
|
|
|
|
- _rootScope = $rootScope;
|
|
|
|
|
- _q = $q;
|
|
|
|
|
- }));
|
|
|
|
|
|
|
+ beforeEach(ctx.providePhase(['datasourceSrv', 'timeSrv', 'templateSrv']));
|
|
|
|
|
+ beforeEach(ctx.createService('templateValuesSrv'));
|
|
|
|
|
|
|
|
describe('update time period variable options', function() {
|
|
describe('update time period variable options', function() {
|
|
|
- var variable = { type: 'time period', query: 'auto,1s,2h,5h,1d', name: 'test' };
|
|
|
|
|
|
|
+ var variable = { type: 'interval', query: 'auto,1s,2h,5h,1d', name: 'test' };
|
|
|
|
|
|
|
|
beforeEach(function() {
|
|
beforeEach(function() {
|
|
|
- _templateValuesSrv.updateOptions(variable);
|
|
|
|
|
|
|
+ ctx.service.updateOptions(variable);
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
it('should update options array', function() {
|
|
it('should update options array', function() {
|
|
@@ -43,179 +28,179 @@ define([
|
|
|
|
|
|
|
|
function describeUpdateVariable(desc, fn) {
|
|
function describeUpdateVariable(desc, fn) {
|
|
|
describe(desc, function() {
|
|
describe(desc, function() {
|
|
|
- var ctx = {};
|
|
|
|
|
- ctx.setup = function(setupFn) {
|
|
|
|
|
- ctx.setupFn = setupFn;
|
|
|
|
|
|
|
+ var scenario = {};
|
|
|
|
|
+ scenario.setup = function(setupFn) {
|
|
|
|
|
+ scenario.setupFn = setupFn;
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
beforeEach(function() {
|
|
beforeEach(function() {
|
|
|
- ctx.setupFn();
|
|
|
|
|
|
|
+ scenario.setupFn();
|
|
|
var ds = {};
|
|
var ds = {};
|
|
|
- ds.metricFindQuery = sinon.stub().returns(_q.when(ctx.queryResult));
|
|
|
|
|
- _datasourceSrv.get = sinon.stub().returns(ds);
|
|
|
|
|
|
|
+ ds.metricFindQuery = sinon.stub().returns(ctx.$q.when(scenario.queryResult));
|
|
|
|
|
+ ctx.datasourceSrv.get = sinon.stub().returns(ds);
|
|
|
|
|
|
|
|
- _templateValuesSrv.updateOptions(ctx.variable);
|
|
|
|
|
- _rootScope.$digest();
|
|
|
|
|
|
|
+ ctx.service.updateOptions(scenario.variable);
|
|
|
|
|
+ ctx.$rootScope.$digest();
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
- fn(ctx);
|
|
|
|
|
|
|
+ fn(scenario);
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- describeUpdateVariable('time period variable ', function(ctx) {
|
|
|
|
|
- ctx.setup(function() {
|
|
|
|
|
- ctx.variable = { type: 'time period', query: 'auto,1s,2h,5h,1d', name: 'test' };
|
|
|
|
|
|
|
+ describeUpdateVariable('time period variable ', function(scenario) {
|
|
|
|
|
+ scenario.setup(function() {
|
|
|
|
|
+ scenario.variable = { type: 'interval', query: 'auto,1s,2h,5h,1d', name: 'test' };
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
it('should update options array', function() {
|
|
it('should update options array', function() {
|
|
|
- expect(ctx.variable.options.length).to.be(5);
|
|
|
|
|
- expect(ctx.variable.options[1].text).to.be('1s');
|
|
|
|
|
- expect(ctx.variable.options[1].value).to.be('1s');
|
|
|
|
|
|
|
+ expect(scenario.variable.options.length).to.be(5);
|
|
|
|
|
+ expect(scenario.variable.options[1].text).to.be('1s');
|
|
|
|
|
+ expect(scenario.variable.options[1].value).to.be('1s');
|
|
|
});
|
|
});
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
- describeUpdateVariable('basic query variable', function(ctx) {
|
|
|
|
|
- ctx.setup(function() {
|
|
|
|
|
- ctx.variable = { type: 'query', query: 'apps.*', name: 'test' };
|
|
|
|
|
- ctx.queryResult = [{text: 'backend1'}, {text: 'backend2'}];
|
|
|
|
|
|
|
+ describeUpdateVariable('basic query variable', function(scenario) {
|
|
|
|
|
+ scenario.setup(function() {
|
|
|
|
|
+ scenario.variable = { type: 'query', query: 'apps.*', name: 'test' };
|
|
|
|
|
+ scenario.queryResult = [{text: 'backend1'}, {text: 'backend2'}];
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
it('should update options array', function() {
|
|
it('should update options array', function() {
|
|
|
- expect(ctx.variable.options.length).to.be(2);
|
|
|
|
|
- expect(ctx.variable.options[0].text).to.be('backend1');
|
|
|
|
|
- expect(ctx.variable.options[0].value).to.be('backend1');
|
|
|
|
|
- expect(ctx.variable.options[1].value).to.be('backend2');
|
|
|
|
|
|
|
+ expect(scenario.variable.options.length).to.be(2);
|
|
|
|
|
+ expect(scenario.variable.options[0].text).to.be('backend1');
|
|
|
|
|
+ expect(scenario.variable.options[0].value).to.be('backend1');
|
|
|
|
|
+ expect(scenario.variable.options[1].value).to.be('backend2');
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
it('should select first option as value', function() {
|
|
it('should select first option as value', function() {
|
|
|
- expect(ctx.variable.current.value).to.be('backend1');
|
|
|
|
|
|
|
+ expect(scenario.variable.current.value).to.be('backend1');
|
|
|
});
|
|
});
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
- describeUpdateVariable('and existing value still exists in options', function(ctx) {
|
|
|
|
|
- ctx.setup(function() {
|
|
|
|
|
- ctx.variable = { type: 'query', query: 'apps.*', name: 'test' };
|
|
|
|
|
- ctx.variable.current = { value: 'backend2'};
|
|
|
|
|
- ctx.queryResult = [{text: 'backend1'}, {text: 'backend2'}];
|
|
|
|
|
|
|
+ describeUpdateVariable('and existing value still exists in options', function(scenario) {
|
|
|
|
|
+ scenario.setup(function() {
|
|
|
|
|
+ scenario.variable = { type: 'query', query: 'apps.*', name: 'test' };
|
|
|
|
|
+ scenario.variable.current = { value: 'backend2'};
|
|
|
|
|
+ scenario.queryResult = [{text: 'backend1'}, {text: 'backend2'}];
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
it('should keep variable value', function() {
|
|
it('should keep variable value', function() {
|
|
|
- expect(ctx.variable.current.value).to.be('backend2');
|
|
|
|
|
|
|
+ expect(scenario.variable.current.value).to.be('backend2');
|
|
|
});
|
|
});
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
- describeUpdateVariable('and regex pattern exists', function(ctx) {
|
|
|
|
|
- ctx.setup(function() {
|
|
|
|
|
- ctx.variable = { type: 'query', query: 'apps.*', name: 'test' };
|
|
|
|
|
- ctx.variable.regex = '/apps.*(backend_[0-9]+)/';
|
|
|
|
|
- ctx.queryResult = [{text: 'apps.backend.backend_01.counters.req'}, {text: 'apps.backend.backend_02.counters.req'}];
|
|
|
|
|
|
|
+ describeUpdateVariable('and regex pattern exists', function(scenario) {
|
|
|
|
|
+ scenario.setup(function() {
|
|
|
|
|
+ scenario.variable = { type: 'query', query: 'apps.*', name: 'test' };
|
|
|
|
|
+ scenario.variable.regex = '/apps.*(backend_[0-9]+)/';
|
|
|
|
|
+ scenario.queryResult = [{text: 'apps.backend.backend_01.counters.req'}, {text: 'apps.backend.backend_02.counters.req'}];
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
it('should extract and use match group', function() {
|
|
it('should extract and use match group', function() {
|
|
|
- expect(ctx.variable.options[0].value).to.be('backend_01');
|
|
|
|
|
|
|
+ expect(scenario.variable.options[0].value).to.be('backend_01');
|
|
|
});
|
|
});
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
- describeUpdateVariable('and regex pattern exists and no match', function(ctx) {
|
|
|
|
|
- ctx.setup(function() {
|
|
|
|
|
- ctx.variable = { type: 'query', query: 'apps.*', name: 'test' };
|
|
|
|
|
- ctx.variable.regex = '/apps.*(backendasd[0-9]+)/';
|
|
|
|
|
- ctx.queryResult = [{text: 'apps.backend.backend_01.counters.req'}, {text: 'apps.backend.backend_02.counters.req'}];
|
|
|
|
|
|
|
+ describeUpdateVariable('and regex pattern exists and no match', function(scenario) {
|
|
|
|
|
+ scenario.setup(function() {
|
|
|
|
|
+ scenario.variable = { type: 'query', query: 'apps.*', name: 'test' };
|
|
|
|
|
+ scenario.variable.regex = '/apps.*(backendasd[0-9]+)/';
|
|
|
|
|
+ scenario.queryResult = [{text: 'apps.backend.backend_01.counters.req'}, {text: 'apps.backend.backend_02.counters.req'}];
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
it('should not add non matching items', function() {
|
|
it('should not add non matching items', function() {
|
|
|
- expect(ctx.variable.options.length).to.be(0);
|
|
|
|
|
|
|
+ expect(scenario.variable.options.length).to.be(0);
|
|
|
});
|
|
});
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
- describeUpdateVariable('regex pattern without slashes', function(ctx) {
|
|
|
|
|
- ctx.setup(function() {
|
|
|
|
|
- ctx.variable = { type: 'query', query: 'apps.*', name: 'test' };
|
|
|
|
|
- ctx.variable.regex = 'backend_01';
|
|
|
|
|
- ctx.queryResult = [{text: 'apps.backend.backend_01.counters.req'}, {text: 'apps.backend.backend_02.counters.req'}];
|
|
|
|
|
|
|
+ describeUpdateVariable('regex pattern without slashes', function(scenario) {
|
|
|
|
|
+ scenario.setup(function() {
|
|
|
|
|
+ scenario.variable = { type: 'query', query: 'apps.*', name: 'test' };
|
|
|
|
|
+ scenario.variable.regex = 'backend_01';
|
|
|
|
|
+ scenario.queryResult = [{text: 'apps.backend.backend_01.counters.req'}, {text: 'apps.backend.backend_02.counters.req'}];
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
it('should return matches options', function() {
|
|
it('should return matches options', function() {
|
|
|
- expect(ctx.variable.options.length).to.be(1);
|
|
|
|
|
|
|
+ expect(scenario.variable.options.length).to.be(1);
|
|
|
});
|
|
});
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
- describeUpdateVariable('regex pattern remove duplicates', function(ctx) {
|
|
|
|
|
- ctx.setup(function() {
|
|
|
|
|
- ctx.variable = { type: 'query', query: 'apps.*', name: 'test' };
|
|
|
|
|
- ctx.variable.regex = 'backend_01';
|
|
|
|
|
- ctx.queryResult = [{text: 'apps.backend.backend_01.counters.req'}, {text: 'apps.backend.backend_01.counters.req'}];
|
|
|
|
|
|
|
+ describeUpdateVariable('regex pattern remove duplicates', function(scenario) {
|
|
|
|
|
+ scenario.setup(function() {
|
|
|
|
|
+ scenario.variable = { type: 'query', query: 'apps.*', name: 'test' };
|
|
|
|
|
+ scenario.variable.regex = 'backend_01';
|
|
|
|
|
+ scenario.queryResult = [{text: 'apps.backend.backend_01.counters.req'}, {text: 'apps.backend.backend_01.counters.req'}];
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
it('should return matches options', function() {
|
|
it('should return matches options', function() {
|
|
|
- expect(ctx.variable.options.length).to.be(1);
|
|
|
|
|
|
|
+ expect(scenario.variable.options.length).to.be(1);
|
|
|
});
|
|
});
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
- describeUpdateVariable('and existing value still exists in options', function(ctx) {
|
|
|
|
|
- ctx.setup(function() {
|
|
|
|
|
- ctx.variable = { type: 'query', query: 'apps.*', name: 'test' };
|
|
|
|
|
- ctx.variable.current = { value: 'backend2'};
|
|
|
|
|
- ctx.queryResult = [{text: 'backend1'}, {text: 'backend2'}];
|
|
|
|
|
|
|
+ describeUpdateVariable('and existing value still exists in options', function(scenario) {
|
|
|
|
|
+ scenario.setup(function() {
|
|
|
|
|
+ scenario.variable = { type: 'query', query: 'apps.*', name: 'test' };
|
|
|
|
|
+ scenario.variable.current = { value: 'backend2'};
|
|
|
|
|
+ scenario.queryResult = [{text: 'backend1'}, {text: 'backend2'}];
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
it('should keep variable value', function() {
|
|
it('should keep variable value', function() {
|
|
|
- expect(ctx.variable.current.value).to.be('backend2');
|
|
|
|
|
|
|
+ expect(scenario.variable.current.value).to.be('backend2');
|
|
|
});
|
|
});
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
- describeUpdateVariable('with include All glob syntax', function(ctx) {
|
|
|
|
|
- ctx.setup(function() {
|
|
|
|
|
- ctx.variable = { type: 'query', query: 'apps.*', name: 'test', includeAll: true, allFormat: 'glob' };
|
|
|
|
|
- ctx.queryResult = [{text: 'backend1'}, {text: 'backend2'}, { text: 'backend3'}];
|
|
|
|
|
|
|
+ describeUpdateVariable('with include All glob syntax', function(scenario) {
|
|
|
|
|
+ scenario.setup(function() {
|
|
|
|
|
+ scenario.variable = { type: 'query', query: 'apps.*', name: 'test', includeAll: true, allFormat: 'glob' };
|
|
|
|
|
+ scenario.queryResult = [{text: 'backend1'}, {text: 'backend2'}, { text: 'backend3'}];
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
it('should add All Glob option', function() {
|
|
it('should add All Glob option', function() {
|
|
|
- expect(ctx.variable.options[0].value).to.be('{backend1,backend2,backend3}');
|
|
|
|
|
|
|
+ expect(scenario.variable.options[0].value).to.be('{backend1,backend2,backend3}');
|
|
|
});
|
|
});
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
- describeUpdateVariable('with include all wildcard', function(ctx) {
|
|
|
|
|
- ctx.setup(function() {
|
|
|
|
|
- ctx.variable = { type: 'query', query: 'apps.*', name: 'test', includeAll: true, allFormat: 'wildcard' };
|
|
|
|
|
- ctx.queryResult = [{text: 'backend1'}, {text: 'backend2'}, { text: 'backend3'}];
|
|
|
|
|
|
|
+ describeUpdateVariable('with include all wildcard', function(scenario) {
|
|
|
|
|
+ scenario.setup(function() {
|
|
|
|
|
+ scenario.variable = { type: 'query', query: 'apps.*', name: 'test', includeAll: true, allFormat: 'wildcard' };
|
|
|
|
|
+ scenario.queryResult = [{text: 'backend1'}, {text: 'backend2'}, { text: 'backend3'}];
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
it('should add All wildcard option', function() {
|
|
it('should add All wildcard option', function() {
|
|
|
- expect(ctx.variable.options[0].value).to.be('*');
|
|
|
|
|
|
|
+ expect(scenario.variable.options[0].value).to.be('*');
|
|
|
});
|
|
});
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
- describeUpdateVariable('with include all wildcard', function(ctx) {
|
|
|
|
|
- ctx.setup(function() {
|
|
|
|
|
- ctx.variable = { type: 'query', query: 'apps.*', name: 'test', includeAll: true, allFormat: 'regex wildcard' };
|
|
|
|
|
- ctx.queryResult = [{text: 'backend1'}, {text: 'backend2'}, { text: 'backend3'}];
|
|
|
|
|
|
|
+ describeUpdateVariable('with include all wildcard', function(scenario) {
|
|
|
|
|
+ scenario.setup(function() {
|
|
|
|
|
+ scenario.variable = { type: 'query', query: 'apps.*', name: 'test', includeAll: true, allFormat: 'regex wildcard' };
|
|
|
|
|
+ scenario.queryResult = [{text: 'backend1'}, {text: 'backend2'}, { text: 'backend3'}];
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
it('should add All wildcard option', function() {
|
|
it('should add All wildcard option', function() {
|
|
|
- expect(ctx.variable.options[0].value).to.be('.*');
|
|
|
|
|
|
|
+ expect(scenario.variable.options[0].value).to.be('.*');
|
|
|
});
|
|
});
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
- describeUpdateVariable('with include all regex values', function(ctx) {
|
|
|
|
|
- ctx.setup(function() {
|
|
|
|
|
- ctx.variable = { type: 'query', query: 'apps.*', name: 'test', includeAll: true, allFormat: 'wildcard' };
|
|
|
|
|
- ctx.queryResult = [{text: 'backend1'}, {text: 'backend2'}, { text: 'backend3'}];
|
|
|
|
|
|
|
+ describeUpdateVariable('with include all regex values', function(scenario) {
|
|
|
|
|
+ scenario.setup(function() {
|
|
|
|
|
+ scenario.variable = { type: 'query', query: 'apps.*', name: 'test', includeAll: true, allFormat: 'wildcard' };
|
|
|
|
|
+ scenario.queryResult = [{text: 'backend1'}, {text: 'backend2'}, { text: 'backend3'}];
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
it('should add All wildcard option', function() {
|
|
it('should add All wildcard option', function() {
|
|
|
- expect(ctx.variable.options[0].value).to.be('*');
|
|
|
|
|
|
|
+ expect(scenario.variable.options[0].value).to.be('*');
|
|
|
});
|
|
});
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
- describeUpdateVariable('with include all glob no values', function(ctx) {
|
|
|
|
|
- ctx.setup(function() {
|
|
|
|
|
- ctx.variable = { type: 'query', query: 'apps.*', name: 'test', includeAll: true, allFormat: 'glob' };
|
|
|
|
|
- ctx.queryResult = [];
|
|
|
|
|
|
|
+ describeUpdateVariable('with include all glob no values', function(scenario) {
|
|
|
|
|
+ scenario.setup(function() {
|
|
|
|
|
+ scenario.variable = { type: 'query', query: 'apps.*', name: 'test', includeAll: true, allFormat: 'glob' };
|
|
|
|
|
+ scenario.queryResult = [];
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
it('should add empty glob', function() {
|
|
it('should add empty glob', function() {
|
|
|
- expect(ctx.variable.options[0].value).to.be('{}');
|
|
|
|
|
|
|
+ expect(scenario.variable.options[0].value).to.be('{}');
|
|
|
});
|
|
});
|
|
|
});
|
|
});
|
|
|
|
|
|