mirror of
https://github.com/elastic/kibana.git
synced 2025-04-25 02:09:32 -04:00
Add test for overridePackageInputs method (#113270)
This commit is contained in:
parent
200d0353d1
commit
acd29eddcf
2 changed files with 103 additions and 2 deletions
|
@ -13,6 +13,9 @@ import type {
|
||||||
import type { NewAgentPolicy } from './agent_policy';
|
import type { NewAgentPolicy } from './agent_policy';
|
||||||
import type { Output } from './output';
|
import type { Output } from './output';
|
||||||
|
|
||||||
|
// TODO: This type is not usable directly, and instead we typically use a type assertion
|
||||||
|
// e.g. `NewPackagePolicyInput as InputsOverride[]`. This type should be altered so that it's
|
||||||
|
// possible to use it directly in tests, etc
|
||||||
export type InputsOverride = Partial<NewPackagePolicyInput> & {
|
export type InputsOverride = Partial<NewPackagePolicyInput> & {
|
||||||
vars?: Array<NewPackagePolicyInput['vars'] & { name: string }>;
|
vars?: Array<NewPackagePolicyInput['vars'] & { name: string }>;
|
||||||
};
|
};
|
||||||
|
|
|
@ -28,11 +28,20 @@ import type { PutPackagePolicyUpdateCallback, PostPackagePolicyCreateCallback }
|
||||||
|
|
||||||
import { createAppContextStartContractMock, xpackMocks } from '../mocks';
|
import { createAppContextStartContractMock, xpackMocks } from '../mocks';
|
||||||
|
|
||||||
import type { DeletePackagePoliciesResponse } from '../../common';
|
import type {
|
||||||
|
DeletePackagePoliciesResponse,
|
||||||
|
InputsOverride,
|
||||||
|
NewPackagePolicy,
|
||||||
|
NewPackagePolicyInput,
|
||||||
|
} from '../../common';
|
||||||
|
|
||||||
import { IngestManagerError } from '../errors';
|
import { IngestManagerError } from '../errors';
|
||||||
|
|
||||||
import { packagePolicyService, _applyIndexPrivileges } from './package_policy';
|
import {
|
||||||
|
overridePackageInputs,
|
||||||
|
packagePolicyService,
|
||||||
|
_applyIndexPrivileges,
|
||||||
|
} from './package_policy';
|
||||||
import { appContextService } from './app_context';
|
import { appContextService } from './app_context';
|
||||||
|
|
||||||
async function mockedGetAssetsData(_a: any, _b: any, dataset: string) {
|
async function mockedGetAssetsData(_a: any, _b: any, dataset: string) {
|
||||||
|
@ -1074,6 +1083,95 @@ describe('Package policy service', () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('overridePackageInputs', () => {
|
||||||
|
it('should override variable in base package policy', () => {
|
||||||
|
const basePackagePolicy: NewPackagePolicy = {
|
||||||
|
name: 'base-package-policy',
|
||||||
|
description: 'Base Package Policy',
|
||||||
|
namespace: 'default',
|
||||||
|
enabled: true,
|
||||||
|
policy_id: 'xxxx',
|
||||||
|
output_id: 'xxxx',
|
||||||
|
package: {
|
||||||
|
name: 'test-package',
|
||||||
|
title: 'Test Package',
|
||||||
|
version: '0.0.1',
|
||||||
|
},
|
||||||
|
inputs: [
|
||||||
|
{
|
||||||
|
type: 'logs',
|
||||||
|
policy_template: 'template_1',
|
||||||
|
enabled: true,
|
||||||
|
vars: {
|
||||||
|
path: {
|
||||||
|
type: 'text',
|
||||||
|
value: ['/var/log/logfile.log'],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
streams: [],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
};
|
||||||
|
|
||||||
|
const packageInfo: PackageInfo = {
|
||||||
|
name: 'test-package',
|
||||||
|
description: 'Test Package',
|
||||||
|
title: 'Test Package',
|
||||||
|
version: '0.0.1',
|
||||||
|
latestVersion: '0.0.1',
|
||||||
|
release: 'experimental',
|
||||||
|
format_version: '1.0.0',
|
||||||
|
owner: { github: 'elastic/fleet' },
|
||||||
|
policy_templates: [
|
||||||
|
{
|
||||||
|
name: 'template_1',
|
||||||
|
title: 'Template 1',
|
||||||
|
description: 'Template 1',
|
||||||
|
inputs: [
|
||||||
|
{
|
||||||
|
type: 'logs',
|
||||||
|
title: 'Log',
|
||||||
|
description: 'Log Input',
|
||||||
|
vars: [
|
||||||
|
{
|
||||||
|
name: 'path',
|
||||||
|
type: 'text',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
// @ts-ignore
|
||||||
|
assets: {},
|
||||||
|
};
|
||||||
|
|
||||||
|
const inputsOverride: NewPackagePolicyInput[] = [
|
||||||
|
{
|
||||||
|
type: 'logs',
|
||||||
|
enabled: true,
|
||||||
|
streams: [],
|
||||||
|
vars: {
|
||||||
|
path: {
|
||||||
|
type: 'text',
|
||||||
|
value: '/var/log/new-logfile.log',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
const result = overridePackageInputs(
|
||||||
|
basePackagePolicy,
|
||||||
|
packageInfo,
|
||||||
|
// TODO: Update this type assertion when the `InputsOverride` type is updated such
|
||||||
|
// that it no longer causes unresolvable type errors when used directly
|
||||||
|
inputsOverride as InputsOverride[],
|
||||||
|
false
|
||||||
|
);
|
||||||
|
expect(result.inputs[0]?.vars?.path.value).toBe('/var/log/new-logfile.log');
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('_applyIndexPrivileges()', () => {
|
describe('_applyIndexPrivileges()', () => {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue