-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0ab60c1
commit c93c07b
Showing
5 changed files
with
188 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
x-pack/test/api_integration/apis/management/ingest_pipelines/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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')); | ||
}); | ||
} |
127 changes: 127 additions & 0 deletions
127
x-pack/test/api_integration/apis/management/ingest_pipelines/ingest_pipelines.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', | ||
}); | ||
}); | ||
}); | ||
}); | ||
} |
41 changes: 41 additions & 0 deletions
41
x-pack/test/api_integration/apis/management/ingest_pipelines/lib/elasticsearch.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}; | ||
}; |
7 changes: 7 additions & 0 deletions
7
x-pack/test/api_integration/apis/management/ingest_pipelines/lib/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'; |