[Fleet] Add unit test for fleet agent id verification config flag (#155720)

This commit is contained in:
Nicolas Chaulet 2023-04-26 14:45:25 -04:00 committed by GitHub
parent 6ec97802d9
commit 5e713fb225
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -17,6 +17,10 @@ import { appContextService } from '../../..';
import type { RegistryDataStream } from '../../../../types';
import { processFields } from '../../fields/field';
import type { Field } from '../../fields/field';
import {
FLEET_COMPONENT_TEMPLATES,
FLEET_GLOBALS_COMPONENT_TEMPLATE_NAME,
} from '../../../../constants';
import {
generateMappings,
@ -26,7 +30,9 @@ import {
updateCurrentWriteIndices,
} from './template';
const FLEET_COMPONENT_TEMPLATES = ['.fleet_globals-1', '.fleet_agent_id_verification-1'];
const FLEET_COMPONENT_TEMPLATES_NAMES = FLEET_COMPONENT_TEMPLATES.map(
(componentTemplate) => componentTemplate.name
);
// Add our own serialiser to just do JSON.stringify
expect.addSnapshotSerializer({
@ -69,7 +75,28 @@ describe('EPM template', () => {
});
expect(template.composed_of).toStrictEqual([
...composedOfTemplates,
...FLEET_COMPONENT_TEMPLATES,
...FLEET_COMPONENT_TEMPLATES_NAMES,
]);
});
it('does not create fleet agent id verification component template if agentIdVerification is disabled', () => {
appContextService.start(
createAppContextStartContractMock({
agentIdVerificationEnabled: false,
})
);
const composedOfTemplates = ['component1', 'component2'];
const template = getTemplate({
templateIndexPattern: 'name-*',
packageName: 'nginx',
composedOfTemplates,
templatePriority: 200,
mappings: { properties: [] },
});
expect(template.composed_of).toStrictEqual([
...composedOfTemplates,
FLEET_GLOBALS_COMPONENT_TEMPLATE_NAME,
]);
});
@ -83,7 +110,7 @@ describe('EPM template', () => {
templatePriority: 200,
mappings: { properties: [] },
});
expect(template.composed_of).toStrictEqual(FLEET_COMPONENT_TEMPLATES);
expect(template.composed_of).toStrictEqual(FLEET_COMPONENT_TEMPLATES_NAMES);
});
it('adds hidden field correctly', () => {