Browse Source

Merge branch 'develop' into pro

Torkel Ödegaard 11 years ago
parent
commit
1bc277fd87

+ 35 - 14
src/test/specs/helpers.js

@@ -6,7 +6,6 @@ define([
   function ControllerTestContext() {
   function ControllerTestContext() {
     var self = this;
     var self = this;
 
 
-    this.timeRange = { from:'now-1h', to: 'now'};
     this.datasource = {};
     this.datasource = {};
     this.annotationsSrv = {};
     this.annotationsSrv = {};
     this.datasourceSrv = {
     this.datasourceSrv = {
@@ -25,18 +24,7 @@ define([
       return inject(function($controller, $rootScope, $q) {
       return inject(function($controller, $rootScope, $q) {
         self.scope = $rootScope.$new();
         self.scope = $rootScope.$new();
         self.scope.panel = {};
         self.scope.panel = {};
-        self.scope.filter = {
-          timeRange: function(parse) {
-            if (!parse) {
-              return self.timeRange;
-            }
-            return {
-              from : kbn.parseDate(self.timeRange.from),
-              to : kbn.parseDate(self.timeRange.to)
-            };
-          }
-        };
-
+        self.scope.filter = new FilterSrvStub();
         $rootScope.colors = [];
         $rootScope.colors = [];
         for (var i = 0; i < 50; i++) { $rootScope.colors.push('#' + i); }
         for (var i = 0; i < 50; i++) { $rootScope.colors.push('#' + i); }
 
 
@@ -50,9 +38,42 @@ define([
     };
     };
   }
   }
 
 
+  function ServiceTestContext() {
+    var self = this;
+
+    this.createService = function(name) {
+      return inject([name, '$q', '$rootScope', '$httpBackend', function(InfluxDatasource, $q, $rootScope, $httpBackend) {
+        self.service = InfluxDatasource;
+        self.$q = $q;
+        self.$rootScope = $rootScope;
+        self.filterSrv = new FilterSrvStub();
+        self.$httpBackend =  $httpBackend;
+      }]);
+    };
+  }
+
+  function FilterSrvStub() {
+    this.time = { from:'now-1h', to: 'now'};
+    this.timeRange = function(parse) {
+      if (!parse) {
+        return this.time;
+      }
+      return {
+        from : kbn.parseDate(this.time.from),
+             to : kbn.parseDate(this.time.to)
+      };
+    };
+
+    this.applyTemplateToTarget = function(target) {
+      return target;
+    };
+  }
+
 
 
   return {
   return {
-    ControllerTestContext: ControllerTestContext
+    ControllerTestContext: ControllerTestContext,
+    FilterSrvStub: FilterSrvStub,
+    ServiceTestContext: ServiceTestContext
   };
   };
 
 
 });
 });

+ 75 - 0
src/test/specs/influxdb-datasource-specs.js

@@ -0,0 +1,75 @@
+define([
+  './helpers',
+  'services/influxdb/influxdbDatasource'
+], function(helpers) {
+  'use strict';
+
+  describe('InfluxDatasource', function() {
+    var ctx = new helpers.ServiceTestContext();
+
+    beforeEach(module('grafana.services'));
+    beforeEach(ctx.createService('InfluxDatasource'));
+
+    describe('When querying influxdb with one target using query editor target spec', function() {
+      var results;
+      var urlExpected = "/series?p=mupp&q=select++mean(value)+from+%22test%22"+
+                        "+where++time+%3E+now()+-+1h+++++group+by+time()++order+asc&time_precision=s";
+      var query = {
+        range: { from: 'now-1h', to: 'now' },
+        targets: [{ series: 'test', column: 'value', function: 'mean' }]
+      };
+
+      var response = [{
+        columns: ["time", "sequence_nr", "value"],
+        name: 'test',
+        points: [[10, 1, 1]],
+      }];
+
+      beforeEach(function() {
+        var ds = new ctx.service({ urls: [''], user: 'test', password: 'mupp' });
+
+        ctx.$httpBackend.expect('GET', urlExpected).respond(response);
+        ds.query(ctx.filterSrv, 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.value');
+      });
+
+    });
+
+    describe('When querying influxdb with one raw query', function() {
+      var results;
+      var urlExpected = "/series?p=mupp&q=select+value+from+series"+
+                        "+where+time+%3E+now()+-+1h+and+time+%3E+1&time_precision=s";
+      var query = {
+        range: { from: 'now-1h', to: 'now' },
+        targets: [{ query: "select value from series where time > 1", rawQuery: true }]
+      };
+
+      var response = [];
+
+      beforeEach(function() {
+        var ds = new ctx.service({ urls: [''], user: 'test', password: 'mupp' });
+
+        ctx.$httpBackend.expect('GET', urlExpected).respond(response);
+        ds.query(ctx.filterSrv, query).then(function(data) { results = data; });
+        ctx.$httpBackend.flush();
+      });
+
+      it('should generate the correct query', function() {
+        ctx.$httpBackend.verifyNoOutstandingExpectation();
+      });
+
+    });
+
+  });
+
+});
+

+ 1 - 0
src/test/test-main.js

@@ -118,6 +118,7 @@ require([
     'specs/parser-specs',
     'specs/parser-specs',
     'specs/gfunc-specs',
     'specs/gfunc-specs',
     'specs/graphiteTargetCtrl-specs',
     'specs/graphiteTargetCtrl-specs',
+    'specs/influxdb-datasource-specs',
     'specs/graph-ctrl-specs',
     'specs/graph-ctrl-specs',
     'specs/filterSrv-specs',
     'specs/filterSrv-specs',
     'specs/kbn-format-specs',
     'specs/kbn-format-specs',

+ 1 - 1
src/vendor/angular/angular-dragdrop.js

@@ -330,4 +330,4 @@ var jqyoui = angular.module('ngDragDrop', []).service('ngDragDropService', ['$ti
 
 
     return element.getAttribute(name) || element.getAttribute('data-' + name);
     return element.getAttribute(name) || element.getAttribute('data-' + name);
   };
   };
-})(window, window.angular);
+})(window, window.angular);

File diff suppressed because it is too large
+ 439 - 293
src/vendor/angular/angular-mocks.js


Some files were not shown because too many files changed in this diff