From 90a20a98bad41b10be2f357da325195a9ae03556 Mon Sep 17 00:00:00 2001 From: Kurt Date: Mon, 19 Sep 2022 15:11:53 -0400 Subject: [PATCH 1/7] Removing esArchiver in favor of testDataLoader --- .../common/lib/test_data_loader.ts | 128 ++++++++++++++++++ .../common/suites/bulk_get.ts | 21 ++- .../security_and_spaces/apis/bulk_get.ts | 10 +- .../spaces_only/apis/bulk_get.ts | 6 +- 4 files changed, 141 insertions(+), 24 deletions(-) create mode 100644 x-pack/test/saved_object_api_integration/common/lib/test_data_loader.ts diff --git a/x-pack/test/saved_object_api_integration/common/lib/test_data_loader.ts b/x-pack/test/saved_object_api_integration/common/lib/test_data_loader.ts new file mode 100644 index 0000000000000..4b25c722603c8 --- /dev/null +++ b/x-pack/test/saved_object_api_integration/common/lib/test_data_loader.ts @@ -0,0 +1,128 @@ +/* + * 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 { FtrProviderContext } from '../ftr_provider_context'; + +const SPACE_1 = { + id: 'space_1', + name: 'Space 1', + description: 'This is the first test space', + disabledFeatures: [], +}; + +const SPACE_2 = { + id: 'space_2', + name: 'Space 2', + description: 'This is the second test space', + disabledFeatures: [], +}; + +// Objects can only be imported in one space at a time. To have test saved objects +// that are shared in multiple spaces we should import all objects in the "original" +// spaces first and then share them to other spaces as a subsequent operation. +const OBJECTS_TO_SHARE: Array<{ + spacesToAdd?: string[]; + spacesToRemove?: string[]; + objects: Array<{ type: string; id: string }>; +}> = [ + { + spacesToAdd: ['*'], + spacesToRemove: ['default'], + objects: [ + { type: 'sharedtype', id: 'all_spaces' }, + { type: 'sharedtype', id: 'space_2_only_matching_origin' }, + { type: 'sharedtype', id: 'alias_delete_exclusive' }, + ], + }, + { + spacesToRemove: ['default'], + spacesToAdd: [SPACE_1.id, SPACE_2.id], + objects: [{ type: 'sharedtype', id: 'space_1_and_space_2' }], + }, + { + spacesToAdd: [SPACE_1.id, SPACE_2.id], + objects: [ + { type: 'sharedtype', id: 'each_space' }, + { type: 'sharedtype', id: 'conflict_2_all' }, + { type: 'sharedtype', id: 'alias_delete_inclusive' }, + ], + }, + { + spacesToAdd: [SPACE_1.id], + objects: [ + { type: 'sharedtype', id: 'conflict_1c_default_and_space_1' }, + { type: 'sharedtype', id: 'default_and_space_1' }, + ], + }, + { + spacesToAdd: [SPACE_2.id], + objects: [{ type: 'sharedtype', id: 'default_and_space_2' }], + }, +]; + +export function getTestDataLoader({ getService }: FtrProviderContext) { + const spacesService = getService('spaces'); + const kbnServer = getService('kibanaServer'); + const supertest = getService('supertest'); + const log = getService('log'); + + return { + before: async () => { + await Promise.all([await spacesService.create(SPACE_1), await spacesService.create(SPACE_2)]); + }, + + after: async () => { + await Promise.all([spacesService.delete(SPACE_1.id), spacesService.delete(SPACE_2.id)]); + }, + + beforeEach: async () => { + log.debug('Loading test data for the following spaces: default, space_1 and space_2'); + await Promise.all([ + kbnServer.importExport.load( + 'x-pack/test/spaces_api_integration/common/fixtures/kbn_archiver/default_space.json' + ), + kbnServer.importExport.load( + 'x-pack/test/spaces_api_integration/common/fixtures/kbn_archiver/space_1.json', + { space: SPACE_1.id } + ), + kbnServer.importExport.load( + 'x-pack/test/spaces_api_integration/common/fixtures/kbn_archiver/space_2.json', + { space: SPACE_2.id } + ), + ]); + + // Adjust spaces for the imported saved objects. + for (const { objects, spacesToAdd = [], spacesToRemove = [] } of OBJECTS_TO_SHARE) { + log.debug( + `Updating spaces for the following objects (add: [${spacesToAdd.join( + ', ' + )}], remove: [${spacesToRemove.join(', ')}]): ${objects + .map(({ type, id }) => `${type}:${id}`) + .join(', ')}` + ); + await supertest + .post('/api/spaces/_update_objects_spaces') + .send({ objects, spacesToAdd, spacesToRemove }) + .expect(200); + } + }, + + afterEach: async () => { + const allSpacesIds = [ + ...(await spacesService.getAll()).map((space) => space.id), + 'non_existent_space', + ]; + log.debug(`Removing data from the following spaces: ${allSpacesIds.join(', ')}`); + await Promise.all( + allSpacesIds.flatMap((spaceId) => [ + kbnServer.savedObjects.cleanStandardList({ space: spaceId }), + kbnServer.savedObjects.clean({ space: spaceId, types: ['sharedtype', 'isolatedtype'] }), + ]) + ); + }, + }; +} diff --git a/x-pack/test/saved_object_api_integration/common/suites/bulk_get.ts b/x-pack/test/saved_object_api_integration/common/suites/bulk_get.ts index 10709a6f20916..55c0a50539c72 100644 --- a/x-pack/test/saved_object_api_integration/common/suites/bulk_get.ts +++ b/x-pack/test/saved_object_api_integration/common/suites/bulk_get.ts @@ -6,11 +6,12 @@ */ import expect from '@kbn/expect'; -import { SuperTest } from 'supertest'; import { SAVED_OBJECT_TEST_CASES as CASES } from '../lib/saved_object_test_cases'; import { SPACES } from '../lib/spaces'; import { expectResponses, getUrlPrefix, getTestTitle } from '../lib/saved_object_test_utils'; import { ExpectResponseBody, TestCase, TestDefinition, TestSuite } from '../lib/types'; +import { FtrProviderContext } from '../ftr_provider_context'; +import {getTestDataLoader} from "../lib/test_data_loader"; export interface BulkGetTestDefinition extends TestDefinition { request: Array<{ type: string; id: string }>; @@ -33,7 +34,11 @@ const createRequest = ({ type, id, namespaces }: BulkGetTestCase) => ({ ...(namespaces && { namespaces }), // individual "object namespaces" string array }); -export function bulkGetTestSuiteFactory(esArchiver: any, supertest: SuperTest) { +export function bulkGetTestSuiteFactory(context: FtrProviderContext) { + + const testDataLoader = getTestDataLoader(context); + const supertest = context.getService('supertestWithoutAuth'); + const expectSavedObjectForbidden = expectResponses.forbiddenTypes('bulk_get'); const expectResponseBody = (testCases: BulkGetTestCase | BulkGetTestCase[], statusCode: 200 | 403): ExpectResponseBody => @@ -91,16 +96,8 @@ export function bulkGetTestSuiteFactory(esArchiver: any, supertest: SuperTest { - before(() => - esArchiver.load( - 'x-pack/test/saved_object_api_integration/common/fixtures/es_archiver/saved_objects/spaces' - ) - ); - after(() => - esArchiver.unload( - 'x-pack/test/saved_object_api_integration/common/fixtures/es_archiver/saved_objects/spaces' - ) - ); + before(async () => await testDataLoader.beforeEach()); + after(async () => await testDataLoader.afterEach()); for (const test of tests) { it(`should return ${test.responseStatusCode} ${test.title}`, async () => { diff --git a/x-pack/test/saved_object_api_integration/security_and_spaces/apis/bulk_get.ts b/x-pack/test/saved_object_api_integration/security_and_spaces/apis/bulk_get.ts index 2c1fbf442b0ec..8ba82ac5c25fd 100644 --- a/x-pack/test/saved_object_api_integration/security_and_spaces/apis/bulk_get.ts +++ b/x-pack/test/saved_object_api_integration/security_and_spaces/apis/bulk_get.ts @@ -67,14 +67,8 @@ const createTestCases = (spaceId: string) => { return { normalTypes, crossNamespace, hiddenType, allTypes }; }; -export default function ({ getService }: FtrProviderContext) { - const supertest = getService('supertestWithoutAuth'); - const esArchiver = getService('esArchiver'); - - const { addTests, createTestDefinitions, expectSavedObjectForbidden } = bulkGetTestSuiteFactory( - esArchiver, - supertest - ); +export default function (context: FtrProviderContext) { + const { addTests, createTestDefinitions, expectSavedObjectForbidden } = bulkGetTestSuiteFactory(context); const createTests = (spaceId: string) => { const { normalTypes, crossNamespace, hiddenType, allTypes } = createTestCases(spaceId); // use singleRequest to reduce execution time and/or test combined cases diff --git a/x-pack/test/saved_object_api_integration/spaces_only/apis/bulk_get.ts b/x-pack/test/saved_object_api_integration/spaces_only/apis/bulk_get.ts index 41fa4749cc48e..6ed108ea1fb05 100644 --- a/x-pack/test/saved_object_api_integration/spaces_only/apis/bulk_get.ts +++ b/x-pack/test/saved_object_api_integration/spaces_only/apis/bulk_get.ts @@ -55,11 +55,9 @@ const createTestCases = (spaceId: string) => [ { ...CASES.MULTI_NAMESPACE_ONLY_SPACE_1, namespaces: [ALL_SPACES_ID] }, ]; -export default function ({ getService }: FtrProviderContext) { - const supertest = getService('supertest'); - const esArchiver = getService('esArchiver'); +export default function (context: FtrProviderContext) { - const { addTests, createTestDefinitions } = bulkGetTestSuiteFactory(esArchiver, supertest); + const { addTests, createTestDefinitions } = bulkGetTestSuiteFactory(context); const createTests = (spaceId: string) => { const testCases = createTestCases(spaceId); return createTestDefinitions(testCases, false, { singleRequest: true }); From 09a50251ccbcd49c6e391edc941948f41e139f28 Mon Sep 17 00:00:00 2001 From: kibanamachine <42973632+kibanamachine@users.noreply.github.com> Date: Mon, 19 Sep 2022 19:27:23 +0000 Subject: [PATCH 2/7] [CI] Auto-commit changed files from 'node scripts/precommit_hook.js --ref HEAD~1..HEAD --fix' --- .../saved_object_api_integration/common/suites/bulk_get.ts | 3 +-- .../security_and_spaces/apis/bulk_get.ts | 3 ++- .../saved_object_api_integration/spaces_only/apis/bulk_get.ts | 1 - 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/x-pack/test/saved_object_api_integration/common/suites/bulk_get.ts b/x-pack/test/saved_object_api_integration/common/suites/bulk_get.ts index 55c0a50539c72..34eb043f165f3 100644 --- a/x-pack/test/saved_object_api_integration/common/suites/bulk_get.ts +++ b/x-pack/test/saved_object_api_integration/common/suites/bulk_get.ts @@ -11,7 +11,7 @@ import { SPACES } from '../lib/spaces'; import { expectResponses, getUrlPrefix, getTestTitle } from '../lib/saved_object_test_utils'; import { ExpectResponseBody, TestCase, TestDefinition, TestSuite } from '../lib/types'; import { FtrProviderContext } from '../ftr_provider_context'; -import {getTestDataLoader} from "../lib/test_data_loader"; +import { getTestDataLoader } from '../lib/test_data_loader'; export interface BulkGetTestDefinition extends TestDefinition { request: Array<{ type: string; id: string }>; @@ -35,7 +35,6 @@ const createRequest = ({ type, id, namespaces }: BulkGetTestCase) => ({ }); export function bulkGetTestSuiteFactory(context: FtrProviderContext) { - const testDataLoader = getTestDataLoader(context); const supertest = context.getService('supertestWithoutAuth'); diff --git a/x-pack/test/saved_object_api_integration/security_and_spaces/apis/bulk_get.ts b/x-pack/test/saved_object_api_integration/security_and_spaces/apis/bulk_get.ts index 8ba82ac5c25fd..ed251440d361a 100644 --- a/x-pack/test/saved_object_api_integration/security_and_spaces/apis/bulk_get.ts +++ b/x-pack/test/saved_object_api_integration/security_and_spaces/apis/bulk_get.ts @@ -68,7 +68,8 @@ const createTestCases = (spaceId: string) => { }; export default function (context: FtrProviderContext) { - const { addTests, createTestDefinitions, expectSavedObjectForbidden } = bulkGetTestSuiteFactory(context); + const { addTests, createTestDefinitions, expectSavedObjectForbidden } = + bulkGetTestSuiteFactory(context); const createTests = (spaceId: string) => { const { normalTypes, crossNamespace, hiddenType, allTypes } = createTestCases(spaceId); // use singleRequest to reduce execution time and/or test combined cases diff --git a/x-pack/test/saved_object_api_integration/spaces_only/apis/bulk_get.ts b/x-pack/test/saved_object_api_integration/spaces_only/apis/bulk_get.ts index 6ed108ea1fb05..30ed220ea9ae3 100644 --- a/x-pack/test/saved_object_api_integration/spaces_only/apis/bulk_get.ts +++ b/x-pack/test/saved_object_api_integration/spaces_only/apis/bulk_get.ts @@ -56,7 +56,6 @@ const createTestCases = (spaceId: string) => [ ]; export default function (context: FtrProviderContext) { - const { addTests, createTestDefinitions } = bulkGetTestSuiteFactory(context); const createTests = (spaceId: string) => { const testCases = createTestCases(spaceId); From 6838a2d098103b94b295d3ccb3575cac5dade43a Mon Sep 17 00:00:00 2001 From: Kurt Date: Thu, 22 Sep 2022 14:36:25 -0400 Subject: [PATCH 3/7] Adding test data for loader --- .../fixtures/kbn_archiver/default_space.json | 163 ++++++++++++++++++ .../common/fixtures/kbn_archiver/space_1.json | 72 ++++++++ .../common/fixtures/kbn_archiver/space_2.json | 58 +++++++ .../common/lib/test_data_loader.ts | 6 +- .../common/suites/bulk_get.ts | 11 +- 5 files changed, 305 insertions(+), 5 deletions(-) create mode 100644 x-pack/test/saved_object_api_integration/common/fixtures/kbn_archiver/default_space.json create mode 100644 x-pack/test/saved_object_api_integration/common/fixtures/kbn_archiver/space_1.json create mode 100644 x-pack/test/saved_object_api_integration/common/fixtures/kbn_archiver/space_2.json diff --git a/x-pack/test/saved_object_api_integration/common/fixtures/kbn_archiver/default_space.json b/x-pack/test/saved_object_api_integration/common/fixtures/kbn_archiver/default_space.json new file mode 100644 index 0000000000000..9a2713fc61872 --- /dev/null +++ b/x-pack/test/saved_object_api_integration/common/fixtures/kbn_archiver/default_space.json @@ -0,0 +1,163 @@ +{ + "attributes": { + "title": "logstash-*" + }, + "coreMigrationVersion": "8.4.0", + "id": "defaultspace-index-pattern-id", + "migrationVersion": { + "index-pattern": "8.0.0" + }, + "originId": "cts_ip_1", + "references": [], + "type": "index-pattern", + "updated_at": "2017-09-21T18:49:16.270Z", + "version": "WzUyOCwxXQ==" +} + +{ + "attributes": { + "title": "Count of requests", + "uiStateJSON": "{\"spy\":{\"mode\":{\"name\":null,\"fill\":false}}}", + "version": 1, + "visState": "{\"title\":\"Count of requests\",\"type\":\"area\",\"params\":{\"type\":\"area\",\"grid\":{\"categoryLines\":false,\"style\":{\"color\":\"#eee\"}},\"categoryAxes\":[{\"id\":\"CategoryAxis-1\",\"type\":\"category\",\"position\":\"bottom\",\"show\":true,\"style\":{},\"scale\":{\"type\":\"linear\"},\"labels\":{\"show\":true,\"truncate\":100},\"title\":{}}],\"valueAxes\":[{\"id\":\"ValueAxis-1\",\"name\":\"LeftAxis-1\",\"type\":\"value\",\"position\":\"left\",\"show\":true,\"style\":{},\"scale\":{\"type\":\"linear\",\"mode\":\"normal\"},\"labels\":{\"show\":true,\"rotate\":0,\"filter\":false,\"truncate\":100},\"title\":{\"text\":\"Count\"}}],\"seriesParams\":[{\"show\":\"true\",\"type\":\"area\",\"mode\":\"stacked\",\"data\":{\"label\":\"Count\",\"id\":\"1\"},\"drawLinesBetweenPoints\":true,\"showCircles\":true,\"interpolate\":\"linear\",\"valueAxis\":\"ValueAxis-1\"}],\"addTooltip\":true,\"addLegend\":true,\"legendPosition\":\"right\",\"times\":[],\"addTimeMarker\":false},\"aggs\":[{\"id\":\"1\",\"enabled\":true,\"type\":\"count\",\"schema\":\"metric\",\"params\":{}},{\"id\":\"2\",\"enabled\":true,\"type\":\"date_histogram\",\"schema\":\"segment\",\"params\":{\"field\":\"@timestamp\",\"interval\":\"auto\",\"customInterval\":\"2h\",\"min_doc_count\":1,\"extended_bounds\":{}}}]}", + "description": "", + "kibanaSavedObjectMeta": { + "searchSourceJSON": "{\"index\":\"defaultspace-index-pattern-id\",\"filter\":[],\"query\":{\"query\":\"\",\"language\":\"lucene\"}}" + } + }, + "id": "defaultspace-isolatedtype-id", + "references": [], + "type": "isolatedtype", + "updated_at": "2017-09-21T18:51:23.794Z", + "version": "WzQ4NywxXQ==" +} + +{ + "attributes": { + "title": "Requests", + "kibanaSavedObjectMeta": { + "searchSourceJSON": "{\"query\":{\"query\":\"\",\"language\":\"lucene\"},\"filter\":[],\"highlightAll\":true,\"version\":true}" + } + }, + "coreMigrationVersion": "8.4.0", + "id": "defaultspace-dashboard-id", + "migrationVersion": { + "dashboard": "8.4.0" + }, + "type": "dashboard", + "updated_at": "2017-09-21T18:49:16.270Z", + "version": "WzUyMCwxXQ==" +} + +{ + "attributes": { + "title": "A share-capable (isolated) saved-object only in the default space" + }, + "id": "only_default_space", + "type": "sharecapabletype", + "updated_at": "2017-09-21T18:59:16.270Z", + "version": "WzQ4OCwxXQ==" +} + +{ + "attributes": { + "title": "A shared saved-object in all spaces" + }, + "id": "all_spaces", + "type": "sharedtype", + "references": [], + "updated_at": "2017-09-21T18:59:16.270Z", + "version": "WzQ5NywxXQ==" +} + +{ + "attributes": { + "title": "My favorite global object" + }, + "id": "globaltype-id", + "references": [], + "type": "globaltype", + "updated_at": "2017-09-21T18:49:16.270Z", + "version": "WzQ4NywxXQ==" +} + +{ + "attributes": { + "title": "A shared saved-object in the default and space_1 spaces" + }, + "id": "default_and_space_1", + "type": "sharedtype", + "updated_at": "2017-09-21T18:59:16.270Z", + "version": "WzQ4OCwxXQ==" +} + +{ + "attributes": { + "title": "A sharedtype saved-object with id: conflict_1" + }, + "id": "conflict_1", + "type": "sharedtype", + "updated_at": "2017-09-21T18:59:16.270Z", + "version": "WzQ4OCwxXQ==" +} + +{ + "attributes": { + "title": "A sharedtype saved-object with id: conflict_2a" + }, + "id": "conflict_2a", + "type": "sharedtype", + "updated_at": "2017-09-21T18:59:16.270Z", + "version": "WzQ4OCwxXQ==" +} + +{ + "attributes": { + "title": "A sharedtype saved-object with id: conflict_2b" + }, + "id": "conflict_2b", + "type": "sharedtype", + "updated_at": "2017-09-21T18:59:16.270Z", + "version": "WzQ4OCwxXQ==" +} + +{ + "attributes": { + "title": "A sharedtype saved-object with id: conflict_3" + }, + "id": "conflict_3", + "type": "sharedtype", + "updated_at": "2017-09-21T18:59:16.270Z", + "version": "WzQ4OCwxXQ==" +} + +{ + "attributes": { + "title": "A sharedtype saved-object with id: conflict_4a" + }, + "id": "conflict_4a", + "type": "sharedtype", + "updated_at": "2017-09-21T18:59:16.270Z", + "version": "WzQ4OCwxXQ==" +} + +{ + "attributes": { + "title": "Resolve outcome exactMatch" + }, + "id": "exact-match", + "type": "resolvetype", + "updated_at": "2017-09-21T18:59:16.270Z", + "version": "WzQ4OCwxXQ==" +} + +{ + "attributes": { + "title": "Resolve outcome aliasMatch" + }, + "id": "alias-match-newid", + "type": "resolvetype", + "updated_at": "2017-09-21T18:59:16.270Z", + "version": "WzQ4OCwxXQ==" +} + diff --git a/x-pack/test/saved_object_api_integration/common/fixtures/kbn_archiver/space_1.json b/x-pack/test/saved_object_api_integration/common/fixtures/kbn_archiver/space_1.json new file mode 100644 index 0000000000000..6356d5c01989b --- /dev/null +++ b/x-pack/test/saved_object_api_integration/common/fixtures/kbn_archiver/space_1.json @@ -0,0 +1,72 @@ + + +{ + "attributes": { + "title": "logstash-*" + }, + "coreMigrationVersion": "8.4.0", + "id": "space1-index-pattern-id", + "migrationVersion": { + "index-pattern": "8.0.0" + }, + "references": [], + "type": "index-pattern", + "updated_at": "2017-09-21T18:49:16.270Z", + "version": "WzUyOSwxXQ==" +} + +{ + "attributes": { + "description": "", + "kibanaSavedObjectMeta": { + "searchSourceJSON": "{\"index\":\"space1-index-pattern-id\",\"filter\":[],\"query\":{\"query\":\"\",\"language\":\"lucene\"}}" + }, + "title": "Count of requests", + "uiStateJSON": "{\"spy\":{\"mode\":{\"name\":null,\"fill\":false}}}", + "version": 1, + "visState": "{\"title\":\"Count of requests\",\"type\":\"area\",\"params\":{\"type\":\"area\",\"grid\":{\"categoryLines\":false,\"style\":{\"color\":\"#eee\"}},\"categoryAxes\":[{\"id\":\"CategoryAxis-1\",\"type\":\"category\",\"position\":\"bottom\",\"show\":true,\"style\":{},\"scale\":{\"type\":\"linear\"},\"labels\":{\"show\":true,\"truncate\":100},\"title\":{}}],\"valueAxes\":[{\"id\":\"ValueAxis-1\",\"name\":\"LeftAxis-1\",\"type\":\"value\",\"position\":\"left\",\"show\":true,\"style\":{},\"scale\":{\"type\":\"linear\",\"mode\":\"normal\"},\"labels\":{\"show\":true,\"rotate\":0,\"filter\":false,\"truncate\":100},\"title\":{\"text\":\"Count\"}}],\"seriesParams\":[{\"show\":\"true\",\"type\":\"area\",\"mode\":\"stacked\",\"data\":{\"label\":\"Count\",\"id\":\"1\"},\"drawLinesBetweenPoints\":true,\"showCircles\":true,\"interpolate\":\"linear\",\"valueAxis\":\"ValueAxis-1\"}],\"addTooltip\":true,\"addLegend\":true,\"legendPosition\":\"right\",\"times\":[],\"addTimeMarker\":false},\"aggs\":[{\"id\":\"1\",\"enabled\":true,\"type\":\"count\",\"schema\":\"metric\",\"params\":{}},{\"id\":\"2\",\"enabled\":true,\"type\":\"date_histogram\",\"schema\":\"segment\",\"params\":{\"field\":\"@timestamp\",\"interval\":\"auto\",\"customInterval\":\"2h\",\"min_doc_count\":1,\"extended_bounds\":{}}}]}" + }, + "id": "space1-isolatedtype-id", + "references": [], + "type": "isolatedtype", + "updated_at": "2017-09-21T18:49:16.270Z", + "version": "WzQ4NywxXQ==" +} + +{ + "attributes": { + "title": "Requests", + "kibanaSavedObjectMeta": { + "searchSourceJSON": "{\"query\":{\"query\":\"\",\"language\":\"lucene\"},\"filter\":[],\"highlightAll\":true,\"version\":true}" + }, + "version": 1 + }, + "coreMigrationVersion": "8.4.0", + "id": "space1-dashboard-id", + "migrationVersion": { + "dashboard": "8.4.0" + }, + "type": "dashboard", + "updated_at": "2017-09-21T18:49:16.270Z", + "version": "WzUyMCwxXQ==" +} + +{ + "attributes": { + "title": "A shared saved-object only in space_1" + }, + "id": "only_space_1", + "type": "sharedtype", + "updated_at": "2017-09-21T18:59:16.270Z", + "version": "WzQ4OCwxXQ==" +} + +{ + "attributes": { + "title": "A share-capable (isolated) saved-object only in space_1" + }, + "id": "only_space_1", + "type": "sharecapabletype", + "updated_at": "2017-09-21T18:59:16.270Z", + "version": "WzQ4OCwxXQ==" +} diff --git a/x-pack/test/saved_object_api_integration/common/fixtures/kbn_archiver/space_2.json b/x-pack/test/saved_object_api_integration/common/fixtures/kbn_archiver/space_2.json new file mode 100644 index 0000000000000..9715a5f54d2b4 --- /dev/null +++ b/x-pack/test/saved_object_api_integration/common/fixtures/kbn_archiver/space_2.json @@ -0,0 +1,58 @@ +{ + "attributes": { + "title": "logstash-*" + }, + "coreMigrationVersion": "8.4.0", + "id": "space2-index-pattern-id", + "migrationVersion": { + "index-pattern": "8.0.0" + }, + "references": [], + "type": "index-pattern", + "updated_at": "2017-09-21T18:49:16.270Z", + "version": "WzUyOSwxXQ==" +} + +{ + "attributes": { + "description": "", + "kibanaSavedObjectMeta": { + "searchSourceJSON": "{\"index\":\"space2-index-pattern-id\",\"filter\":[],\"query\":{\"query\":\"\",\"language\":\"lucene\"}}" + }, + "title": "Count of requests", + "version": 1 + }, + "id": "space2-isolatedtype-id", + "references": [], + "type": "isolatedtype", + "updated_at": "2017-09-21T18:49:16.270Z", + "version": "WzQ4NywxXQ==" +} + +{ + "attributes": { + "title": "Requests", + "kibanaSavedObjectMeta": { + "searchSourceJSON": "{\"query\":{\"query\":\"\",\"language\":\"lucene\"},\"filter\":[],\"highlightAll\":true,\"version\":true}" + }, + "version": 1 + }, + "coreMigrationVersion": "8.4.0", + "id": "space2-dashboard-id", + "migrationVersion": { + "dashboard": "8.4.0" + }, + "type": "dashboard", + "updated_at": "2017-09-21T18:49:16.270Z", + "version": "WzUyMCwxXQ==" +} + +{ + "attributes": { + "title": "A shared saved-object only in space_2" + }, + "id": "only_space_2", + "type": "sharedtype", + "updated_at": "2017-09-21T18:59:16.270Z", + "version": "WzQ4OCwxXQ==" +} diff --git a/x-pack/test/saved_object_api_integration/common/lib/test_data_loader.ts b/x-pack/test/saved_object_api_integration/common/lib/test_data_loader.ts index 4b25c722603c8..e7ff86beacfd8 100644 --- a/x-pack/test/saved_object_api_integration/common/lib/test_data_loader.ts +++ b/x-pack/test/saved_object_api_integration/common/lib/test_data_loader.ts @@ -83,14 +83,14 @@ export function getTestDataLoader({ getService }: FtrProviderContext) { log.debug('Loading test data for the following spaces: default, space_1 and space_2'); await Promise.all([ kbnServer.importExport.load( - 'x-pack/test/spaces_api_integration/common/fixtures/kbn_archiver/default_space.json' + 'x-pack/test/saved_object_api_integration/common/fixtures/kbn_archiver/default_space.json', ), kbnServer.importExport.load( - 'x-pack/test/spaces_api_integration/common/fixtures/kbn_archiver/space_1.json', + 'x-pack/test/saved_object_api_integration/common/fixtures/kbn_archiver/space_1.json', { space: SPACE_1.id } ), kbnServer.importExport.load( - 'x-pack/test/spaces_api_integration/common/fixtures/kbn_archiver/space_2.json', + 'x-pack/test/saved_object_api_integration/common/fixtures/kbn_archiver/space_2.json', { space: SPACE_2.id } ), ]); diff --git a/x-pack/test/saved_object_api_integration/common/suites/bulk_get.ts b/x-pack/test/saved_object_api_integration/common/suites/bulk_get.ts index 34eb043f165f3..047be8a576bf2 100644 --- a/x-pack/test/saved_object_api_integration/common/suites/bulk_get.ts +++ b/x-pack/test/saved_object_api_integration/common/suites/bulk_get.ts @@ -95,8 +95,15 @@ export function bulkGetTestSuiteFactory(context: FtrProviderContext) { const { user, spaceId = SPACES.DEFAULT.spaceId, tests } = definition; describeFn(description, () => { - before(async () => await testDataLoader.beforeEach()); - after(async () => await testDataLoader.afterEach()); + before(async () => { + await testDataLoader.before(); + await testDataLoader.beforeEach(); + }); + + after(async () => { + await testDataLoader.after(); + await testDataLoader.afterEach(); + }); for (const test of tests) { it(`should return ${test.responseStatusCode} ${test.title}`, async () => { From 4a12e5fbfb4e4a638c66a3938403acb9927952da Mon Sep 17 00:00:00 2001 From: kibanamachine <42973632+kibanamachine@users.noreply.github.com> Date: Thu, 22 Sep 2022 18:45:17 +0000 Subject: [PATCH 4/7] [CI] Auto-commit changed files from 'node scripts/precommit_hook.js --ref HEAD~1..HEAD --fix' --- .../saved_object_api_integration/common/lib/test_data_loader.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x-pack/test/saved_object_api_integration/common/lib/test_data_loader.ts b/x-pack/test/saved_object_api_integration/common/lib/test_data_loader.ts index e7ff86beacfd8..b1e051edc3d42 100644 --- a/x-pack/test/saved_object_api_integration/common/lib/test_data_loader.ts +++ b/x-pack/test/saved_object_api_integration/common/lib/test_data_loader.ts @@ -83,7 +83,7 @@ export function getTestDataLoader({ getService }: FtrProviderContext) { log.debug('Loading test data for the following spaces: default, space_1 and space_2'); await Promise.all([ kbnServer.importExport.load( - 'x-pack/test/saved_object_api_integration/common/fixtures/kbn_archiver/default_space.json', + 'x-pack/test/saved_object_api_integration/common/fixtures/kbn_archiver/default_space.json' ), kbnServer.importExport.load( 'x-pack/test/saved_object_api_integration/common/fixtures/kbn_archiver/space_1.json', From 7c482ef81d3fea53b079e5b0bce0104273f908b1 Mon Sep 17 00:00:00 2001 From: Kurt Date: Wed, 28 Sep 2022 14:19:06 -0400 Subject: [PATCH 5/7] Adding generic TestDataLoader --- .../common/lib/test_data_loader.ts | 38 +++--- .../common/lib/test_data_loader.ts | 128 ------------------ .../common/suites/bulk_get.ts | 22 ++- .../common/suites/copy_to_space.ts | 24 +++- .../suites/resolve_copy_to_space_conflicts.ts | 21 ++- 5 files changed, 76 insertions(+), 157 deletions(-) rename x-pack/test/{spaces_api_integration => }/common/lib/test_data_loader.ts (81%) delete mode 100644 x-pack/test/saved_object_api_integration/common/lib/test_data_loader.ts diff --git a/x-pack/test/spaces_api_integration/common/lib/test_data_loader.ts b/x-pack/test/common/lib/test_data_loader.ts similarity index 81% rename from x-pack/test/spaces_api_integration/common/lib/test_data_loader.ts rename to x-pack/test/common/lib/test_data_loader.ts index 4b25c722603c8..daacaae035912 100644 --- a/x-pack/test/spaces_api_integration/common/lib/test_data_loader.ts +++ b/x-pack/test/common/lib/test_data_loader.ts @@ -5,16 +5,14 @@ * 2.0. */ -import { FtrProviderContext } from '../ftr_provider_context'; - -const SPACE_1 = { +export const SPACE_1 = { id: 'space_1', name: 'Space 1', description: 'This is the first test space', disabledFeatures: [], }; -const SPACE_2 = { +export const SPACE_2 = { id: 'space_2', name: 'Space 2', description: 'This is the second test space', @@ -64,7 +62,8 @@ const OBJECTS_TO_SHARE: Array<{ }, ]; -export function getTestDataLoader({ getService }: FtrProviderContext) { +// @ts-ignore +export function getTestDataLoader({ getService }) { const spacesService = getService('spaces'); const kbnServer = getService('kibanaServer'); const supertest = getService('supertest'); @@ -79,21 +78,20 @@ export function getTestDataLoader({ getService }: FtrProviderContext) { await Promise.all([spacesService.delete(SPACE_1.id), spacesService.delete(SPACE_2.id)]); }, - beforeEach: async () => { + beforeEach: async (spaceData: Array<{ spaceName: string | null; dataUrl: string }>) => { log.debug('Loading test data for the following spaces: default, space_1 and space_2'); - await Promise.all([ - kbnServer.importExport.load( - 'x-pack/test/spaces_api_integration/common/fixtures/kbn_archiver/default_space.json' - ), - kbnServer.importExport.load( - 'x-pack/test/spaces_api_integration/common/fixtures/kbn_archiver/space_1.json', - { space: SPACE_1.id } - ), - kbnServer.importExport.load( - 'x-pack/test/spaces_api_integration/common/fixtures/kbn_archiver/space_2.json', - { space: SPACE_2.id } - ), - ]); + + await Promise.all( + spaceData.map((spaceDataObj) => { + if (spaceDataObj.spaceName) { + return kbnServer.importExport.load(spaceDataObj.dataUrl, { + space: spaceDataObj.spaceName, + }); + } else { + return kbnServer.importExport.load(spaceDataObj.dataUrl); + } + }) + ); // Adjust spaces for the imported saved objects. for (const { objects, spacesToAdd = [], spacesToRemove = [] } of OBJECTS_TO_SHARE) { @@ -113,7 +111,7 @@ export function getTestDataLoader({ getService }: FtrProviderContext) { afterEach: async () => { const allSpacesIds = [ - ...(await spacesService.getAll()).map((space) => space.id), + ...(await spacesService.getAll()).map((space: { id: string }) => space.id), 'non_existent_space', ]; log.debug(`Removing data from the following spaces: ${allSpacesIds.join(', ')}`); diff --git a/x-pack/test/saved_object_api_integration/common/lib/test_data_loader.ts b/x-pack/test/saved_object_api_integration/common/lib/test_data_loader.ts deleted file mode 100644 index b1e051edc3d42..0000000000000 --- a/x-pack/test/saved_object_api_integration/common/lib/test_data_loader.ts +++ /dev/null @@ -1,128 +0,0 @@ -/* - * 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 { FtrProviderContext } from '../ftr_provider_context'; - -const SPACE_1 = { - id: 'space_1', - name: 'Space 1', - description: 'This is the first test space', - disabledFeatures: [], -}; - -const SPACE_2 = { - id: 'space_2', - name: 'Space 2', - description: 'This is the second test space', - disabledFeatures: [], -}; - -// Objects can only be imported in one space at a time. To have test saved objects -// that are shared in multiple spaces we should import all objects in the "original" -// spaces first and then share them to other spaces as a subsequent operation. -const OBJECTS_TO_SHARE: Array<{ - spacesToAdd?: string[]; - spacesToRemove?: string[]; - objects: Array<{ type: string; id: string }>; -}> = [ - { - spacesToAdd: ['*'], - spacesToRemove: ['default'], - objects: [ - { type: 'sharedtype', id: 'all_spaces' }, - { type: 'sharedtype', id: 'space_2_only_matching_origin' }, - { type: 'sharedtype', id: 'alias_delete_exclusive' }, - ], - }, - { - spacesToRemove: ['default'], - spacesToAdd: [SPACE_1.id, SPACE_2.id], - objects: [{ type: 'sharedtype', id: 'space_1_and_space_2' }], - }, - { - spacesToAdd: [SPACE_1.id, SPACE_2.id], - objects: [ - { type: 'sharedtype', id: 'each_space' }, - { type: 'sharedtype', id: 'conflict_2_all' }, - { type: 'sharedtype', id: 'alias_delete_inclusive' }, - ], - }, - { - spacesToAdd: [SPACE_1.id], - objects: [ - { type: 'sharedtype', id: 'conflict_1c_default_and_space_1' }, - { type: 'sharedtype', id: 'default_and_space_1' }, - ], - }, - { - spacesToAdd: [SPACE_2.id], - objects: [{ type: 'sharedtype', id: 'default_and_space_2' }], - }, -]; - -export function getTestDataLoader({ getService }: FtrProviderContext) { - const spacesService = getService('spaces'); - const kbnServer = getService('kibanaServer'); - const supertest = getService('supertest'); - const log = getService('log'); - - return { - before: async () => { - await Promise.all([await spacesService.create(SPACE_1), await spacesService.create(SPACE_2)]); - }, - - after: async () => { - await Promise.all([spacesService.delete(SPACE_1.id), spacesService.delete(SPACE_2.id)]); - }, - - beforeEach: async () => { - log.debug('Loading test data for the following spaces: default, space_1 and space_2'); - await Promise.all([ - kbnServer.importExport.load( - 'x-pack/test/saved_object_api_integration/common/fixtures/kbn_archiver/default_space.json' - ), - kbnServer.importExport.load( - 'x-pack/test/saved_object_api_integration/common/fixtures/kbn_archiver/space_1.json', - { space: SPACE_1.id } - ), - kbnServer.importExport.load( - 'x-pack/test/saved_object_api_integration/common/fixtures/kbn_archiver/space_2.json', - { space: SPACE_2.id } - ), - ]); - - // Adjust spaces for the imported saved objects. - for (const { objects, spacesToAdd = [], spacesToRemove = [] } of OBJECTS_TO_SHARE) { - log.debug( - `Updating spaces for the following objects (add: [${spacesToAdd.join( - ', ' - )}], remove: [${spacesToRemove.join(', ')}]): ${objects - .map(({ type, id }) => `${type}:${id}`) - .join(', ')}` - ); - await supertest - .post('/api/spaces/_update_objects_spaces') - .send({ objects, spacesToAdd, spacesToRemove }) - .expect(200); - } - }, - - afterEach: async () => { - const allSpacesIds = [ - ...(await spacesService.getAll()).map((space) => space.id), - 'non_existent_space', - ]; - log.debug(`Removing data from the following spaces: ${allSpacesIds.join(', ')}`); - await Promise.all( - allSpacesIds.flatMap((spaceId) => [ - kbnServer.savedObjects.cleanStandardList({ space: spaceId }), - kbnServer.savedObjects.clean({ space: spaceId, types: ['sharedtype', 'isolatedtype'] }), - ]) - ); - }, - }; -} diff --git a/x-pack/test/saved_object_api_integration/common/suites/bulk_get.ts b/x-pack/test/saved_object_api_integration/common/suites/bulk_get.ts index 047be8a576bf2..fbff3745c1d06 100644 --- a/x-pack/test/saved_object_api_integration/common/suites/bulk_get.ts +++ b/x-pack/test/saved_object_api_integration/common/suites/bulk_get.ts @@ -6,12 +6,12 @@ */ import expect from '@kbn/expect'; +import { getTestDataLoader, SPACE_1, SPACE_2 } from '../../../common/lib/test_data_loader'; import { SAVED_OBJECT_TEST_CASES as CASES } from '../lib/saved_object_test_cases'; import { SPACES } from '../lib/spaces'; import { expectResponses, getUrlPrefix, getTestTitle } from '../lib/saved_object_test_utils'; import { ExpectResponseBody, TestCase, TestDefinition, TestSuite } from '../lib/types'; -import { FtrProviderContext } from '../ftr_provider_context'; -import { getTestDataLoader } from '../lib/test_data_loader'; +import type { FtrProviderContext } from '../ftr_provider_context'; export interface BulkGetTestDefinition extends TestDefinition { request: Array<{ type: string; id: string }>; @@ -97,7 +97,23 @@ export function bulkGetTestSuiteFactory(context: FtrProviderContext) { describeFn(description, () => { before(async () => { await testDataLoader.before(); - await testDataLoader.beforeEach(); + await testDataLoader.beforeEach([ + { + spaceName: null, + dataUrl: + 'x-pack/test/saved_object_api_integration/common/fixtures/kbn_archiver/default_space.json', + }, + { + spaceName: SPACE_1.id, + dataUrl: + 'x-pack/test/saved_object_api_integration/common/fixtures/kbn_archiver/space_1.json', + }, + { + spaceName: SPACE_2.id, + dataUrl: + 'x-pack/test/saved_object_api_integration/common/fixtures/kbn_archiver/space_2.json', + }, + ]); }); after(async () => { diff --git a/x-pack/test/spaces_api_integration/common/suites/copy_to_space.ts b/x-pack/test/spaces_api_integration/common/suites/copy_to_space.ts index c781eff6d3272..c4b6239e46456 100644 --- a/x-pack/test/spaces_api_integration/common/suites/copy_to_space.ts +++ b/x-pack/test/spaces_api_integration/common/suites/copy_to_space.ts @@ -14,7 +14,7 @@ import { } from '@kbn/core/server'; import { getAggregatedSpaceData, getUrlPrefix } from '../lib/space_test_utils'; import { DescribeFn, TestDefinitionAuthentication } from '../lib/types'; -import { getTestDataLoader } from '../lib/test_data_loader'; +import { getTestDataLoader, SPACE_1, SPACE_2 } from '../../../common/lib/test_data_loader'; import { FtrProviderContext } from '../ftr_provider_context'; type TestResponse = Record; @@ -74,6 +74,21 @@ const UUID_PATTERN = new RegExp( /^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i ); +const SPACE_DATA_TO_LOAD: Array<{ spaceName: string | null; dataUrl: string }> = [ + { + spaceName: null, + dataUrl: 'x-pack/test/spaces_api_integration/common/fixtures/kbn_archiver/default_space.json', + }, + { + spaceName: SPACE_1.id, + dataUrl: 'x-pack/test/spaces_api_integration/common/fixtures/kbn_archiver/space_1.json', + }, + { + spaceName: SPACE_2.id, + dataUrl: 'x-pack/test/spaces_api_integration/common/fixtures/kbn_archiver/space_2.json', + }, +]; + const getDestinationWithoutConflicts = () => 'space_2'; const getDestinationWithConflicts = (originSpaceId?: string) => !originSpaceId || originSpaceId === DEFAULT_SPACE_ID ? 'space_1' : DEFAULT_SPACE_ID; @@ -756,7 +771,10 @@ export function copyToSpaceTestSuiteFactory(context: FtrProviderContext) { }); describe('single-namespace types', () => { - beforeEach(async () => await testDataLoader.beforeEach()); + beforeEach(async () => { + await testDataLoader.beforeEach(SPACE_DATA_TO_LOAD); + }); + afterEach(async () => await testDataLoader.afterEach()); const dashboardObject = { type: 'dashboard', id: `cts_dashboard_${spaceId}` }; @@ -898,7 +916,7 @@ export function copyToSpaceTestSuiteFactory(context: FtrProviderContext) { const spaces = ['space_2']; const includeReferences = false; describe(`multi-namespace types with overwrite=${overwrite} and createNewCopies=${createNewCopies}`, () => { - before(async () => await testDataLoader.beforeEach()); + before(async () => await testDataLoader.beforeEach(SPACE_DATA_TO_LOAD)); after(async () => await testDataLoader.afterEach()); const testCases = tests.multiNamespaceTestCases(overwrite, createNewCopies); diff --git a/x-pack/test/spaces_api_integration/common/suites/resolve_copy_to_space_conflicts.ts b/x-pack/test/spaces_api_integration/common/suites/resolve_copy_to_space_conflicts.ts index 58a434bd0ca91..49f1a06a5b12f 100644 --- a/x-pack/test/spaces_api_integration/common/suites/resolve_copy_to_space_conflicts.ts +++ b/x-pack/test/spaces_api_integration/common/suites/resolve_copy_to_space_conflicts.ts @@ -12,7 +12,7 @@ import { CopyResponse } from '@kbn/spaces-plugin/server/lib/copy_to_spaces'; import { getUrlPrefix } from '../lib/space_test_utils'; import { DescribeFn, TestDefinitionAuthentication } from '../lib/types'; import { FtrProviderContext } from '../ftr_provider_context'; -import { getTestDataLoader } from '../lib/test_data_loader'; +import { getTestDataLoader, SPACE_1, SPACE_2 } from '../../../common/lib/test_data_loader'; type TestResponse = Record; @@ -44,6 +44,21 @@ interface ResolveCopyToSpaceTestDefinition { const NON_EXISTENT_SPACE_ID = 'non_existent_space'; +const SPACE_DATA_TO_LOAD: Array<{ spaceName: string | null; dataUrl: string }> = [ + { + spaceName: null, + dataUrl: 'x-pack/test/spaces_api_integration/common/fixtures/kbn_archiver/default_space.json', + }, + { + spaceName: SPACE_1.id, + dataUrl: 'x-pack/test/spaces_api_integration/common/fixtures/kbn_archiver/space_1.json', + }, + { + spaceName: SPACE_2.id, + dataUrl: 'x-pack/test/spaces_api_integration/common/fixtures/kbn_archiver/space_2.json', + }, +]; + const getDestinationSpace = (originSpaceId?: string) => { if (!originSpaceId || originSpaceId === DEFAULT_SPACE_ID) { return 'space_1'; @@ -487,7 +502,7 @@ export function resolveCopyToSpaceConflictsSuite(context: FtrProviderContext) { }); describe('single-namespace types', () => { - beforeEach(async () => await testDataLoader.beforeEach()); + beforeEach(async () => await testDataLoader.beforeEach(SPACE_DATA_TO_LOAD)); afterEach(async () => await testDataLoader.afterEach()); const dashboardObject = { type: 'dashboard', id: `cts_dashboard_${spaceId}` }; @@ -630,7 +645,7 @@ export function resolveCopyToSpaceConflictsSuite(context: FtrProviderContext) { const includeReferences = false; const createNewCopies = false; describe(`multi-namespace types with "overwrite" retry`, () => { - before(async () => await testDataLoader.beforeEach()); + before(async () => await testDataLoader.beforeEach(SPACE_DATA_TO_LOAD)); after(async () => await testDataLoader.afterEach()); const testCases = tests.multiNamespaceTestCases(); From 5137f46d00e2b5c71cd6e13c936727291a0b9622 Mon Sep 17 00:00:00 2001 From: Kurt Date: Fri, 30 Sep 2022 16:54:59 -0400 Subject: [PATCH 6/7] Importing just the type per PR feedback --- .../test/spaces_api_integration/common/suites/copy_to_space.ts | 2 +- .../common/suites/resolve_copy_to_space_conflicts.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/x-pack/test/spaces_api_integration/common/suites/copy_to_space.ts b/x-pack/test/spaces_api_integration/common/suites/copy_to_space.ts index c4b6239e46456..7a44af15af085 100644 --- a/x-pack/test/spaces_api_integration/common/suites/copy_to_space.ts +++ b/x-pack/test/spaces_api_integration/common/suites/copy_to_space.ts @@ -15,7 +15,7 @@ import { import { getAggregatedSpaceData, getUrlPrefix } from '../lib/space_test_utils'; import { DescribeFn, TestDefinitionAuthentication } from '../lib/types'; import { getTestDataLoader, SPACE_1, SPACE_2 } from '../../../common/lib/test_data_loader'; -import { FtrProviderContext } from '../ftr_provider_context'; +import type { FtrProviderContext } from '../ftr_provider_context'; type TestResponse = Record; diff --git a/x-pack/test/spaces_api_integration/common/suites/resolve_copy_to_space_conflicts.ts b/x-pack/test/spaces_api_integration/common/suites/resolve_copy_to_space_conflicts.ts index 49f1a06a5b12f..2e18dc53f0ba5 100644 --- a/x-pack/test/spaces_api_integration/common/suites/resolve_copy_to_space_conflicts.ts +++ b/x-pack/test/spaces_api_integration/common/suites/resolve_copy_to_space_conflicts.ts @@ -11,7 +11,7 @@ import { DEFAULT_SPACE_ID } from '@kbn/spaces-plugin/common/constants'; import { CopyResponse } from '@kbn/spaces-plugin/server/lib/copy_to_spaces'; import { getUrlPrefix } from '../lib/space_test_utils'; import { DescribeFn, TestDefinitionAuthentication } from '../lib/types'; -import { FtrProviderContext } from '../ftr_provider_context'; +import type { FtrProviderContext } from '../ftr_provider_context'; import { getTestDataLoader, SPACE_1, SPACE_2 } from '../../../common/lib/test_data_loader'; type TestResponse = Record; From f05a1e469c29f5e4decc31b5f8f9d1b91774e673 Mon Sep 17 00:00:00 2001 From: Kurt Date: Mon, 3 Oct 2022 10:08:51 -0400 Subject: [PATCH 7/7] Changing testDataLoader function names to be more descriptive --- x-pack/test/common/lib/test_data_loader.ts | 10 ++++++---- .../common/suites/bulk_get.ts | 8 ++++---- .../common/suites/copy_to_space.ts | 12 ++++++------ .../common/suites/resolve_copy_to_space_conflicts.ts | 10 ++++++---- 4 files changed, 22 insertions(+), 18 deletions(-) diff --git a/x-pack/test/common/lib/test_data_loader.ts b/x-pack/test/common/lib/test_data_loader.ts index daacaae035912..61c8ff4c1bf52 100644 --- a/x-pack/test/common/lib/test_data_loader.ts +++ b/x-pack/test/common/lib/test_data_loader.ts @@ -70,15 +70,17 @@ export function getTestDataLoader({ getService }) { const log = getService('log'); return { - before: async () => { + createFtrSpaces: async () => { await Promise.all([await spacesService.create(SPACE_1), await spacesService.create(SPACE_2)]); }, - after: async () => { + deleteFtrSpaces: async () => { await Promise.all([spacesService.delete(SPACE_1.id), spacesService.delete(SPACE_2.id)]); }, - beforeEach: async (spaceData: Array<{ spaceName: string | null; dataUrl: string }>) => { + createFtrSavedObjectsData: async ( + spaceData: Array<{ spaceName: string | null; dataUrl: string }> + ) => { log.debug('Loading test data for the following spaces: default, space_1 and space_2'); await Promise.all( @@ -109,7 +111,7 @@ export function getTestDataLoader({ getService }) { } }, - afterEach: async () => { + deleteFtrSavedObjectsData: async () => { const allSpacesIds = [ ...(await spacesService.getAll()).map((space: { id: string }) => space.id), 'non_existent_space', diff --git a/x-pack/test/saved_object_api_integration/common/suites/bulk_get.ts b/x-pack/test/saved_object_api_integration/common/suites/bulk_get.ts index fbff3745c1d06..c9cb3b9739eee 100644 --- a/x-pack/test/saved_object_api_integration/common/suites/bulk_get.ts +++ b/x-pack/test/saved_object_api_integration/common/suites/bulk_get.ts @@ -96,8 +96,8 @@ export function bulkGetTestSuiteFactory(context: FtrProviderContext) { describeFn(description, () => { before(async () => { - await testDataLoader.before(); - await testDataLoader.beforeEach([ + await testDataLoader.createFtrSpaces(); + await testDataLoader.createFtrSavedObjectsData([ { spaceName: null, dataUrl: @@ -117,8 +117,8 @@ export function bulkGetTestSuiteFactory(context: FtrProviderContext) { }); after(async () => { - await testDataLoader.after(); - await testDataLoader.afterEach(); + await testDataLoader.deleteFtrSpaces(); + await testDataLoader.deleteFtrSavedObjectsData(); }); for (const test of tests) { diff --git a/x-pack/test/spaces_api_integration/common/suites/copy_to_space.ts b/x-pack/test/spaces_api_integration/common/suites/copy_to_space.ts index 7a44af15af085..4c5ae878bbf6e 100644 --- a/x-pack/test/spaces_api_integration/common/suites/copy_to_space.ts +++ b/x-pack/test/spaces_api_integration/common/suites/copy_to_space.ts @@ -763,19 +763,19 @@ export function copyToSpaceTestSuiteFactory(context: FtrProviderContext) { // test data only allows for the following spaces as the copy origin expect(['default', 'space_1']).to.contain(spaceId); - await testDataLoader.before(); + await testDataLoader.createFtrSpaces(); }); after(async () => { - await testDataLoader.after(); + await testDataLoader.deleteFtrSpaces(); }); describe('single-namespace types', () => { beforeEach(async () => { - await testDataLoader.beforeEach(SPACE_DATA_TO_LOAD); + await testDataLoader.createFtrSavedObjectsData(SPACE_DATA_TO_LOAD); }); - afterEach(async () => await testDataLoader.afterEach()); + afterEach(async () => await testDataLoader.deleteFtrSavedObjectsData()); const dashboardObject = { type: 'dashboard', id: `cts_dashboard_${spaceId}` }; @@ -916,8 +916,8 @@ export function copyToSpaceTestSuiteFactory(context: FtrProviderContext) { const spaces = ['space_2']; const includeReferences = false; describe(`multi-namespace types with overwrite=${overwrite} and createNewCopies=${createNewCopies}`, () => { - before(async () => await testDataLoader.beforeEach(SPACE_DATA_TO_LOAD)); - after(async () => await testDataLoader.afterEach()); + before(async () => await testDataLoader.createFtrSavedObjectsData(SPACE_DATA_TO_LOAD)); + after(async () => await testDataLoader.deleteFtrSavedObjectsData()); const testCases = tests.multiNamespaceTestCases(overwrite, createNewCopies); testCases.forEach(({ testTitle, objects, statusCode, response }) => { diff --git a/x-pack/test/spaces_api_integration/common/suites/resolve_copy_to_space_conflicts.ts b/x-pack/test/spaces_api_integration/common/suites/resolve_copy_to_space_conflicts.ts index 2e18dc53f0ba5..5f2c361714c49 100644 --- a/x-pack/test/spaces_api_integration/common/suites/resolve_copy_to_space_conflicts.ts +++ b/x-pack/test/spaces_api_integration/common/suites/resolve_copy_to_space_conflicts.ts @@ -502,8 +502,10 @@ export function resolveCopyToSpaceConflictsSuite(context: FtrProviderContext) { }); describe('single-namespace types', () => { - beforeEach(async () => await testDataLoader.beforeEach(SPACE_DATA_TO_LOAD)); - afterEach(async () => await testDataLoader.afterEach()); + beforeEach( + async () => await testDataLoader.createFtrSavedObjectsData(SPACE_DATA_TO_LOAD) + ); + afterEach(async () => await testDataLoader.deleteFtrSavedObjectsData()); const dashboardObject = { type: 'dashboard', id: `cts_dashboard_${spaceId}` }; const visualizationObject = { type: 'visualization', id: `cts_vis_3_${spaceId}` }; @@ -645,8 +647,8 @@ export function resolveCopyToSpaceConflictsSuite(context: FtrProviderContext) { const includeReferences = false; const createNewCopies = false; describe(`multi-namespace types with "overwrite" retry`, () => { - before(async () => await testDataLoader.beforeEach(SPACE_DATA_TO_LOAD)); - after(async () => await testDataLoader.afterEach()); + before(async () => await testDataLoader.createFtrSavedObjectsData(SPACE_DATA_TO_LOAD)); + after(async () => await testDataLoader.deleteFtrSavedObjectsData()); const testCases = tests.multiNamespaceTestCases(); testCases.forEach(({ testTitle, objects, retries, statusCode, response }) => {