Browse Source

fix elastic tests

fix-postgres-and-elastic-tests
CorpGlory Inc. 4 years ago
parent
commit
50cbb804d3
  1. 51
      spec/elasticsearch.jest.ts

51
spec/elasticsearch.jest.ts

@ -1,12 +1,11 @@
import { ElasticsearchMetric } from '../src/metrics/elasticsearch_metric'; import { ElasticsearchMetric } from '../src/metrics/elasticsearch_metric';
import { MetricQuery, Datasource } from '../src/metrics/metric'; import { Datasource } from '../src/metrics/metric';
import 'jest';
import * as _ from 'lodash'; import * as _ from 'lodash';
describe('simple query', function(){ describe('simple query', function(){
let datasourse: Datasource = { let datasource: Datasource = {
url: "api/datasources/proxy/1/_msearch", url: "api/datasources/proxy/1/_msearch",
data: [{ data: [{
"search_type": "query_then_fetch", "search_type": "query_then_fetch",
@ -65,7 +64,7 @@ describe('simple query', function(){
}], }],
type: "elasticsearch" type: "elasticsearch"
}; };
datasourse.data = datasourse.data.map(d => JSON.stringify(d)).join('\n'); datasource.data = datasource.data.map(d => JSON.stringify(d)).join('\n');
let targets = [ let targets = [
{ {
@ -120,8 +119,8 @@ describe('simple query', function(){
{ {
"range": { "range": {
"@timestamp": { "@timestamp": {
"gte": "0", "gte": "1545933121101",
"lte": "1", "lte": "1545954721101",
"format": "epoch_millis" "format": "epoch_millis"
} }
} }
@ -163,25 +162,36 @@ describe('simple query', function(){
} }
}]; }];
let elasticMetric = new ElasticsearchMetric(datasourse, targets); let elasticMetric = new ElasticsearchMetric(datasource, targets);
it('check correct time processing', function() { it('check correct time processing', function() {
const expectedQueryTemplate = _.cloneDeep(queryTemplate);
const from = 0;
const to = 1;
const limit = 222;
const offset = 333;
expectedQueryTemplate[1].query.bool.filter[0].range['@timestamp'].gte = from.toString();
expectedQueryTemplate[1].query.bool.filter[0].range['@timestamp'].lte = to.toString();
expectedQueryTemplate[1].aggs["2"].date_histogram.extended_bounds = {
min: from.toString(),
max: to.toString()
};
let expectedQuery = { let expectedQuery = {
headers: { headers: {
"Content-Type": 'application/json' 'Content-Type': 'application/json'
}, },
url: datasourse.url, url: datasource.url,
method: 'POST', method: 'POST',
schema: { schema: {
data: queryTemplate.map(e => JSON.stringify(e)).join('\n') data: expectedQueryTemplate.map(e => JSON.stringify(e)).join('\n') + '\n'
} }
}; };
let from = 0;
let to = 1;
let limit = 222;
let offset = 333;
let result = elasticMetric.getQuery(from, to, limit, offset); let result = elasticMetric.getQuery(from, to, limit, offset);
expect(result).toEqual(expectedQuery); expect(result).toEqual(expectedQuery);
@ -248,11 +258,12 @@ describe('simple query', function(){
it('check results parsing', function() { it('check results parsing', function() {
let expectedResult = { let expectedResult = {
columns: ['timestamp', 'target'], columns: ['timestamp', 'target'],
values: [[1545934140000, null], values: [
[1545934200000, 991287.4583339691], [1545934140000, null],
[1545934260000, 898992.5] [1545934200000, 991287.4583339691],
] [1545934260000, 898992.5]
} ]
};
expect(elasticMetric.getResults(result)).toEqual(expectedResult); expect(elasticMetric.getResults(result)).toEqual(expectedResult);
}); });

Loading…
Cancel
Save