updating DELETE tests for ability to optionally delete template along with pattern
This commit is contained in:
parent
3d30ebdeb5
commit
56b729ac61
2 changed files with 47 additions and 2 deletions
|
@ -1,6 +1,7 @@
|
|||
const _ = require('lodash');
|
||||
const handleESError = require('../../../lib/handle_es_error');
|
||||
const getIndexPattern = require('./get_index_pattern');
|
||||
const Boom = require('boom');
|
||||
|
||||
module.exports = function registerDelete(server) {
|
||||
server.route({
|
||||
|
@ -21,9 +22,14 @@ module.exports = function registerDelete(server) {
|
|||
if (shouldIncludeTemplate) {
|
||||
result = getIndexPattern(patternId, boundCallWithRequest)
|
||||
.then((patternResource) => {
|
||||
const templateId = _.get(patternResource, 'data.relationships.template.data.id');
|
||||
if (!templateId) {
|
||||
throw Boom.badRequest('The specified index pattern has no related template to delete');
|
||||
}
|
||||
|
||||
return boundCallWithRequest(
|
||||
'indices.deleteTemplate',
|
||||
{name: _.get(patternResource, 'data.relationships.template.data.id')}
|
||||
{name: templateId}
|
||||
)
|
||||
.catch((error) => {
|
||||
if (!error.status || error.status !== 404) {
|
||||
|
|
|
@ -19,7 +19,15 @@ define(function (require) {
|
|||
});
|
||||
|
||||
bdd.afterEach(function () {
|
||||
return request.del('/kibana/index_patterns/logstash-*?include=template');
|
||||
return request.del('/kibana/index_patterns/logstash-*')
|
||||
.then(function () {
|
||||
return scenarioManager.client.indices.deleteTemplate({name: 'kibana-logstash-*'})
|
||||
.catch(function (err) {
|
||||
if (err.status !== 404) {
|
||||
throw err;
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
bdd.it('should return 200 for successful deletion of pattern and template', function () {
|
||||
|
@ -36,6 +44,37 @@ define(function (require) {
|
|||
});
|
||||
});
|
||||
|
||||
bdd.it('should not delete the template if the include parameter is not sent', function () {
|
||||
return request.del('/kibana/index_patterns/logstash-*')
|
||||
.expect(200)
|
||||
.then(function () {
|
||||
return request.get('/kibana/index_patterns/logstash-*').expect(404);
|
||||
})
|
||||
.then(function () {
|
||||
return scenarioManager.client.indices.getTemplate({name: 'kibana-logstash-*'})
|
||||
.then(function (res) {
|
||||
expect(res['kibana-logstash-*']).to.be.ok();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
bdd.it('should return a 400 if template deletion is requsted for a pattern with no related template', function () {
|
||||
var templatelessPattern = createTestData().indexPatternWithTemplate;
|
||||
delete templatelessPattern.included;
|
||||
delete templatelessPattern.data.relationships;
|
||||
|
||||
return request.del('/kibana/index_patterns/logstash-*?include=template')
|
||||
.then(function () {
|
||||
return request.post('/kibana/index_patterns')
|
||||
.send(templatelessPattern)
|
||||
.expect(201);
|
||||
})
|
||||
.then(function () {
|
||||
return request.del('/kibana/index_patterns/logstash-*?include=template')
|
||||
.expect(400);
|
||||
});
|
||||
});
|
||||
|
||||
bdd.it('should return 404 for a non-existent id', function () {
|
||||
return request.del('/kibana/index_patterns/doesnotexist?include=template')
|
||||
.expect(404);
|
||||
|
|
Loading…
Reference in a new issue