mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
added unit test for influxdb query
This commit is contained in:
parent
59c7edfd90
commit
f69dcf38ef
@ -6,7 +6,6 @@ define([
|
|||||||
function ControllerTestContext() {
|
function ControllerTestContext() {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
this.timeRange = { from:'now-1h', to: 'now'};
|
|
||||||
this.datasource = {};
|
this.datasource = {};
|
||||||
this.annotationsSrv = {};
|
this.annotationsSrv = {};
|
||||||
this.datasourceSrv = {
|
this.datasourceSrv = {
|
||||||
@ -25,18 +24,7 @@ define([
|
|||||||
return inject(function($controller, $rootScope, $q) {
|
return inject(function($controller, $rootScope, $q) {
|
||||||
self.scope = $rootScope.$new();
|
self.scope = $rootScope.$new();
|
||||||
self.scope.panel = {};
|
self.scope.panel = {};
|
||||||
self.scope.filter = {
|
self.scope.filter = new FilterSrvStub();
|
||||||
timeRange: function(parse) {
|
|
||||||
if (!parse) {
|
|
||||||
return self.timeRange;
|
|
||||||
}
|
|
||||||
return {
|
|
||||||
from : kbn.parseDate(self.timeRange.from),
|
|
||||||
to : kbn.parseDate(self.timeRange.to)
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
$rootScope.colors = [];
|
$rootScope.colors = [];
|
||||||
for (var i = 0; i < 50; i++) { $rootScope.colors.push('#' + i); }
|
for (var i = 0; i < 50; i++) { $rootScope.colors.push('#' + i); }
|
||||||
|
|
||||||
@ -50,9 +38,42 @@ define([
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function ServiceTestContext() {
|
||||||
|
var self = this;
|
||||||
|
|
||||||
|
this.createService = function(name) {
|
||||||
|
return inject([name, '$q', '$rootScope', '$httpBackend', function(InfluxDatasource, $q, $rootScope, $httpBackend) {
|
||||||
|
self.service = InfluxDatasource;
|
||||||
|
self.$q = $q;
|
||||||
|
self.$rootScope = $rootScope;
|
||||||
|
self.filterSrv = new FilterSrvStub();
|
||||||
|
self.$httpBackend = $httpBackend;
|
||||||
|
}]);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
function FilterSrvStub() {
|
||||||
|
this.time = { from:'now-1h', to: 'now'};
|
||||||
|
this.timeRange = function(parse) {
|
||||||
|
if (!parse) {
|
||||||
|
return this.time;
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
from : kbn.parseDate(this.time.from),
|
||||||
|
to : kbn.parseDate(this.time.to)
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
this.applyTemplateToTarget = function(target) {
|
||||||
|
return target;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
ControllerTestContext: ControllerTestContext
|
ControllerTestContext: ControllerTestContext,
|
||||||
|
FilterSrvStub: FilterSrvStub,
|
||||||
|
ServiceTestContext: ServiceTestContext
|
||||||
};
|
};
|
||||||
|
|
||||||
});
|
});
|
||||||
|
49
src/test/specs/influxdb-datasource-specs.js
Normal file
49
src/test/specs/influxdb-datasource-specs.js
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
define([
|
||||||
|
'./helpers',
|
||||||
|
'services/influxdb/influxdbDatasource'
|
||||||
|
], function(helpers) {
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
describe('InfluxDatasource', function() {
|
||||||
|
var ctx = new helpers.ServiceTestContext();
|
||||||
|
|
||||||
|
beforeEach(module('grafana.services'));
|
||||||
|
beforeEach(ctx.createService('InfluxDatasource'));
|
||||||
|
|
||||||
|
describe('query with 2 targets', function() {
|
||||||
|
var results;
|
||||||
|
var urlExpected = "/series?p=mupp&q=select++mean(value)+from+%22test%22"+
|
||||||
|
"+where++time+%3E+now()+-+1h+++++group+by+time()++order+asc&time_precision=s";
|
||||||
|
var query = {
|
||||||
|
range: { from: 'now-1h', to: 'now' },
|
||||||
|
targets: [{ series: 'test', column: 'value', function: 'mean' }]
|
||||||
|
};
|
||||||
|
|
||||||
|
var response = [{
|
||||||
|
columns: ["time", "sequence_nr", "value"],
|
||||||
|
name: 'test',
|
||||||
|
points: [[10, 1, 1]],
|
||||||
|
}];
|
||||||
|
|
||||||
|
beforeEach(function() {
|
||||||
|
var ds = new ctx.service({ urls: [''], user: 'test', password: 'mupp' });
|
||||||
|
|
||||||
|
ctx.$httpBackend.expect('GET', urlExpected).respond(response);
|
||||||
|
ds.query(ctx.filterSrv, query).then(function(data) { results = data; });
|
||||||
|
ctx.$httpBackend.flush();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should generate the correct query', function() {
|
||||||
|
ctx.$httpBackend.verifyNoOutstandingExpectation();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return series list', function() {
|
||||||
|
expect(results.data.length).to.be(1);
|
||||||
|
expect(results.data[0].target).to.be('test.value');
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
@ -118,6 +118,7 @@ require([
|
|||||||
'specs/parser-specs',
|
'specs/parser-specs',
|
||||||
'specs/gfunc-specs',
|
'specs/gfunc-specs',
|
||||||
'specs/graphiteTargetCtrl-specs',
|
'specs/graphiteTargetCtrl-specs',
|
||||||
|
'specs/influxdb-datasource-specs',
|
||||||
'specs/graph-ctrl-specs',
|
'specs/graph-ctrl-specs',
|
||||||
'specs/filterSrv-specs',
|
'specs/filterSrv-specs',
|
||||||
'specs/kbn-format-specs',
|
'specs/kbn-format-specs',
|
||||||
|
2380
src/vendor/angular/angular-dragdrop.js
vendored
2380
src/vendor/angular/angular-dragdrop.js
vendored
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user