From b552138189a5885eadee87eab0791ffd11edd422 Mon Sep 17 00:00:00 2001 From: ymao1 Date: Mon, 30 Nov 2020 23:02:16 -0500 Subject: [PATCH] =?UTF-8?q?Fixes=20Failing=20test:=20X-Pack=20Alerting=20A?= =?UTF-8?q?PI=20Integration=20Tests.x-pack/test/alerting=5Fapi=5Fintegrati?= =?UTF-8?q?on/security=5Fand=5Fspaces/tests/alerting/rbac=5Flegacy=C2=B7ts?= =?UTF-8?q?=20-=20alerting=20api=20integration=20security=20and=20spaces?= =?UTF-8?q?=20enabled=20Alerts=20alerts=20"before=20all"=20hook=20in=20"al?= =?UTF-8?q?erts"=20(#84255)=20(#84572)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Unskipping update test * Changing order of tests * Cleanup Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> --- .../tests/actions/index.ts | 9 +++ .../tests/alerting/index.ts | 62 ++++++++++++------- .../tests/alerting/rbac_legacy.ts | 4 +- .../security_and_spaces/tests/index.ts | 34 ++++------ 4 files changed, 62 insertions(+), 47 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 7b2e5f14fc4b6..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,10 +5,19 @@ */ import { FtrProviderContext } from '../../../common/ftr_provider_context'; +import { setupSpacesAndUsers, tearDown } from '..'; // eslint-disable-next-line import/no-default-export export default function actionsTests({ loadTestFile, getService }: FtrProviderContext) { describe('Actions', () => { + before(async () => { + await setupSpacesAndUsers(getService); + }); + + after(async () => { + await tearDown(getService); + }); + loadTestFile(require.resolve('./builtin_action_types/email')); loadTestFile(require.resolve('./builtin_action_types/es_index')); loadTestFile(require.resolve('./builtin_action_types/es_index_preconfigured')); 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 4f8525cfcf683..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,30 +5,50 @@ */ import { FtrProviderContext } from '../../../common/ftr_provider_context'; +import { setupSpacesAndUsers, tearDown } from '..'; // eslint-disable-next-line import/no-default-export -export default function alertingTests({ loadTestFile }: FtrProviderContext) { +export default function alertingTests({ loadTestFile, getService }: FtrProviderContext) { describe('Alerts', () => { - loadTestFile(require.resolve('./find')); - loadTestFile(require.resolve('./create')); - loadTestFile(require.resolve('./delete')); - loadTestFile(require.resolve('./disable')); - loadTestFile(require.resolve('./enable')); - loadTestFile(require.resolve('./execution_status')); - loadTestFile(require.resolve('./get')); - loadTestFile(require.resolve('./get_alert_state')); - loadTestFile(require.resolve('./get_alert_instance_summary')); - loadTestFile(require.resolve('./list_alert_types')); - loadTestFile(require.resolve('./mute_all')); - loadTestFile(require.resolve('./mute_instance')); - loadTestFile(require.resolve('./unmute_all')); - loadTestFile(require.resolve('./unmute_instance')); - loadTestFile(require.resolve('./update')); - loadTestFile(require.resolve('./update_api_key')); - loadTestFile(require.resolve('./alerts')); - loadTestFile(require.resolve('./event_log')); + describe('legacy alerts', () => { + before(async () => { + await setupSpacesAndUsers(getService); + }); - // note that this test will destroy existing spaces - loadTestFile(require.resolve('./rbac_legacy')); + after(async () => { + await tearDown(getService); + }); + + loadTestFile(require.resolve('./rbac_legacy')); + }); + + describe('alerts', () => { + before(async () => { + await setupSpacesAndUsers(getService); + }); + + after(async () => { + await tearDown(getService); + }); + + loadTestFile(require.resolve('./find')); + loadTestFile(require.resolve('./create')); + loadTestFile(require.resolve('./delete')); + loadTestFile(require.resolve('./disable')); + loadTestFile(require.resolve('./enable')); + loadTestFile(require.resolve('./execution_status')); + loadTestFile(require.resolve('./get')); + loadTestFile(require.resolve('./get_alert_state')); + loadTestFile(require.resolve('./get_alert_instance_summary')); + loadTestFile(require.resolve('./list_alert_types')); + loadTestFile(require.resolve('./mute_all')); + loadTestFile(require.resolve('./mute_instance')); + loadTestFile(require.resolve('./unmute_all')); + loadTestFile(require.resolve('./unmute_instance')); + loadTestFile(require.resolve('./update')); + loadTestFile(require.resolve('./update_api_key')); + loadTestFile(require.resolve('./alerts')); + loadTestFile(require.resolve('./event_log')); + }); }); } 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/index.ts b/x-pack/test/alerting_api_integration/security_and_spaces/tests/index.ts index 7daa223dc2d43..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,30 +50,15 @@ export async function tearDownUsers(securityService: ReturnType { - await setupSpacesAndUsers(spacesService, securityService); - }); - - after(async () => { - await tearDownUsers(securityService); - - await esArchiver.unload('empty_kibana'); - }); - loadTestFile(require.resolve('./actions')); loadTestFile(require.resolve('./alerting')); });