|
|
@@ -1,10 +1,9 @@
|
|
|
+import angular from 'angular';
|
|
|
+import * as dateMath from 'app/core/utils/datemath';
|
|
|
import _ from 'lodash';
|
|
|
import moment from 'moment';
|
|
|
-import angular from 'angular';
|
|
|
import { ElasticDatasource } from '../datasource';
|
|
|
|
|
|
-import * as dateMath from 'app/core/utils/datemath';
|
|
|
-
|
|
|
describe('ElasticDatasource', function(this: any) {
|
|
|
const backendSrv = {
|
|
|
datasourceRequest: jest.fn(),
|
|
|
@@ -73,9 +72,9 @@ describe('ElasticDatasource', function(this: any) {
|
|
|
});
|
|
|
|
|
|
describe('When issuing metric query with interval pattern', () => {
|
|
|
- let requestOptions, parts, header, query;
|
|
|
+ let requestOptions, parts, header, query, result;
|
|
|
|
|
|
- beforeEach(() => {
|
|
|
+ beforeEach(async () => {
|
|
|
createDatasource({
|
|
|
url: 'http://es.com',
|
|
|
index: '[asd-]YYYY.MM.DD',
|
|
|
@@ -84,7 +83,24 @@ describe('ElasticDatasource', function(this: any) {
|
|
|
|
|
|
ctx.backendSrv.datasourceRequest = jest.fn(options => {
|
|
|
requestOptions = options;
|
|
|
- return Promise.resolve({ data: { responses: [] } });
|
|
|
+ return Promise.resolve({
|
|
|
+ data: {
|
|
|
+ responses: [
|
|
|
+ {
|
|
|
+ aggregations: {
|
|
|
+ '1': {
|
|
|
+ buckets: [
|
|
|
+ {
|
|
|
+ doc_count: 10,
|
|
|
+ key: 1000,
|
|
|
+ },
|
|
|
+ ],
|
|
|
+ },
|
|
|
+ },
|
|
|
+ },
|
|
|
+ ],
|
|
|
+ },
|
|
|
+ });
|
|
|
});
|
|
|
|
|
|
query = {
|
|
|
@@ -95,14 +111,14 @@ describe('ElasticDatasource', function(this: any) {
|
|
|
targets: [
|
|
|
{
|
|
|
alias: '$varAlias',
|
|
|
- bucketAggs: [],
|
|
|
- metrics: [{ type: 'raw_document' }],
|
|
|
+ bucketAggs: [{ type: 'date_histogram', field: '@timestamp', id: '1' }],
|
|
|
+ metrics: [{ type: 'count', id: '1' }],
|
|
|
query: 'escape\\:test',
|
|
|
},
|
|
|
],
|
|
|
};
|
|
|
|
|
|
- ctx.ds.query(query);
|
|
|
+ result = await ctx.ds.query(query);
|
|
|
|
|
|
parts = requestOptions.data.split('\n');
|
|
|
header = angular.fromJson(parts[0]);
|
|
|
@@ -112,8 +128,12 @@ describe('ElasticDatasource', function(this: any) {
|
|
|
expect(header.index).toEqual(['asd-2015.05.30', 'asd-2015.05.31', 'asd-2015.06.01']);
|
|
|
});
|
|
|
|
|
|
- it('should resolve the alias variable', () => {
|
|
|
- expect(query.targets[0].alias).toEqual('resolvedVariable');
|
|
|
+ it('should not resolve the variable in the original alias field in the query', () => {
|
|
|
+ expect(query.targets[0].alias).toEqual('$varAlias');
|
|
|
+ });
|
|
|
+
|
|
|
+ it('should resolve the alias variable for the alias/target in the result', () => {
|
|
|
+ expect(result.data[0].target).toEqual('resolvedVariable');
|
|
|
});
|
|
|
|
|
|
it('should json escape lucene query', () => {
|