Skip to content

Commit

Permalink
Add FTR test to ensure data views aren't recreated after subsequent i…
Browse files Browse the repository at this point in the history
…ntegration installations
  • Loading branch information
kpollich committed Nov 1, 2023
1 parent fc05694 commit 797626d
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 0 deletions.
77 changes: 77 additions & 0 deletions x-pack/test/fleet_api_integration/apis/epm/data_views.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/*
* 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';

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

const supertest = getService('supertest');

const testPkgs = [
{
name: 'apache',
version: '0.1.4',
},
{
name: 'nginx',
version: '1.2.1',
},
];

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

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

const listDataViews = async () => {
const response = await supertest.get('/api/data_views');

return response.body.data_view;
};

describe('EPM - data views', () => {
skipIfNoDockerRegistry(providerContext);
setupFleetAndAgents(providerContext);

afterEach(async () => {
await Promise.all(testPkgs.map((pkg) => uninstallPackage(pkg.name, pkg.version)));
});

describe('with subsequent integration installation', async () => {
it('does not recreate managed data views', async () => {
await installPackage(testPkgs[0].name, testPkgs[0].version);
const initialDataViews: any[] = await listDataViews();
const initialLogsDataView = initialDataViews.find(({ title }) => title === 'logs-*');
const initialMetricsDataView = initialDataViews.find(({ title }) => title === 'metrics-*');

expect(initialLogsDataView).to.be.ok();
expect(initialMetricsDataView).to.be.ok();

await installPackage(testPkgs[1].name, testPkgs[1].version);
const subsequentDataViews: any[] = await listDataViews();
const subsequentLogsDataView = subsequentDataViews.find(({ title }) => title === 'logs-*');
const subsequentMetricsDataView = subsequentDataViews.find(
({ title }) => title === 'metrics-*'
);

// ID's should not have changed as the data views should not have been recreated
expect(initialLogsDataView.id).to.eql(subsequentLogsDataView.id);
expect(initialMetricsDataView.id).to.eql(subsequentMetricsDataView.id);
});
});
});
}
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 @@ -47,5 +47,6 @@ export default function loadTests({ loadTestFile, getService }) {
loadTestFile(require.resolve('./routing_rules'));
loadTestFile(require.resolve('./install_runtime_field'));
loadTestFile(require.resolve('./get_templates_inputs'));
loadTestFile(require.resolve('./data_views'));
});
}

0 comments on commit 797626d

Please sign in to comment.