Skip to content

Commit 8a39b32

Browse files
committed
refactor: moved elasticsearch specs to plugin folder and to typescript
1 parent 7d2646f commit 8a39b32

20 files changed

+702
-709
lines changed

public/app/plugins/datasource/elasticsearch/bucketAgg.js renamed to public/app/plugins/datasource/elasticsearch/bucket_agg.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
define([
22
'angular',
33
'lodash',
4-
'./queryDef',
4+
'./query_def',
55
],
66
function (angular, _, queryDef) {
77
'use strict';

public/app/plugins/datasource/elasticsearch/datasource.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ define([
33
'lodash',
44
'moment',
55
'kbn',
6-
'./queryBuilder',
7-
'./indexPattern',
8-
'./elasticResponse',
9-
'./queryCtrl',
6+
'./query_builder',
7+
'./index_pattern',
8+
'./elastic_response',
9+
'./query_ctrl',
1010
'./directives'
1111
],
1212
function (angular, _, moment, kbn, ElasticQueryBuilder, IndexPattern, ElasticResponse) {

public/app/plugins/datasource/elasticsearch/directives.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
define([
22
'angular',
3-
'./bucketAgg',
4-
'./metricAgg',
3+
'./bucket_agg',
4+
'./metric_agg',
55
],
66
function (angular) {
77
'use strict';

public/app/plugins/datasource/elasticsearch/elasticResponse.js renamed to public/app/plugins/datasource/elasticsearch/elastic_response.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
define([
22
"lodash",
3-
"./queryDef"
3+
"./query_def"
44
],
55
function (_, queryDef) {
66
'use strict';

public/app/plugins/datasource/elasticsearch/metricAgg.js renamed to public/app/plugins/datasource/elasticsearch/metric_agg.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
define([
22
'angular',
33
'lodash',
4-
'./queryDef'
4+
'./query_def'
55
],
66
function (angular, _, queryDef) {
77
'use strict';
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
///<amd-dependency path="../datasource" />
2+
///<amd-dependency path="test/specs/helpers" name="helpers" />
3+
4+
import {describe, beforeEach, it, sinon, expect, angularMocks} from 'test/lib/common';
5+
import moment = require('moment');
6+
import angular = require('angular');
7+
8+
declare var helpers: any;
9+
10+
describe('ElasticDatasource', function() {
11+
var ctx = new helpers.ServiceTestContext();
12+
13+
beforeEach(angularMocks.module('grafana.services'));
14+
beforeEach(ctx.providePhase(['templateSrv', 'backendSrv']));
15+
beforeEach(ctx.createService('ElasticDatasource'));
16+
beforeEach(function() {
17+
ctx.ds = new ctx.service({jsonData: {}});
18+
});
19+
20+
describe('When testing datasource with index pattern', function() {
21+
beforeEach(function() {
22+
ctx.ds = new ctx.service({
23+
url: 'http://es.com',
24+
index: '[asd-]YYYY.MM.DD',
25+
jsonData: { interval: 'Daily' }
26+
});
27+
});
28+
29+
it('should translate index pattern to current day', function() {
30+
var requestOptions;
31+
ctx.backendSrv.datasourceRequest = function(options) {
32+
requestOptions = options;
33+
return ctx.$q.when({});
34+
};
35+
36+
ctx.ds.testDatasource();
37+
ctx.$rootScope.$apply();
38+
39+
var today = moment().format("YYYY.MM.DD");
40+
expect(requestOptions.url).to.be("http://es.com/asd-" + today + '/_stats');
41+
});
42+
});
43+
44+
describe('When issueing metric query with interval pattern', function() {
45+
beforeEach(function() {
46+
ctx.ds = new ctx.service({
47+
url: 'http://es.com',
48+
index: '[asd-]YYYY.MM.DD',
49+
jsonData: { interval: 'Daily' }
50+
});
51+
});
52+
53+
it('should translate index pattern to current day', function() {
54+
var requestOptions;
55+
ctx.backendSrv.datasourceRequest = function(options) {
56+
requestOptions = options;
57+
return ctx.$q.when({data: {responses: []}});
58+
};
59+
60+
ctx.ds.query({
61+
range: {
62+
from: moment([2015, 4, 30, 10]),
63+
to: moment([2015, 5, 1, 10])
64+
},
65+
targets: [{ bucketAggs: [], metrics: [] }]
66+
});
67+
68+
ctx.$rootScope.$apply();
69+
var parts = requestOptions.data.split('\n');
70+
var header = angular.fromJson(parts[0]);
71+
expect(header.index).to.eql(['asd-2015.05.30', 'asd-2015.05.31', 'asd-2015.06.01']);
72+
});
73+
});
74+
});

0 commit comments

Comments
 (0)