Commit dbc07827 by Masaori Koshiba

Add a basic test of KairosDBDatasource

parent 05c27d83
define([
'helpers',
'plugins/datasource/kairosdb/datasource'
], function(helpers) {
'use strict';
describe('KairosDBDatasource', function() {
var ctx = new helpers.ServiceTestContext();
beforeEach(module('grafana.services'));
beforeEach(ctx.providePhase(['templateSrv']));
beforeEach(ctx.createService('KairosDBDatasource'));
beforeEach(function() {
ctx.ds = new ctx.service({ url: ''});
});
describe('When querying kairosdb with one target using query editor target spec', function() {
var results;
var urlExpected = "/api/v1/datapoints/query";
var bodyExpected = {
metrics: [{ name: "test" }],
cache_time: 0,
start_relative: {
value: "1",
unit: "hours"
}
};
var query = {
range: { from: 'now-1h', to: 'now' },
targets: [{ metric: 'test', downsampling: '(NONE)'}]
};
var response = {
queries: [{
sample_size: 60,
results: [{
name: "test",
values: [[1420070400000, 1]]
}]
}]
};
beforeEach(function() {
ctx.$httpBackend.expect('POST', urlExpected, bodyExpected).respond(response);
ctx.ds.query(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');
});
});
});
});
...@@ -128,6 +128,7 @@ require([ ...@@ -128,6 +128,7 @@ require([
'specs/influxQueryBuilder-specs', 'specs/influxQueryBuilder-specs',
'specs/influx09-querybuilder-specs', 'specs/influx09-querybuilder-specs',
'specs/influxdb-datasource-specs', 'specs/influxdb-datasource-specs',
'specs/kairosdb-datasource-specs',
'specs/graph-ctrl-specs', 'specs/graph-ctrl-specs',
'specs/graph-specs', 'specs/graph-specs',
'specs/graph-tooltip-specs', 'specs/graph-tooltip-specs',
...@@ -150,4 +151,3 @@ require([ ...@@ -150,4 +151,3 @@ require([
window.__karma__.start(); window.__karma__.start();
}); });
}); });
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