From eb8b906836a55e99810cfc1992853aa591a8572d Mon Sep 17 00:00:00 2001 From: Ying Mao Date: Tue, 24 Nov 2020 10:09:04 -0500 Subject: [PATCH] Cleanup --- .../tests/actions/index.ts | 11 +++------- .../tests/alerting/index.ts | 16 +++++---------- .../tests/alerting/rbac_legacy.ts | 4 +--- .../tests/alerting/update.ts | 2 +- .../security_and_spaces/tests/index.ts | 20 ++++++++++--------- 5 files changed, 21 insertions(+), 32 deletions(-) diff --git a/x-pack/test/alerting_api_integration/security_and_spaces/tests/actions/index.ts b/x-pack/test/alerting_api_integration/security_and_spaces/tests/actions/index.ts index 64b50326f89fd..52088a03199be 100644 --- a/x-pack/test/alerting_api_integration/security_and_spaces/tests/actions/index.ts +++ b/x-pack/test/alerting_api_integration/security_and_spaces/tests/actions/index.ts @@ -5,22 +5,17 @@ */ import { FtrProviderContext } from '../../../common/ftr_provider_context'; -import { setupSpacesAndUsers, tearDownUsers } from '..'; +import { setupSpacesAndUsers, tearDown } from '..'; // eslint-disable-next-line import/no-default-export export default function actionsTests({ loadTestFile, getService }: FtrProviderContext) { describe('Actions', () => { - const securityService = getService('security'); - const spacesService = getService('spaces'); - const esArchiver = getService('esArchiver'); - before(async () => { - await setupSpacesAndUsers(spacesService, securityService); + await setupSpacesAndUsers(getService); }); after(async () => { - await tearDownUsers(securityService); - await esArchiver.unload('empty_kibana'); + await tearDown(getService); }); loadTestFile(require.resolve('./builtin_action_types/email')); diff --git a/x-pack/test/alerting_api_integration/security_and_spaces/tests/alerting/index.ts b/x-pack/test/alerting_api_integration/security_and_spaces/tests/alerting/index.ts index 5ecaccf9e5de7..8ed979a171169 100644 --- a/x-pack/test/alerting_api_integration/security_and_spaces/tests/alerting/index.ts +++ b/x-pack/test/alerting_api_integration/security_and_spaces/tests/alerting/index.ts @@ -5,23 +5,18 @@ */ import { FtrProviderContext } from '../../../common/ftr_provider_context'; -import { setupSpacesAndUsers, tearDownUsers } from '..'; +import { setupSpacesAndUsers, tearDown } from '..'; // eslint-disable-next-line import/no-default-export export default function alertingTests({ loadTestFile, getService }: FtrProviderContext) { describe('Alerts', () => { - const securityService = getService('security'); - const spacesService = getService('spaces'); - const esArchiver = getService('esArchiver'); - describe('legacy alerts', () => { before(async () => { - await setupSpacesAndUsers(spacesService, securityService); + await setupSpacesAndUsers(getService); }); after(async () => { - await tearDownUsers(securityService); - await esArchiver.unload('empty_kibana'); + await tearDown(getService); }); loadTestFile(require.resolve('./rbac_legacy')); @@ -29,12 +24,11 @@ export default function alertingTests({ loadTestFile, getService }: FtrProviderC describe('alerts', () => { before(async () => { - await setupSpacesAndUsers(spacesService, securityService); + await setupSpacesAndUsers(getService); }); after(async () => { - await tearDownUsers(securityService); - await esArchiver.unload('empty_kibana'); + await tearDown(getService); }); loadTestFile(require.resolve('./find')); diff --git a/x-pack/test/alerting_api_integration/security_and_spaces/tests/alerting/rbac_legacy.ts b/x-pack/test/alerting_api_integration/security_and_spaces/tests/alerting/rbac_legacy.ts index 513b7fc449065..2b25c82cc92e5 100644 --- a/x-pack/test/alerting_api_integration/security_and_spaces/tests/alerting/rbac_legacy.ts +++ b/x-pack/test/alerting_api_integration/security_and_spaces/tests/alerting/rbac_legacy.ts @@ -16,8 +16,6 @@ export default function alertTests({ getService }: FtrProviderContext) { const es = getService('legacyEs'); const retry = getService('retry'); const esArchiver = getService('esArchiver'); - const securityService = getService('security'); - const spacesService = getService('spaces'); const supertestWithoutAuth = getService('supertestWithoutAuth'); const esTestIndexTool = new ESTestIndexTool(es, retry); @@ -39,7 +37,7 @@ export default function alertTests({ getService }: FtrProviderContext) { await esArchiver.load('alerts_legacy'); await esTestIndexTool.setup(); await es.indices.create({ index: authorizationIndex }); - await setupSpacesAndUsers(spacesService, securityService); + await setupSpacesAndUsers(getService); }); after(async () => { diff --git a/x-pack/test/alerting_api_integration/security_and_spaces/tests/alerting/update.ts b/x-pack/test/alerting_api_integration/security_and_spaces/tests/alerting/update.ts index c099627a1c341..9c3d2801c0886 100644 --- a/x-pack/test/alerting_api_integration/security_and_spaces/tests/alerting/update.ts +++ b/x-pack/test/alerting_api_integration/security_and_spaces/tests/alerting/update.ts @@ -32,7 +32,7 @@ export default function createUpdateTests({ getService }: FtrProviderContext) { } // FLAKY: https://github.com/elastic/kibana/issues/82804 - describe('update', () => { + describe.skip('update', () => { const objectRemover = new ObjectRemover(supertest); after(() => objectRemover.removeAll()); diff --git a/x-pack/test/alerting_api_integration/security_and_spaces/tests/index.ts b/x-pack/test/alerting_api_integration/security_and_spaces/tests/index.ts index 4b3c6d979da70..085e2c6d23335 100644 --- a/x-pack/test/alerting_api_integration/security_and_spaces/tests/index.ts +++ b/x-pack/test/alerting_api_integration/security_and_spaces/tests/index.ts @@ -8,10 +8,10 @@ import { FtrProviderContext } from '../../common/ftr_provider_context'; import { isCustomRoleSpecification } from '../../common/types'; import { Spaces, Users } from '../scenarios'; -export async function setupSpacesAndUsers( - spacesService: ReturnType, - securityService: ReturnType -) { +export async function setupSpacesAndUsers(getService: FtrProviderContext['getService']) { + const securityService = getService('security'); + const spacesService = getService('spaces'); + for (const space of Spaces) { await spacesService.create(space); } @@ -36,7 +36,10 @@ export async function setupSpacesAndUsers( } } -export async function tearDownUsers(securityService: ReturnType) { +export async function tearDown(getService: FtrProviderContext['getService']) { + const securityService = getService('security'); + const esArchiver = getService('esArchiver'); + for (const user of Users) { await securityService.user.delete(user.username); @@ -47,13 +50,12 @@ export async function tearDownUsers(securityService: ReturnType