Skip to content

Commit

Permalink
install packages before test suite runs
Browse files Browse the repository at this point in the history
  • Loading branch information
klacabane committed Sep 6, 2023
1 parent ff22826 commit e2cc808
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 13 deletions.
5 changes: 4 additions & 1 deletion x-pack/test/monitoring_api_integration/apis/apm/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@
*/

import { FtrProviderContext } from '../../../api_integration/ftr_provider_context';
import { installPackage } from '../../packages';

export default function ({ loadTestFile }: FtrProviderContext) {
export default function ({ loadTestFile, getService }: FtrProviderContext) {
describe('APM', () => {
before(() => installPackage(getService('supertest'), 'beat'));

loadTestFile(require.resolve('./overview'));
loadTestFile(require.resolve('./instances'));
});
Expand Down
5 changes: 4 additions & 1 deletion x-pack/test/monitoring_api_integration/apis/beats/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@
*/

import { FtrProviderContext } from '../../../api_integration/ftr_provider_context';
import { installPackage } from '../../packages';

export default function ({ loadTestFile }: FtrProviderContext) {
export default function ({ loadTestFile, getService }: FtrProviderContext) {
describe('Beats', () => {
before(() => installPackage(getService('supertest'), 'beat'));

loadTestFile(require.resolve('./overview'));
loadTestFile(require.resolve('./beats'));
loadTestFile(require.resolve('./beat'));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@
*/

import { FtrProviderContext } from '../../../api_integration/ftr_provider_context';
import { installPackage } from '../../packages';

export default function ({ loadTestFile }: FtrProviderContext) {
export default function ({ loadTestFile, getService }: FtrProviderContext) {
describe('Elasticsearch', () => {
before(() => installPackage(getService('supertest'), 'elasticsearch'));

loadTestFile(require.resolve('./ccr'));
loadTestFile(require.resolve('./indices'));
loadTestFile(require.resolve('./ml_jobs'));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@
*/

import { FtrProviderContext } from '../../../api_integration/ftr_provider_context';
import { installPackage } from '../../packages';

export default function ({ loadTestFile }: FtrProviderContext) {
export default function ({ loadTestFile, getService }: FtrProviderContext) {
describe('Enterprisesearch', () => {
before(() => installPackage(getService('supertest'), 'enterprisesearch'));

loadTestFile(require.resolve('./overview'));
});
}
5 changes: 4 additions & 1 deletion x-pack/test/monitoring_api_integration/apis/kibana/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@
*/

import { FtrProviderContext } from '../../../api_integration/ftr_provider_context';
import { installPackage } from '../../packages';

export default function ({ loadTestFile }: FtrProviderContext) {
export default function ({ loadTestFile, getService }: FtrProviderContext) {
describe('Kibana', () => {
before(() => installPackage(getService('supertest'), 'kibana'));

loadTestFile(require.resolve('./overview'));
loadTestFile(require.resolve('./instances'));
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@
*/

import { FtrProviderContext } from '../../../api_integration/ftr_provider_context';
import { installPackage } from '../../packages';

export default function ({ loadTestFile }: FtrProviderContext) {
export default function ({ loadTestFile, getService }: FtrProviderContext) {
describe('Logstash', () => {
before(() => installPackage(getService('supertest'), 'logstash'));

loadTestFile(require.resolve('./overview'));
loadTestFile(require.resolve('./nodes'));
loadTestFile(require.resolve('./pipelines'));
Expand Down
8 changes: 1 addition & 7 deletions x-pack/test/monitoring_api_integration/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@

import { FtrConfigProviderContext } from '@kbn/test';

import { bundledPackagesLocation, getPackagesArgs } from './packages';

export default async function ({ readConfigFile }: FtrConfigProviderContext) {
const xPackAPITestsConfig = await readConfigFile(require.resolve('../api_integration/config.ts'));

Expand All @@ -22,11 +20,7 @@ export default async function ({ readConfigFile }: FtrConfigProviderContext) {
esTestCluster: xPackAPITestsConfig.get('esTestCluster'),
kbnTestServer: {
...xPackAPITestsConfig.get('kbnTestServer'),
serverArgs: [
...xPackAPITestsConfig.get('kbnTestServer.serverArgs'),
`--xpack.fleet.developer.bundledPackageLocation=${bundledPackagesLocation}`,
...getPackagesArgs(),
],
serverArgs: [...xPackAPITestsConfig.get('kbnTestServer.serverArgs')],
},
};
}
27 changes: 27 additions & 0 deletions x-pack/test/monitoring_api_integration/packages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
*/

import path from 'path';
import { createReadStream } from 'fs';
import type SuperTest from 'supertest';

type SupportedPackage = 'beat' | 'elasticsearch' | 'enterprisesearch' | 'logstash' | 'kibana';

const PACKAGES = [
{ name: 'beat', version: '0.1.3' },
Expand All @@ -25,3 +29,26 @@ export const getPackagesArgs = (): string[] => {
};

export const bundledPackagesLocation = path.join(path.dirname(__filename), '/fixtures/packages');

export function installPackage(
supertest: SuperTest.SuperTest<SuperTest.Test>,
packageName: SupportedPackage
) {
const pkg = PACKAGES.find(({ name }) => name === packageName);
const request = supertest
.post('/api/fleet/epm/packages')
.set('kbn-xsrf', 'xxx')
.set('content-type', 'application/zip');

return new Promise<void>((resolve, reject) => {
createReadStream(path.join(bundledPackagesLocation, `${pkg!.name}-${pkg!.version}.zip`))
.on('data', (chunk) => request.write(chunk))
.on('end', () => {
request
.send()
.expect(200)
.then(() => resolve())
.catch(reject);
});
});
}

0 comments on commit e2cc808

Please sign in to comment.