mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 09:48:58 -04:00
[Fleet] refactored input package tests (#184410)
## Summary Closes https://github.com/elastic/kibana/issues/175563 Refactored input package tests not to depend on each other.
This commit is contained in:
parent
0a8b651f8d
commit
7fef12bca0
1 changed files with 33 additions and 47 deletions
|
@ -79,13 +79,6 @@ export default function (providerContext: FtrProviderContext) {
|
|||
return res.body.item;
|
||||
};
|
||||
|
||||
const deletePackagePolicy = (id: string) => {
|
||||
return supertest
|
||||
.delete(`/api/fleet/package_policies/${id}`)
|
||||
.set('kbn-xsrf', 'xxxx')
|
||||
.expect(200);
|
||||
};
|
||||
|
||||
const createAgentPolicy = async (name = 'Input Package Test 3') => {
|
||||
const res = await supertest
|
||||
.post(`/api/fleet/agent_policies`)
|
||||
|
@ -180,20 +173,20 @@ export default function (providerContext: FtrProviderContext) {
|
|||
await es.indices.deleteIndexTemplate({ name: templateName });
|
||||
};
|
||||
|
||||
// Tests are order-dependent and share state so can fail.
|
||||
describe.skip('Package Policy - input package behavior', async function () {
|
||||
describe('Package Policy - input package behavior', async function () {
|
||||
skipIfNoDockerRegistry(providerContext);
|
||||
|
||||
let agentPolicyId: string;
|
||||
const packagePolicyIds: string[] = [];
|
||||
before(async () => {
|
||||
installPackage(PACKAGE_NAME, START_VERSION);
|
||||
beforeEach(async () => {
|
||||
await installPackage(PACKAGE_NAME, START_VERSION);
|
||||
const agentPolicy = await createAgentPolicy();
|
||||
agentPolicyId = agentPolicy.id;
|
||||
});
|
||||
|
||||
after(async () => {
|
||||
afterEach(async () => {
|
||||
await deleteAgentPolicy(agentPolicyId);
|
||||
|
||||
await uninstallPackage(PACKAGE_NAME, START_VERSION);
|
||||
});
|
||||
setupFleetAndAgents(providerContext);
|
||||
|
||||
|
@ -203,8 +196,7 @@ export default function (providerContext: FtrProviderContext) {
|
|||
});
|
||||
|
||||
it('should create index templates and update installed_es on package policy creation', async () => {
|
||||
const packagePolicy = await createPackagePolicyWithDataset(agentPolicyId, 'dataset1');
|
||||
packagePolicyIds.push(packagePolicy.id);
|
||||
await createPackagePolicyWithDataset(agentPolicyId, 'dataset1');
|
||||
const installation = await getInstallationSavedObject(PACKAGE_NAME, START_VERSION);
|
||||
expectIdArraysEqual(installation.installed_es, [
|
||||
{ id: 'logs-dataset1-1.0.0', type: 'ingest_pipeline' },
|
||||
|
@ -224,7 +216,7 @@ export default function (providerContext: FtrProviderContext) {
|
|||
lifecycle: { name: 'logs' },
|
||||
default_pipeline: 'logs-dataset1-1.0.0',
|
||||
mapping: {
|
||||
total_fields: { limit: '10000' },
|
||||
total_fields: { limit: '1000' },
|
||||
},
|
||||
},
|
||||
},
|
||||
|
@ -251,37 +243,39 @@ export default function (providerContext: FtrProviderContext) {
|
|||
});
|
||||
|
||||
it('should create index templates and update installed_es on second package policy creation', async () => {
|
||||
const packagePolicy = await createPackagePolicyWithDataset(agentPolicyId, 'dataset2');
|
||||
packagePolicyIds.push(packagePolicy.id);
|
||||
await createPackagePolicyWithDataset(agentPolicyId, 'dataset2');
|
||||
const installation = await getInstallationSavedObject(PACKAGE_NAME, START_VERSION);
|
||||
expectIdArraysEqual(installation.installed_es, [
|
||||
{ id: 'logs-dataset1-1.0.0', type: 'ingest_pipeline' },
|
||||
{ id: 'logs-dataset1', type: 'index_template' },
|
||||
{ id: 'logs-dataset1@package', type: 'component_template' },
|
||||
{ id: 'logs-dataset1@custom', type: 'component_template' },
|
||||
let found = 0;
|
||||
[
|
||||
{ id: 'logs-dataset2-1.0.0', type: 'ingest_pipeline' },
|
||||
{ id: 'logs-dataset2', type: 'index_template' },
|
||||
{ id: 'logs-dataset2@package', type: 'component_template' },
|
||||
{ id: 'logs-dataset2@custom', type: 'component_template' },
|
||||
]);
|
||||
].forEach((obj) => {
|
||||
if (installation.installed_es.find((installed: any) => installed.id === obj.id)) {
|
||||
found++;
|
||||
}
|
||||
});
|
||||
expect(found).to.eql(4);
|
||||
});
|
||||
|
||||
it('should allow data to be sent to existing stream if owned by package and should not create templates', async () => {
|
||||
await createFakeFleetDataStream('dataset3');
|
||||
|
||||
const packagePolicy = await createPackagePolicyWithDataset(agentPolicyId, 'dataset3');
|
||||
packagePolicyIds.push(packagePolicy.id);
|
||||
await createPackagePolicyWithDataset(agentPolicyId, 'dataset3');
|
||||
const installation = await getInstallationSavedObject(PACKAGE_NAME, START_VERSION);
|
||||
expectIdArraysEqual(installation.installed_es, [
|
||||
{ id: 'logs-dataset1-1.0.0', type: 'ingest_pipeline' },
|
||||
{ id: 'logs-dataset1', type: 'index_template' },
|
||||
{ id: 'logs-dataset1@package', type: 'component_template' },
|
||||
{ id: 'logs-dataset1@custom', type: 'component_template' },
|
||||
{ id: 'logs-dataset2-1.0.0', type: 'ingest_pipeline' },
|
||||
{ id: 'logs-dataset2', type: 'index_template' },
|
||||
{ id: 'logs-dataset2@package', type: 'component_template' },
|
||||
{ id: 'logs-dataset2@custom', type: 'component_template' },
|
||||
]);
|
||||
let found = 0;
|
||||
[
|
||||
{ id: 'logs-dataset3-1.0.0', type: 'ingest_pipeline' },
|
||||
{ id: 'logs-dataset3', type: 'index_template' },
|
||||
{ id: 'logs-dataset3@package', type: 'component_template' },
|
||||
{ id: 'logs-dataset3@custom', type: 'component_template' },
|
||||
].forEach((obj) => {
|
||||
if (installation.installed_es.find((installed: any) => installed.id === obj.id)) {
|
||||
found++;
|
||||
}
|
||||
});
|
||||
expect(found).to.eql(0);
|
||||
|
||||
const dataset3PkgComponentTemplate = await getComponentTemplate('logs-dataset3@package');
|
||||
expect(dataset3PkgComponentTemplate).eql(null);
|
||||
|
@ -346,6 +340,7 @@ export default function (providerContext: FtrProviderContext) {
|
|||
});
|
||||
|
||||
it('should update all index templates created by package policies when the package is upgraded', async () => {
|
||||
await createPackagePolicyWithDataset(agentPolicyId, 'dataset1');
|
||||
// version 1.1.0 of the test package introduces elasticsearch mappings to the index
|
||||
// templates, upgrading the package should add this field to both package component templates
|
||||
await installPackage(PACKAGE_NAME, UPGRADE_VERSION);
|
||||
|
@ -367,24 +362,15 @@ export default function (providerContext: FtrProviderContext) {
|
|||
mappingsWithTimestamp
|
||||
);
|
||||
|
||||
const dataset2PkgComponentTemplate = await getComponentTemplate('logs-dataset2@package');
|
||||
expect(dataset2PkgComponentTemplate).not.eql(null);
|
||||
expect(dataset2PkgComponentTemplate!.component_template.template?.mappings?.properties).eql(
|
||||
mappingsWithTimestamp
|
||||
);
|
||||
await uninstallPackage(PACKAGE_NAME, UPGRADE_VERSION);
|
||||
});
|
||||
it('should delete all index templates created by package policies when the package is uninstalled', async () => {
|
||||
for (const packagePolicyId of packagePolicyIds) {
|
||||
await deletePackagePolicy(packagePolicyId);
|
||||
}
|
||||
await createPackagePolicyWithDataset(agentPolicyId, 'dataset1');
|
||||
await deleteAgentPolicy(agentPolicyId);
|
||||
await uninstallPackage(PACKAGE_NAME, UPGRADE_VERSION);
|
||||
|
||||
const dataset1PkgComponentTemplate = await getComponentTemplate('logs-dataset1@package');
|
||||
expect(dataset1PkgComponentTemplate).eql(null);
|
||||
|
||||
const dataset2PkgComponentTemplate = await getComponentTemplate('logs-dataset2@package');
|
||||
expect(dataset2PkgComponentTemplate).eql(null);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue