Skip to content

Commit

Permalink
Adding setup integration test
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathan-buttner committed Sep 22, 2020
1 parent 99f6aee commit 8a41396
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export interface InstallPackageResponse {
export interface IBulkInstallPackageError {
name: string;
statusCode: number;
error: string | Error;
error: string;
}

export interface BulkInstallPackageInfo {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,10 @@ export async function ensureInstalledDefaultPackages(

for (const resp of bulkResponse) {
if (isBulkInstallError(resp)) {
if (resp.error instanceof Error) {
throw resp.error;
} else {
throw new Error(resp.error);
}
throw new Error(resp.error);
} else {
// getInstallation can return undefined so we'll tack on the name so when we throw an error in setup we can
// reference the name of the package that we failed to retrieve the installation information for
const installation = getInstallationAndName(savedObjectsClient, resp.name);
installations.push(installation);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
export default function loadTests({ loadTestFile }) {
describe('EPM Endpoints', () => {
loadTestFile(require.resolve('./list'));
loadTestFile(require.resolve('./setup'));
loadTestFile(require.resolve('./get'));
loadTestFile(require.resolve('./file'));
//loadTestFile(require.resolve('./template'));
Expand Down
48 changes: 48 additions & 0 deletions x-pack/test/ingest_manager_api_integration/apis/epm/setup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

import expect from '@kbn/expect';
import { FtrProviderContext } from '../../../api_integration/ftr_provider_context';
import { skipIfNoDockerRegistry } from '../../helpers';
import { GetInfoResponse, Installed } from '../../../../plugins/ingest_manager/common';

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

describe('setup api', async () => {
skipIfNoDockerRegistry(providerContext);
describe('setup performs upgrades', async () => {
const oldEndpointVersion = '0.13.0';
beforeEach(async () => {
await supertest
.post(`/api/ingest_manager/epm/packages/endpoint-${oldEndpointVersion}`)
.set('kbn-xsrf', 'xxxx')
.send({ force: true })
.expect(200);
});
it('upgrades the endpoint package from 0.13.0 to the latest version available', async function () {
let { body }: { body: GetInfoResponse } = await supertest
.get(`/api/ingest_manager/epm/packages/endpoint-${oldEndpointVersion}`)
.expect(200);
const latestEndpointVersion = body.response.latestVersion;
log.info(`Endpoint package latest version: ${latestEndpointVersion}`);
// make sure we're actually doing an upgrade
expect(latestEndpointVersion).not.eql(oldEndpointVersion);
await supertest.post(`/api/ingest_manager/setup`).set('kbn-xsrf', 'xxxx').expect(200);

({ body } = await supertest
.get(`/api/ingest_manager/epm/packages/endpoint-${latestEndpointVersion}`)
.expect(200));
expect(body.response).to.have.property('savedObject');
expect((body.response as Installed).savedObject.attributes.install_version).to.eql(
latestEndpointVersion
);
});
});
});
}

0 comments on commit 8a41396

Please sign in to comment.