Skip to content

Commit

Permalink
[Fleet] Add integration test for epm install on multiple spaces
Browse files Browse the repository at this point in the history
  • Loading branch information
criamico committed May 5, 2023
1 parent 14f5b9e commit 3cd7f96
Show file tree
Hide file tree
Showing 4 changed files with 120 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ export default function (providerContext: FtrProviderContext) {
expect(body).to.eql({ data_streams: [] });
});

it('TESTME should return correct basic data stream information', async function () {
it('should return correct basic data stream information', async function () {
await seedDataStreams();
// we can't compare the array directly as the order is unpredictable
const expectedStreamsByDataset = keyBy(
Expand Down
1 change: 1 addition & 0 deletions x-pack/test/fleet_api_integration/apis/epm/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,6 @@ export default function loadTests({ loadTestFile, getService }) {
loadTestFile(require.resolve('./final_pipeline'));
loadTestFile(require.resolve('./custom_ingest_pipeline'));
loadTestFile(require.resolve('./verification_key_id'));
loadTestFile(require.resolve('./install_integration_in_multiple_spaces.ts'));
});
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import expect from '@kbn/expect';
import { FtrProviderContext } from '../../../api_integration/ftr_provider_context';
import { skipIfNoDockerRegistry } from '../../helpers';
import { setupFleetAndAgents } from '../agents/services';

const testSpaceId = 'fleet_test_space';

export default function (providerContext: FtrProviderContext) {
const { getService } = providerContext;
const kibanaServer = getService('kibanaServer');
const supertest = getService('supertest');
const dockerServers = getService('dockerServers');
const server = dockerServers.get('registry');
const pkgName = 'system';
const pkgVersion = '1.27.0';

const installPackage = async (name: string, version: string) => {
await supertest
.post(`/api/fleet/epm/packages/${name}/${version}`)
.set('kbn-xsrf', 'xxxx')
.send({ force: true });
};

const uninstallPackage = async (pkg: string, version: string) => {
await supertest
.delete(`/api/fleet/epm/packages/${pkg}/${version}`)
.set('kbn-xsrf', 'xxxx')
.expect(200);
};

const installPackageInSpace = async (pkg: string, version: string, spaceId: string) => {
await supertest
.post(`/s/${spaceId}/api/fleet/epm/packages/${pkg}/${version}`)
.set('kbn-xsrf', 'xxxx')
.send({ force: true })
.expect(200);
};

const createSpace = async (spaceId: string) => {
await supertest.post(`/api/spaces/space`).set('kbn-xsrf', 'xxxx').send({
name: spaceId,
id: spaceId,
initials: 's',
color: '#D6BF57',
disabledFeatures: [],
imageUrl: '',
});
};

const deleteSpace = async (spaceId: string) => {
await supertest.delete(`/api/spaces/space/${spaceId}`).set('kbn-xsrf', 'xxxx').send();
};

const getTag = async (id: string, space?: string) =>
kibanaServer.savedObjects
.get({
type: 'tag',
id,
...(space && { space }),
})
.catch(() => {});

describe('When installing system integration in multiple spaces', async () => {
skipIfNoDockerRegistry(providerContext);
setupFleetAndAgents(providerContext);

before(async () => {
if (!server.enabled) return;
await installPackage(pkgName, pkgVersion);

await createSpace(testSpaceId);
await uninstallPackage(pkgName, pkgVersion);
await installPackageInSpace(pkgName, pkgVersion, testSpaceId);
});

after(async () => {
await deleteSpace(testSpaceId);
});

it('should install kibana assets', async function () {
// These are installed from Fleet along with every package
const resIndexPatternLogs = await kibanaServer.savedObjects.get({
type: 'index-pattern',
id: 'logs-*',
});
expect(resIndexPatternLogs.id).equal('logs-*');
const resIndexPatternMetrics = await kibanaServer.savedObjects.get({
type: 'index-pattern',
id: 'metrics-*',
});
expect(resIndexPatternMetrics.id).equal('metrics-*');
});

it('should create managed tag saved objects', async () => {
const defaultTag = await getTag('fleet-managed-default');
expect(defaultTag).not.equal(undefined);

const spaceTag = await getTag('fleet-managed-fleet_test_space', testSpaceId);
expect(spaceTag).not.equal(undefined);
});

it('should create package tag saved objects', async () => {
const spaceTag = await getTag(`fleet-pkg-${pkgName}-fleet_test_space`, testSpaceId);
expect(spaceTag).not.equal(undefined);
});
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import type { Client } from '@elastic/elasticsearch';
import expect from '@kbn/expect';
import { FtrProviderContext } from '../../../api_integration/ftr_provider_context';
import { skipIfNoDockerRegistry } from '../../helpers';
Expand All @@ -18,7 +17,6 @@ export default function (providerContext: FtrProviderContext) {
const supertest = getService('supertest');
const dockerServers = getService('dockerServers');
const server = dockerServers.get('registry');
const es: Client = getService('es');
const pkgName = 'only_dashboard';
const pkgVersion = '0.1.0';

Expand Down Expand Up @@ -69,10 +67,8 @@ export default function (providerContext: FtrProviderContext) {
});

expectAssetsInstalled({
pkgVersion,
pkgName,
es,
kibanaServer,
space: testSpaceId,
});
});

Expand Down Expand Up @@ -123,17 +119,7 @@ export default function (providerContext: FtrProviderContext) {
});
}

const expectAssetsInstalled = ({
pkgVersion,
pkgName,
es,
kibanaServer,
}: {
pkgVersion: string;
pkgName: string;
es: Client;
kibanaServer: any;
}) => {
const expectAssetsInstalled = ({ kibanaServer, space }: { kibanaServer: any; space: string }) => {
it('should have installed the kibana assets', async function () {
// These are installed from Fleet along with every package
const resIndexPatternLogs = await kibanaServer.savedObjects.get({
Expand All @@ -151,20 +137,20 @@ const expectAssetsInstalled = ({
const resDashboard = await kibanaServer.savedObjects.get({
type: 'dashboard',
id: 'test_dashboard',
space: testSpaceId,
space,
});
expect(resDashboard.id).equal('test_dashboard');

const resVis = await kibanaServer.savedObjects.get({
type: 'visualization',
id: 'test_visualization',
space: testSpaceId,
space,
});
expect(resVis.id).equal('test_visualization');
const resSearch = await kibanaServer.savedObjects.get({
type: 'search',
id: 'test_search',
space: testSpaceId,
space,
});
expect(resSearch.id).equal('test_search');
});
Expand Down

0 comments on commit 3cd7f96

Please sign in to comment.