influxdb-datasource-specs.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. define([
  2. './helpers',
  3. 'services/influxdb/influxdbDatasource'
  4. ], function(helpers) {
  5. 'use strict';
  6. describe('InfluxDatasource', function() {
  7. var ctx = new helpers.ServiceTestContext();
  8. beforeEach(module('grafana.services'));
  9. beforeEach(ctx.providePhase(['templateSrv']));
  10. beforeEach(ctx.createService('InfluxDatasource'));
  11. beforeEach(function() {
  12. ctx.ds = new ctx.service({ urls: [''], user: 'test', password: 'mupp' });
  13. });
  14. describe('When querying influxdb with one target using query editor target spec', function() {
  15. var results;
  16. var urlExpected = "/series?p=mupp&q=select+mean(value)+from+%22test%22"+
  17. "+where+time+%3E+now()+-+1h+group+by+time(1s)+order+asc&time_precision=s";
  18. var query = {
  19. range: { from: 'now-1h', to: 'now' },
  20. targets: [{ series: 'test', column: 'value', function: 'mean' }],
  21. interval: '1s'
  22. };
  23. var response = [{
  24. columns: ["time", "sequence_nr", "value"],
  25. name: 'test',
  26. points: [[10, 1, 1]],
  27. }];
  28. beforeEach(function() {
  29. ctx.$httpBackend.expect('GET', urlExpected).respond(response);
  30. ctx.ds.query(query).then(function(data) { results = data; });
  31. ctx.$httpBackend.flush();
  32. });
  33. it('should generate the correct query', function() {
  34. ctx.$httpBackend.verifyNoOutstandingExpectation();
  35. });
  36. it('should return series list', function() {
  37. expect(results.data.length).to.be(1);
  38. expect(results.data[0].target).to.be('test.value');
  39. });
  40. });
  41. describe('When querying influxdb with one raw query', function() {
  42. var results;
  43. var urlExpected = "/series?p=mupp&q=select+value+from+series"+
  44. "+where+time+%3E+now()+-+1h&time_precision=s";
  45. var query = {
  46. range: { from: 'now-1h', to: 'now' },
  47. targets: [{ query: "select value from series where $timeFilter", rawQuery: true }]
  48. };
  49. var response = [];
  50. beforeEach(function() {
  51. ctx.$httpBackend.expect('GET', urlExpected).respond(response);
  52. ctx.ds.query(query).then(function(data) { results = data; });
  53. ctx.$httpBackend.flush();
  54. });
  55. it('should generate the correct query', function() {
  56. ctx.$httpBackend.verifyNoOutstandingExpectation();
  57. });
  58. });
  59. describe('When issuing annotation query', function() {
  60. var results;
  61. var urlExpected = "/series?p=mupp&q=select+title+from+events.backend_01"+
  62. "+where+time+%3E+now()+-+1h&time_precision=s";
  63. var range = { from: 'now-1h', to: 'now' };
  64. var annotation = { query: 'select title from events.$server where $timeFilter' };
  65. var response = [];
  66. beforeEach(function() {
  67. ctx.templateSrv.replace = function(str) {
  68. return str.replace('$server', 'backend_01');
  69. };
  70. ctx.$httpBackend.expect('GET', urlExpected).respond(response);
  71. ctx.ds.annotationQuery(annotation, range).then(function(data) { results = data; });
  72. ctx.$httpBackend.flush();
  73. });
  74. it('should generate the correct query', function() {
  75. ctx.$httpBackend.verifyNoOutstandingExpectation();
  76. });
  77. });
  78. });
  79. });