mirror of
https://github.com/grafana/grafana.git
synced 2024-11-25 10:20:29 -06:00
graphite: adds tests for tags and tag_values functions
This commit is contained in:
parent
cfef609c32
commit
5b968329a0
@ -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);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user