From 4f130ad8b68c452324e0bc60da07bc715371575c Mon Sep 17 00:00:00 2001 From: Kurt Date: Tue, 4 Oct 2022 08:50:12 -0400 Subject: [PATCH] Removing esArchiver in favor of testDataLoader for `bulk_get` Saved Objects integration tests (#140998) * Removing esArchiver in favor of testDataLoader * [CI] Auto-commit changed files from 'node scripts/precommit_hook.js --ref HEAD~1..HEAD --fix' * Adding test data for loader * [CI] Auto-commit changed files from 'node scripts/precommit_hook.js --ref HEAD~1..HEAD --fix' * Adding generic TestDataLoader * Importing just the type per PR feedback * Changing testDataLoader function names to be more descriptive Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com> Co-authored-by: Larry Gregory Co-authored-by: Thomas Watson --- .../common/lib/test_data_loader.ts | 46 ++--- .../fixtures/kbn_archiver/default_space.json | 163 ++++++++++++++++++ .../common/fixtures/kbn_archiver/space_1.json | 72 ++++++++ .../common/fixtures/kbn_archiver/space_2.json | 58 +++++++ .../common/suites/bulk_get.ts | 43 +++-- .../security_and_spaces/apis/bulk_get.ts | 11 +- .../spaces_only/apis/bulk_get.ts | 7 +- .../common/suites/copy_to_space.ts | 34 +++- .../suites/resolve_copy_to_space_conflicts.ts | 29 +++- 9 files changed, 401 insertions(+), 62 deletions(-) rename x-pack/test/{spaces_api_integration => }/common/lib/test_data_loader.ts (78%) 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/spaces_api_integration/common/lib/test_data_loader.ts b/x-pack/test/common/lib/test_data_loader.ts similarity index 78% 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 3ff108af5bf89..4627fbc00fce3 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', @@ -56,36 +54,38 @@ 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'); 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 () => { + 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([ - 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) { @@ -103,9 +103,9 @@ export function getTestDataLoader({ getService }: FtrProviderContext) { } }, - afterEach: async () => { + deleteFtrSavedObjectsData: 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/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/suites/bulk_get.ts b/x-pack/test/saved_object_api_integration/common/suites/bulk_get.ts index 10709a6f20916..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 @@ -6,11 +6,12 @@ */ import expect from '@kbn/expect'; -import { SuperTest } from 'supertest'; +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 type { FtrProviderContext } from '../ftr_provider_context'; export interface BulkGetTestDefinition extends TestDefinition { request: Array<{ type: string; id: string }>; @@ -33,7 +34,10 @@ 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 +95,31 @@ 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.createFtrSpaces(); + await testDataLoader.createFtrSavedObjectsData([ + { + 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 () => { + await testDataLoader.deleteFtrSpaces(); + await testDataLoader.deleteFtrSavedObjectsData(); + }); 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 1ffbd239624d2..972b8f68a9851 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,9 @@ 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..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 @@ -55,11 +55,8 @@ 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'); - - const { addTests, createTestDefinitions } = bulkGetTestSuiteFactory(esArchiver, supertest); +export default function (context: FtrProviderContext) { + const { addTests, createTestDefinitions } = bulkGetTestSuiteFactory(context); const createTests = (spaceId: string) => { const testCases = createTestCases(spaceId); return createTestDefinitions(testCases, false, { singleRequest: true }); 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 345f19b950c77..c2c04a8aa93c4 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,8 +14,8 @@ import { DEFAULT_SPACE_ID } from '../../../../plugins/spaces/common/constants'; import { CopyResponse } from '../../../../plugins/spaces/server/lib/copy_to_spaces'; import { getUrlPrefix } from '../lib/space_test_utils'; import { DescribeFn, TestDefinitionAuthentication } from '../lib/types'; -import { getTestDataLoader } from '../lib/test_data_loader'; -import { FtrProviderContext } from '../ftr_provider_context'; +import { getTestDataLoader, SPACE_1, SPACE_2 } from '../../../common/lib/test_data_loader'; +import type { FtrProviderContext } from '../ftr_provider_context'; type TestResponse = Record; @@ -72,6 +72,21 @@ const INITIAL_COUNTS: Record> = { space_2: { dashboard: 1 }, }; +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; @@ -627,16 +642,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()); - 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' }; @@ -777,8 +795,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()); - 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 ef17fa9fe2e4a..1b4f7bc642401 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,8 +11,8 @@ import { DEFAULT_SPACE_ID } from '../../../../plugins/spaces/common/constants'; import { CopyResponse } from '../../../../plugins/spaces/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 type { FtrProviderContext } from '../ftr_provider_context'; +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'; @@ -432,8 +447,10 @@ export function resolveCopyToSpaceConflictsSuite(context: FtrProviderContext) { }); describe('single-namespace types', () => { - beforeEach(async () => await testDataLoader.beforeEach()); - 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' }; const visualizationObject = { type: 'visualization', id: 'cts_vis_3' }; @@ -522,8 +539,8 @@ export function resolveCopyToSpaceConflictsSuite(context: FtrProviderContext) { const includeReferences = false; const createNewCopies = false; describe(`multi-namespace types with "overwrite" retry`, () => { - before(async () => await testDataLoader.beforeEach()); - 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 }) => {