kairosdb-datasource-specs.js 1.6 KB

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