Skip to content

Commit

Permalink
Removing esArchiver from bulkCreate (#142676)
Browse files Browse the repository at this point in the history
  • Loading branch information
kc13greiner authored Oct 5, 2022
1 parent 9394228 commit 035a433
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
*/

import expect from '@kbn/expect';
import { SuperTest } from 'supertest';
import { SavedObjectsErrorHelpers } from '@kbn/core/server';
import { SAVED_OBJECT_TEST_CASES as CASES } from '../lib/saved_object_test_cases';
import { SPACES, ALL_SPACES_ID } from '../lib/spaces';
Expand All @@ -17,6 +16,8 @@ import {
getRedactedNamespaces,
} from '../lib/saved_object_test_utils';
import { ExpectResponseBody, TestCase, TestDefinition, TestSuite, TestUser } from '../lib/types';
import { FtrProviderContext } from '../ftr_provider_context';
import { getTestDataLoader, SPACE_1, SPACE_2 } from '../../../common/lib/test_data_loader';

const {
DEFAULT: { spaceId: DEFAULT_SPACE_ID },
Expand Down Expand Up @@ -85,7 +86,10 @@ const createRequest = ({ type, id, initialNamespaces }: BulkCreateTestCase) => (
...(initialNamespaces && { initialNamespaces }),
});

export function bulkCreateTestSuiteFactory(esArchiver: any, supertest: SuperTest<any>) {
export function bulkCreateTestSuiteFactory(context: FtrProviderContext) {
const testDataLoader = getTestDataLoader(context);
const supertest = context.getService('supertestWithoutAuth');

const expectSavedObjectForbidden = expectResponses.forbiddenTypes('bulk_create');
const expectResponseBody =
(
Expand Down Expand Up @@ -193,16 +197,31 @@ export function bulkCreateTestSuiteFactory(esArchiver: any, supertest: SuperTest
const { user, spaceId = SPACES.DEFAULT.spaceId, tests } = definition;

describeFn(description, () => {
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();
});

const attrs = { attributes: { [NEW_ATTRIBUTE_KEY]: NEW_ATTRIBUTE_VAL } };

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,9 @@ const createTestCases = (overwrite: boolean, spaceId: string) => {
return { normalTypes, crossNamespace, hiddenType, allTypes };
};

export default function ({ getService }: FtrProviderContext) {
const supertest = getService('supertestWithoutAuth');
const esArchiver = getService('esArchiver');

export default function (context: FtrProviderContext) {
const { addTests, createTestDefinitions, expectSavedObjectForbidden } =
bulkCreateTestSuiteFactory(esArchiver, supertest);
bulkCreateTestSuiteFactory(context);
const createTests = (overwrite: boolean, spaceId: string, user: TestUser) => {
const { normalTypes, crossNamespace, hiddenType, allTypes } = createTestCases(
overwrite,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,8 @@ const createTestCases = (overwrite: boolean, spaceId: string) => {
];
};

export default function ({ getService }: FtrProviderContext) {
const supertest = getService('supertest');
const esArchiver = getService('esArchiver');

const { addTests, createTestDefinitions } = bulkCreateTestSuiteFactory(esArchiver, supertest);
export default function (context: FtrProviderContext) {
const { addTests, createTestDefinitions } = bulkCreateTestSuiteFactory(context);
const createTests = (overwrite: boolean, spaceId: string) => {
const testCases = createTestCases(overwrite, spaceId);
return createTestDefinitions(testCases, false, overwrite, {
Expand Down

0 comments on commit 035a433

Please sign in to comment.