Merge pull request #1814 from masaori335/kairosdb-test

Add a basic test of KairosDBDatasource
This commit is contained in:
Torkel Ödegaard 2015-04-19 18:23:00 +02:00
commit 0d8e024c18
5 changed files with 81 additions and 21 deletions

View File

@ -150,9 +150,6 @@ function (angular, _, kbn) {
var output = [];
var index = 0;
_.each(results.data.queries, function(series) {
var sample_size = series.sample_size;
console.log("sample_size:" + sample_size + " samples");
_.each(series.results, function(result) {
//var target = result.name;

View File

@ -2,7 +2,7 @@
<div ng-repeat="target in panel.targets"
class="tight-form-container"
ng-class="{'tight-form-disabled': target.hide}"
ng-controller="KairosDBTargetCtrl"
ng-controller="KairosDBQueryCtrl"
ng-init="init()">
<div class="tight-form">
@ -345,7 +345,7 @@
</div>
</div>
<section class="grafana-metric-options" ng-controller="KairosDBTargetCtrl">
<section class="grafana-metric-options" ng-controller="KairosDBQueryCtrl">
<div class="tight-form">
<ul class="tight-form-list">
<li class="tight-form-item tight-form-item-icon">

View File

@ -9,7 +9,7 @@ function (angular, _) {
var metricList = null;
var targetLetters = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O'];
module.controller('KairosDBTargetCtrl', function($scope) {
module.controller('KairosDBQueryCtrl', function($scope) {
$scope.init = function() {
$scope.metric = {

View File

@ -0,0 +1,63 @@
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');
});
});
});
});

View File

@ -128,6 +128,7 @@ require([
'specs/influxQueryBuilder-specs',
'specs/influx09-querybuilder-specs',
'specs/influxdb-datasource-specs',
'specs/kairosdb-datasource-specs',
'specs/graph-ctrl-specs',
'specs/graph-specs',
'specs/graph-tooltip-specs',
@ -150,4 +151,3 @@ require([
window.__karma__.start();
});
});