cleaning up tests

This commit is contained in:
Matthew Bargar 2015-12-11 16:42:27 -05:00
parent 97cb8a0548
commit 1f6105591d
8 changed files with 5 additions and 238 deletions

View file

@ -3,7 +3,7 @@
"timeFieldName": "@timestamp",
"fields": [
{
"name": "geo.coordinates",
"name": "bytes",
"count": 0,
"scripted": false
},

View file

@ -18,18 +18,13 @@
},
"bytes": {
"index": "not_analyzed",
"type": "number",
"type": "long",
"doc_values": true
},
"ip": {
"index": "not_analyzed",
"type": "ip",
"doc_values": true
},
"geo.coordinates": {
"index": "not_analyzed",
"type": "geo_point",
"doc_values": false
}
}
}

View file

@ -26,10 +26,10 @@ describe('addMappingInfoToPatternFields', function () {
addMappingInfoToPatternFields(testPattern, testTemplate);
expect(_.get(testPattern, 'fields[0]')).to.be.ok();
expect(_.get(testPattern, 'fields[1]')).to.be.ok();
expect(testPattern.fields[0]).to.have.property('type', 'geo_point');
expect(testPattern.fields[0]).to.have.property('type', 'number');
expect(testPattern.fields[0]).to.have.property('indexed', true);
expect(testPattern.fields[0]).to.have.property('analyzed', false);
expect(testPattern.fields[0]).to.have.property('doc_values', false);
expect(testPattern.fields[0]).to.have.property('doc_values', true);
expect(testPattern.fields[1]).to.have.property('type', 'ip');
expect(testPattern.fields[1]).to.have.property('indexed', true);

View file

@ -1,86 +0,0 @@
const expect = require('expect.js');
const _ = require('lodash');
const getMappings = require('../get_mappings');
const indexTemplate = require('../../../../../fixtures/index_template.json');
const fieldMappings = require('../../../../../fixtures/field_mapping_multi_index.json');
const correctResult = {
'agent': {
index: 'analyzed',
type: 'string',
doc_values: false
},
'@timestamp': {
index: 'not_analyzed',
type: 'date',
doc_values: true
},
bytes: {
index: 'not_analyzed',
type: 'number',
doc_values: true
},
ip: {
index: 'not_analyzed',
type: 'ip',
doc_values: true
},
'geo.coordinates': {
index: 'not_analyzed',
type: 'geo_point',
doc_values: false
}
};
function mockCallWithRequestWithTemplate(endpoint, params) {
if (endpoint === 'indices.getTemplate') {
return Promise.resolve(indexTemplate);
}
}
function mockCallWithRequestNoTemplate(endpoint, params) {
if (endpoint === 'indices.getTemplate') {
return Promise.reject();
}
if (endpoint === 'indices.getFieldMapping') {
return Promise.resolve(fieldMappings);
}
}
function mockCallWithRequestWithTypeConflict(endpoint, params) {
if (endpoint === 'indices.getTemplate') {
return Promise.reject();
}
if (endpoint === 'indices.getFieldMapping') {
const conflictedMappings = _.cloneDeep(fieldMappings);
conflictedMappings['logstash-2015.12.03'].mappings.apache.agent.mapping.agent.type = 'date';
return Promise.resolve(conflictedMappings);
}
}
describe('getMappings', function () {
it('should return an object with field mappings for a given index pattern keyed by the field names', function () {
return getMappings('logstash-*', mockCallWithRequestWithTemplate)
.then(function (result) {
expect(_.isEqual(result, correctResult)).to.be(true);
});
});
it('should return mappings directly from the indices when no index template exists', function () {
return getMappings('logstash-*', mockCallWithRequestNoTemplate)
.then(function (result) {
expect(_.isEqual(result, correctResult)).to.be(true);
});
});
it('should mark a field\'s type as \'conflict\' if has different types across indices', function () {
return getMappings('logstash-*', mockCallWithRequestWithTypeConflict)
.then(function (result) {
const correctResultWithConflict = _.cloneDeep(correctResult);
correctResultWithConflict.agent.type = 'conflict';
expect(_.isEqual(result, correctResultWithConflict)).to.be(true);
});
});
});

View file

@ -1,55 +0,0 @@
const expect = require('expect.js');
const _ = require('lodash');
const removeDeprecatedFieldProps = require('../remove_deprecated_field_props');
const indexPattern = require('../../../../../fixtures/index_pattern.json');
indexPattern.fields[0].type = 'geo_point';
indexPattern.fields[0].indexed = true;
indexPattern.fields[0].analyzed = false;
indexPattern.fields[0].doc_values = false;
indexPattern.fields[1].type = 'ip';
indexPattern.fields[1].indexed = true;
indexPattern.fields[1].analyzed = false;
indexPattern.fields[1].doc_values = true;
describe('removeDeprecatedFieldProps', function () {
it('should remove properties from old index patterns that are now included in the field mappings', function () {
const result = removeDeprecatedFieldProps(indexPattern);
expect(result.fields[0]).not.to.have.property('type');
expect(result.fields[0]).not.to.have.property('indxed');
expect(result.fields[0]).not.to.have.property('analyzed');
expect(result.fields[0]).not.to.have.property('doc_values');
expect(result.fields[1]).not.to.have.property('type');
expect(result.fields[1]).not.to.have.property('indxed');
expect(result.fields[1]).not.to.have.property('analyzed');
expect(result.fields[1]).not.to.have.property('doc_values');
});
it('should accept an array of index patterns', function () {
const indexPatternNumeroDos = _.cloneDeep(indexPattern);
const result = removeDeprecatedFieldProps([indexPattern, indexPatternNumeroDos]);
expect(result).to.be.an('array');
expect(result[0].fields[0]).not.to.have.property('type');
expect(result[0].fields[0]).not.to.have.property('indxed');
expect(result[0].fields[0]).not.to.have.property('analyzed');
expect(result[0].fields[0]).not.to.have.property('doc_values');
expect(result[0].fields[1]).not.to.have.property('type');
expect(result[0].fields[1]).not.to.have.property('indxed');
expect(result[0].fields[1]).not.to.have.property('analyzed');
expect(result[0].fields[1]).not.to.have.property('doc_values');
expect(result[1].fields[0]).not.to.have.property('type');
expect(result[1].fields[0]).not.to.have.property('indxed');
expect(result[1].fields[0]).not.to.have.property('analyzed');
expect(result[1].fields[0]).not.to.have.property('doc_values');
expect(result[1].fields[1]).not.to.have.property('type');
expect(result[1].fields[1]).not.to.have.property('indxed');
expect(result[1].fields[1]).not.to.have.property('analyzed');
expect(result[1].fields[1]).not.to.have.property('doc_values');
});
});

View file

@ -1,56 +0,0 @@
const _ = require('lodash');
const Promise = require('bluebird');
const {templateToPattern, patternToTemplate} = require('./convert_pattern_and_template_name');
/**
* Returns normalized mappings for fields in indices matching pattern. Gets mappings from
* a matching index template if it exists, otherwise obtained directly from the indices
* themselves.
*
* @param {string} pattern - An index pattern e.g. 'logstash-*'
* @param {function} boundCallWithRequest - a partial application of callWithRequest bound to the current request
* @returns {object} Mappings keyed by field name.
*/
module.exports = function getMappings(pattern, boundCallWithRequest) {
const templateName = patternToTemplate(pattern);
const fieldMappingParams = {
index: pattern,
field: '*',
ignore_unavailable: false,
allow_no_indices: false,
include_defaults: true
};
return boundCallWithRequest('indices.getTemplate', {name: templateName})
.then((template) => {
let mappings = template[templateName].mappings;
let mergedMappings = {};
_.forEach(mappings, (type) => {
_.forEach(type.properties, (value, key) => {
mergedMappings[key] = value;
});
});
return mergedMappings;
}, (error) => {
return boundCallWithRequest('indices.getFieldMapping', fieldMappingParams)
.then((fieldMappings) => {
return _.reduce(fieldMappings, (mergedMappings, indexMappings) => {
return _.reduce(indexMappings.mappings, (mergedMappings, typeMappings) => {
return _.assign(mergedMappings, typeMappings, function (mergedValue, typeValue, key) {
const shortName = _.last(typeValue.full_name.split('.'));
if (mergedValue === undefined) {
return typeValue.mapping[shortName];
}
else {
if (mergedValue.type !== typeValue.mapping[shortName].type) {
mergedValue.type = 'conflict';
}
return mergedValue;
}
});
}, mergedMappings);
}, {});
});
});
};

View file

@ -1,26 +0,0 @@
const _ = require('lodash');
module.exports = function removeDeprecatedFieldProps(patternResources) {
if (_.isEmpty(patternResources)) { return patternResources; }
function removeFields(patternResource) {
patternResource.fields.forEach((field) => {
delete field.type;
delete field.indexed;
delete field.analyzed;
delete field.doc_values;
});
}
if (_.isArray(patternResources)) {
patternResources.forEach((patternResource) => {
removeFields(patternResource);
});
}
else {
removeFields(patternResources);
}
return patternResources;
};

View file

@ -8,10 +8,6 @@ module.exports = function createTestData() {
'title': 'logstash-*',
'time_field_name': '@timestamp',
'fields': [{
'name': 'geo.coordinates',
'count': 0,
'scripted': false
}, {
'name': 'ip',
'count': 2,
'scripted': false
@ -44,11 +40,10 @@ module.exports = function createTestData() {
'mappings': {
'_default_': {
'properties': {
'geo.coordinates': {'type': 'geo_point', 'index': 'not_analyzed', 'doc_values': false},
'ip': {'type': 'ip', 'index': 'not_analyzed', 'doc_values': true},
'@timestamp': {'type': 'date', 'index': 'not_analyzed', 'doc_values': true},
'agent': {'type': 'string', 'index': 'analyzed', 'doc_values': false},
'bytes': {'type': 'number', 'index': 'not_analyzed', 'doc_values': true}
'bytes': {'type': 'long', 'index': 'not_analyzed', 'doc_values': true}
}
}
}