Skip to content

Commit

Permalink
add api integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
alisonelizabeth committed Apr 7, 2020
1 parent 0ab60c1 commit c93c07b
Show file tree
Hide file tree
Showing 5 changed files with 188 additions and 0 deletions.
1 change: 1 addition & 0 deletions x-pack/test/api_integration/apis/management/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@ export default function({ loadTestFile }) {
loadTestFile(require.resolve('./rollup'));
loadTestFile(require.resolve('./index_management'));
loadTestFile(require.resolve('./index_lifecycle_management'));
loadTestFile(require.resolve('./ingest_pipelines'));
});
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
import { FtrProviderContext } from '../../../ftr_provider_context';

export default function({ loadTestFile }: FtrProviderContext) {
describe('Ingest Node Pipelines', () => {
loadTestFile(require.resolve('./ingest_pipelines'));
});
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

import expect from '@kbn/expect';
import { registerEsHelpers } from './lib';

import { FtrProviderContext } from '../../../ftr_provider_context';

const API_BASE_PATH = '/api/ingest_pipelines';

export default function({ getService }: FtrProviderContext) {
const supertest = getService('supertest');

const { createPipeline, deletePipeline } = registerEsHelpers(getService);

describe('Pipelines', function() {
describe('Create', () => {
const PIPELINE_ID = 'test_create_pipeline';
after(() => deletePipeline(PIPELINE_ID));

it('should create a pipeline', async () => {
const { body } = await supertest
.put(API_BASE_PATH)
.set('kbn-xsrf', 'xxx')
.send({
name: PIPELINE_ID,
description: 'test pipeline description',
processors: [
{
script: {
source: 'ctx._type = null',
},
},
],
version: 1,
})
.expect(200);

expect(body).to.eql({
acknowledged: true,
});
});

it('should not allow creation of an existing pipeline', async () => {
const { body } = await supertest
.put(API_BASE_PATH)
.set('kbn-xsrf', 'xxx')
.send({
name: PIPELINE_ID,
description: 'test pipeline description',
processors: [
{
script: {
source: 'ctx._type = null',
},
},
],
version: 1,
})
.expect(409);

expect(body).to.eql({
statusCode: 409,
error: 'Conflict',
message: `There is already a pipeline with name '${PIPELINE_ID}'.`,
});
});
});

describe('Update', () => {
const PIPELINE_ID = 'test_update_pipeline';
const PIPELINE = {
description: 'test pipeline description',
processors: [
{
script: {
source: 'ctx._type = null',
},
},
],
version: 1,
};

before(() => createPipeline({ body: PIPELINE, id: PIPELINE_ID }));
after(() => deletePipeline(PIPELINE_ID));

it('should allow an existing pipeline to be updated', async () => {
const uri = `${API_BASE_PATH}/${PIPELINE_ID}`;

const { body } = await supertest
.put(uri)
.set('kbn-xsrf', 'xxx')
.send({
...PIPELINE,
description: 'updated test pipeline description',
})
.expect(200);

expect(body).to.eql({
acknowledged: true,
});
});

it('should not allow a non-existing pipeline to be updated', async () => {
const uri = `${API_BASE_PATH}/pipeline_does_not_exist`;

const { body } = await supertest
.put(uri)
.set('kbn-xsrf', 'xxx')
.send({
...PIPELINE,
description: 'updated test pipeline description',
})
.expect(404);

expect(body).to.eql({
statusCode: 404,
error: 'Not Found',
message: 'Not Found',
});
});
});
});
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
import { FtrProviderContext } from '../../../../ftr_provider_context';

interface Pipeline {
id: string;
body: {
description: string;
processors: any[];
version?: number;
};
}

/**
* Helpers to create and delete indices on the Elasticsearch instance
* during our tests.
* @param {ElasticsearchClient} es The Elasticsearch client instance
*/
export const registerEsHelpers = (getService: FtrProviderContext['getService']) => {
const es = getService('legacyEs');

let pipelinesCreated: Pipeline[] = [];

const createPipeline = (pipeline: Pipeline) => {
pipelinesCreated.push(pipeline);
return es.ingest.putPipeline(pipeline).then(() => pipeline);
};

const deletePipeline = (pipelineId: string) => {
pipelinesCreated = pipelinesCreated.filter(({ id }) => id !== pipelineId);
return es.ingest.deletePipeline({ id: pipelineId });
};

return {
createPipeline,
deletePipeline,
};
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

export { registerEsHelpers } from './elasticsearch';

0 comments on commit c93c07b

Please sign in to comment.