Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Index Management] Add serverless tests for index mappings #171920

Merged
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,
};
}

This file was deleted.

This file was deleted.

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);
});
});
}
4 changes: 4 additions & 0 deletions x-pack/test/api_integration/services/index_management.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import { FtrProviderContext } from '../ftr_provider_context';
import { indicesApi } from '../apis/management/index_management/lib/indices.api';
import { mappingsApi } from '../apis/management/index_management/lib/mappings.api';
import { indicesHelpers } from '../apis/management/index_management/lib/indices.helpers';

export function IndexManagementProvider({ getService }: FtrProviderContext) {
Expand All @@ -15,5 +16,8 @@ export function IndexManagementProvider({ getService }: FtrProviderContext) {
api: indicesApi(getService),
helpers: indicesHelpers(getService),
},
mappings: {
api: mappingsApi(getService),
},
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@ export default function ({ loadTestFile }: FtrProviderContext) {
loadTestFile(require.resolve('./index_templates'));
loadTestFile(require.resolve('./indices'));
loadTestFile(require.resolve('./create_enrich_policies'));
loadTestFile(require.resolve('./mappings'));
});
}
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);
});
});
}
Loading