|
@@ -1,9 +1,7 @@
|
|
|
define([
|
|
define([
|
|
|
'./helpers',
|
|
'./helpers',
|
|
|
'moment',
|
|
'moment',
|
|
|
- 'app/plugins/datasource/prometheus/datasource',
|
|
|
|
|
- 'app/services/backendSrv',
|
|
|
|
|
- 'app/services/alertSrv'
|
|
|
|
|
|
|
+ 'app/plugins/datasource/prometheus/datasource'
|
|
|
], function(helpers, moment) {
|
|
], function(helpers, moment) {
|
|
|
'use strict';
|
|
'use strict';
|
|
|
|
|
|
|
@@ -11,7 +9,6 @@ define([
|
|
|
var ctx = new helpers.ServiceTestContext();
|
|
var ctx = new helpers.ServiceTestContext();
|
|
|
|
|
|
|
|
beforeEach(module('grafana.services'));
|
|
beforeEach(module('grafana.services'));
|
|
|
- beforeEach(ctx.providePhase(['templateSrv']));
|
|
|
|
|
beforeEach(ctx.createService('PrometheusDatasource'));
|
|
beforeEach(ctx.createService('PrometheusDatasource'));
|
|
|
beforeEach(function() {
|
|
beforeEach(function() {
|
|
|
ctx.ds = new ctx.service({ url: '', user: 'test', password: 'mupp' });
|
|
ctx.ds = new ctx.service({ url: '', user: 'test', password: 'mupp' });
|
|
@@ -56,6 +53,54 @@ define([
|
|
|
|
|
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
|
|
+ describe('When performing metricFindQuery', function() {
|
|
|
|
|
+ var results;
|
|
|
|
|
+ var response;
|
|
|
|
|
+
|
|
|
|
|
+ it('label_values(resource) should generate label search query', function() {
|
|
|
|
|
+ response = {
|
|
|
|
|
+ status: "success",
|
|
|
|
|
+ data: ["value1", "value2", "value3"]
|
|
|
|
|
+ };
|
|
|
|
|
+ ctx.$httpBackend.expect('GET', '/api/v1/label/resource/values').respond(response);
|
|
|
|
|
+ ctx.ds.metricFindQuery('label_values(resource)').then(function(data) { results = data; });
|
|
|
|
|
+ ctx.$httpBackend.flush();
|
|
|
|
|
+ ctx.$rootScope.$apply();
|
|
|
|
|
+ expect(results.length).to.be(3);
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ it('label_values(metric, resource) should generate count metric query', function() {
|
|
|
|
|
+ response = {
|
|
|
|
|
+ status: "success",
|
|
|
|
|
+ data:{
|
|
|
|
|
+ resultType: "vector",
|
|
|
|
|
+ result:[
|
|
|
|
|
+ {metric:{resource:"value1"},value:[]},
|
|
|
|
|
+ {metric:{resource:"value2"},value:[]},
|
|
|
|
|
+ {metric:{resource:"value3"},value:[]}
|
|
|
|
|
+ ]
|
|
|
|
|
+ }
|
|
|
|
|
+ };
|
|
|
|
|
+ ctx.$httpBackend.expect('GET', /\/api\/v1\/query\?query=count\(metric\)%20by%20\(resource\)&time=.*/).respond(response);
|
|
|
|
|
+ ctx.ds.metricFindQuery('label_values(metric, resource)').then(function(data) { results = data; });
|
|
|
|
|
+ ctx.$httpBackend.flush();
|
|
|
|
|
+ ctx.$rootScope.$apply();
|
|
|
|
|
+ expect(results.length).to.be(3);
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ it('metrics(metric.*) should generate metric name query', function() {
|
|
|
|
|
+ response = {
|
|
|
|
|
+ status: "success",
|
|
|
|
|
+ data:["metric1","metric2","metric3","nomatch"]
|
|
|
|
|
+ };
|
|
|
|
|
+ ctx.$httpBackend.expect('GET', '/api/v1/label/__name__/values').respond(response);
|
|
|
|
|
+ ctx.ds.metricFindQuery('metrics(metric.*)').then(function(data) { results = data; });
|
|
|
|
|
+ ctx.$httpBackend.flush();
|
|
|
|
|
+ ctx.$rootScope.$apply();
|
|
|
|
|
+ expect(results.length).to.be(3);
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ });
|
|
|
});
|
|
});
|
|
|
});
|
|
});
|
|
|
|
|
|