Commit 5b968329 by Daniel Lee

graphite: adds tests for tags and tag_values functions

parent cfef609c
......@@ -320,7 +320,7 @@ export function GraphiteDatasource(instanceSettings, $q, backendSrv, templateSrv
method: 'GET',
url: '/tags/autoComplete/tags',
params: {
expr: _.map(expressions, expression => templateSrv.replace(expression)),
expr: _.map(expressions, expression => templateSrv.replace((expression || '').trim())),
},
// for cancellations
requestId: options.requestId,
......@@ -355,8 +355,8 @@ export function GraphiteDatasource(instanceSettings, $q, backendSrv, templateSrv
method: 'GET',
url: '/tags/autoComplete/values',
params: {
expr: _.map(expressions, expression => templateSrv.replace(expression)),
tag: templateSrv.replace(tag),
expr: _.map(expressions, expression => templateSrv.replace((expression || '').trim())),
tag: templateSrv.replace((tag || '').trim()),
},
// for cancellations
requestId: options.requestId,
......
......@@ -222,4 +222,99 @@ describe('graphiteDatasource', function() {
expect(results.length).to.be(2);
});
});
describe('querying for template variables', () => {
let results;
let requestOptions;
beforeEach(() => {
ctx.backendSrv.datasourceRequest = function(options) {
requestOptions = options;
return ctx.$q.when({
data: [{ target: 'prod1.count', datapoints: [[10, 1], [12, 1]] }],
});
};
});
it('should generate tags query', () => {
ctx.ds.metricFindQuery('tags()').then(data => {
results = data;
});
ctx.$rootScope.$apply();
expect(requestOptions.url).to.be('/tags/autoComplete/tags');
expect(requestOptions.params.expr).to.eql([]);
expect(results).not.to.be(null);
});
it('should generate tags query with a filter expression', () => {
ctx.ds.metricFindQuery('tags(server=backend_01)').then(data => {
results = data;
});
ctx.$rootScope.$apply();
expect(requestOptions.url).to.be('/tags/autoComplete/tags');
expect(requestOptions.params.expr).to.eql(['server=backend_01']);
expect(results).not.to.be(null);
});
it('should generate tag query for an expression with whitespace after', () => {
ctx.ds.metricFindQuery('tags(server=backend_01 )').then(data => {
results = data;
});
ctx.$rootScope.$apply();
expect(requestOptions.url).to.be('/tags/autoComplete/tags');
expect(requestOptions.params.expr).to.eql(['server=backend_01']);
expect(results).not.to.be(null);
});
it('should generate tag values query for one tag', () => {
ctx.ds.metricFindQuery('tag_values(server)').then(data => {
results = data;
});
ctx.$rootScope.$apply();
expect(requestOptions.url).to.be('/tags/autoComplete/values');
expect(requestOptions.params.tag).to.be('server');
expect(requestOptions.params.expr).to.eql([]);
expect(results).not.to.be(null);
});
it('should generate tag values query for a tag and expression', () => {
ctx.ds.metricFindQuery('tag_values(server,server=~backend*)').then(data => {
results = data;
});
ctx.$rootScope.$apply();
expect(requestOptions.url).to.be('/tags/autoComplete/values');
expect(requestOptions.params.tag).to.be('server');
expect(requestOptions.params.expr).to.eql(['server=~backend*']);
expect(results).not.to.be(null);
});
it('should generate tag values query for a tag with whitespace after', () => {
ctx.ds.metricFindQuery('tag_values(server )').then(data => {
results = data;
});
ctx.$rootScope.$apply();
expect(requestOptions.url).to.be('/tags/autoComplete/values');
expect(requestOptions.params.tag).to.be('server');
expect(requestOptions.params.expr).to.eql([]);
expect(results).not.to.be(null);
});
it('should generate tag values query for a tag and expression with whitespace after', () => {
ctx.ds.metricFindQuery('tag_values(server , server=~backend* )').then(data => {
results = data;
});
ctx.$rootScope.$apply();
expect(requestOptions.url).to.be('/tags/autoComplete/values');
expect(requestOptions.params.tag).to.be('server');
expect(requestOptions.params.expr).to.eql(['server=~backend*']);
expect(results).not.to.be(null);
});
});
});
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment