kairosdb-datasource-specs.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. define([
  2. './helpers',
  3. 'app/plugins/datasource/kairosdb/datasource'
  4. ], function(helpers) {
  5. 'use strict';
  6. describe('KairosDBDatasource', function() {
  7. var ctx = new helpers.ServiceTestContext();
  8. beforeEach(module('grafana.core'));
  9. beforeEach(module('grafana.services'));
  10. beforeEach(ctx.providePhase(['templateSrv']));
  11. beforeEach(ctx.createService('KairosDBDatasource'));
  12. beforeEach(function() {
  13. ctx.ds = new ctx.service({ url: ''});
  14. });
  15. describe('When querying kairosdb with one target using query editor target spec', function() {
  16. var results;
  17. var urlExpected = "/api/v1/datapoints/query";
  18. var bodyExpected = {
  19. metrics: [{ name: "test" }],
  20. cache_time: 0,
  21. start_relative: {
  22. value: "1",
  23. unit: "hours"
  24. }
  25. };
  26. var query = {
  27. rangeRaw: { from: 'now-1h', to: 'now' },
  28. targets: [{ metric: 'test', downsampling: '(NONE)'}]
  29. };
  30. var response = {
  31. queries: [{
  32. sample_size: 60,
  33. results: [{
  34. name: "test",
  35. values: [[1420070400000, 1]]
  36. }]
  37. }]
  38. };
  39. beforeEach(function() {
  40. ctx.$httpBackend.expect('POST', urlExpected, bodyExpected).respond(response);
  41. ctx.ds.query(query).then(function(data) { results = data; });
  42. ctx.$httpBackend.flush();
  43. });
  44. it('should generate the correct query', function() {
  45. ctx.$httpBackend.verifyNoOutstandingExpectation();
  46. });
  47. it('should return series list', function() {
  48. expect(results.data.length).to.be(1);
  49. expect(results.data[0].target).to.be('test');
  50. });
  51. });
  52. });
  53. });