Skip to content

Commit

Permalink
Add Ingest setup to Endpoint FTR tests.
Browse files Browse the repository at this point in the history
Refactor start method
  • Loading branch information
John Schulz committed Jun 18, 2020
1 parent ab0217e commit e10df84
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 14 deletions.
30 changes: 19 additions & 11 deletions x-pack/plugins/ingest_manager/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,19 +75,27 @@ export class IngestManagerPlugin
}

public async start(core: CoreStart): Promise<IngestManagerStart> {
const permissionsResponse = await core.http.get<CheckPermissionsResponse>(
appRoutesService.getCheckPermissionsPath()
);
if (permissionsResponse.success) {
const successPromise = core.http
.post<PostIngestSetupResponse>(setupRouteService.getSetupPath())
.then(({ isInitialized }: { isInitialized: boolean }) => Promise.resolve(isInitialized))
.catch(Promise.reject);
let successPromise = Promise.resolve(false);
try {
const permissionsResponse = await core.http.get<CheckPermissionsResponse>(
appRoutesService.getCheckPermissionsPath()
);

return { success: successPromise, registerDatasource };
} else {
if (permissionsResponse.success) {
successPromise = core.http
.post<PostIngestSetupResponse>(setupRouteService.getSetupPath())
.then(({ isInitialized }: { isInitialized: boolean }) => Promise.resolve(isInitialized));
} else {
successPromise = Promise.reject(new Error(permissionsResponse.error));
}

return {
success: successPromise,
registerDatasource,
};
} catch (error) {
return {
success: Promise.reject(new Error(permissionsResponse.error)),
success: Promise.reject(error),
registerDatasource,
};
}
Expand Down
6 changes: 5 additions & 1 deletion x-pack/test/api_integration/apis/endpoint/policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ export default function ({ getService }: FtrProviderContext) {
const supertest = getService('supertest');
describe('Endpoint policy api', () => {
describe('GET /api/endpoint/policy_response', () => {
before(async () => await esArchiver.load('endpoint/policy', { useCreate: true }));
before(async () => {
const ingestManager = getService('ingestManager');
await ingestManager.setup();
await esArchiver.load('endpoint/policy', { useCreate: true });
});

// the endpoint uses data streams and es archiver does not support deleting them at the moment so we need
// to do it manually
Expand Down
7 changes: 5 additions & 2 deletions x-pack/test/security_solution_endpoint/apps/endpoint/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@
*/
import { FtrProviderContext } from '../../ftr_provider_context';

export default function ({ loadTestFile }: FtrProviderContext) {
export default function ({ loadTestFile, getService }: FtrProviderContext) {
describe('endpoint', function () {
this.tags('ciGroup7');

const ingestManager = getService('ingestManager');
before(async () => {
await ingestManager.setup();
});
loadTestFile(require.resolve('./endpoint_list'));
loadTestFile(require.resolve('./policy_list'));
loadTestFile(require.resolve('./policy_details'));
Expand Down
2 changes: 2 additions & 0 deletions x-pack/test/security_solution_endpoint/services/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { services as apiIntegrationServices } from '../../api_integration/services';
import { services as xPackFunctionalServices } from '../../functional/services';
import { EndpointPolicyTestResourcesProvider } from './endpoint_policy';

export const services = {
...xPackFunctionalServices,
ingestManager: apiIntegrationServices.ingestManager,
policyTestResources: EndpointPolicyTestResourcesProvider,
};

0 comments on commit e10df84

Please sign in to comment.