-
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.
[Index Management] Add serverless tests for index mappings (#171920)
- Loading branch information
1 parent
cc12ab7
commit 3fe27bf
Showing
7 changed files
with
150 additions
and
54 deletions.
There are no files selected for viewing
23 changes: 23 additions & 0 deletions
23
x-pack/test/api_integration/apis/management/index_management/lib/mappings.api.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,23 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { API_BASE_PATH } from '../constants'; | ||
import { FtrProviderContext } from '../../../../ftr_provider_context'; | ||
|
||
export function mappingsApi(getService: FtrProviderContext['getService']) { | ||
const supertest = getService('supertest'); | ||
|
||
const getMapping = (index: string) => | ||
supertest | ||
.get(`${API_BASE_PATH}/mapping/${index}`) | ||
.set('kbn-xsrf', 'xxx') | ||
.set('x-elastic-internal-origin', 'xxx'); | ||
|
||
return { | ||
getMapping, | ||
}; | ||
} |
16 changes: 0 additions & 16 deletions
16
x-pack/test/api_integration/apis/management/index_management/mapping.helpers.js
This file was deleted.
Oops, something went wrong.
38 changes: 0 additions & 38 deletions
38
x-pack/test/api_integration/apis/management/index_management/mapping.js
This file was deleted.
Oops, something went wrong.
58 changes: 58 additions & 0 deletions
58
x-pack/test/api_integration/apis/management/index_management/mapping.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,58 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import expect from '@kbn/expect'; | ||
|
||
import { mappingsApi } from './lib/mappings.api'; | ||
import { indicesHelpers } from './lib/indices.helpers'; | ||
import { FtrProviderContext } from '../../../ftr_provider_context'; | ||
|
||
export default function ({ getService }: FtrProviderContext) { | ||
const log = getService('log'); | ||
|
||
const { getMapping } = mappingsApi(getService); | ||
const { createIndex, deleteAllIndices } = indicesHelpers(getService); | ||
|
||
describe('mappings', () => { | ||
let indexName: string; | ||
|
||
const mappings = { | ||
properties: { | ||
total: { type: 'long' }, | ||
tag: { type: 'keyword' }, | ||
createdAt: { type: 'date' }, | ||
}, | ||
}; | ||
|
||
after(async () => await deleteAllIndices()); | ||
|
||
before(async () => { | ||
log.debug('Creating index'); | ||
try { | ||
indexName = await createIndex(undefined, mappings); | ||
} catch (err) { | ||
log.debug('[Setup error] Error creating index'); | ||
throw err; | ||
} | ||
}); | ||
|
||
after(async () => { | ||
try { | ||
await deleteAllIndices(); | ||
} catch (err) { | ||
log.debug('[Cleanup error] Error deleting index'); | ||
throw err; | ||
} | ||
}); | ||
|
||
it('should get the index mappings', async () => { | ||
const { body } = await getMapping(indexName).expect(200); | ||
|
||
expect(body.mappings).to.eql(mappings); | ||
}); | ||
}); | ||
} |
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
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
64 changes: 64 additions & 0 deletions
64
x-pack/test_serverless/api_integration/test_suites/common/index_management/mappings.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,64 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import expect from '@kbn/expect'; | ||
|
||
import { FtrProviderContext } from '../../../ftr_provider_context'; | ||
|
||
export default function ({ getService }: FtrProviderContext) { | ||
const log = getService('log'); | ||
const indexManagementService = getService('indexManagement'); | ||
|
||
describe('mappings', () => { | ||
let indexName: string; | ||
let getMapping: typeof indexManagementService['mappings']['api']['getMapping']; | ||
let createIndex: typeof indexManagementService['indices']['helpers']['createIndex']; | ||
let deleteAllIndices: typeof indexManagementService['indices']['helpers']['deleteAllIndices']; | ||
|
||
const mappings = { | ||
properties: { | ||
total: { type: 'long' }, | ||
tag: { type: 'keyword' }, | ||
createdAt: { type: 'date' }, | ||
}, | ||
}; | ||
|
||
before(async () => { | ||
({ | ||
indices: { | ||
helpers: { createIndex, deleteAllIndices }, | ||
}, | ||
mappings: { | ||
api: { getMapping }, | ||
}, | ||
} = indexManagementService); | ||
|
||
log.debug('Creating index'); | ||
try { | ||
indexName = await createIndex(undefined, mappings); | ||
} catch (err) { | ||
log.debug('[Setup error] Error creating index'); | ||
throw err; | ||
} | ||
}); | ||
|
||
after(async () => { | ||
try { | ||
await deleteAllIndices(); | ||
} catch (err) { | ||
log.debug('[Cleanup error] Error deleting index'); | ||
throw err; | ||
} | ||
}); | ||
|
||
it('should get the index mappings', async () => { | ||
const { body } = await getMapping(indexName).expect(200); | ||
|
||
expect(body.mappings).to.eql(mappings); | ||
}); | ||
}); | ||
} |