diff --git a/x-pack/plugins/fleet/common/services/package_policies_to_agent_inputs.test.ts b/x-pack/plugins/fleet/common/services/package_policies_to_agent_inputs.test.ts index 6ccaaf222fbf7..41964cefb85ed 100644 --- a/x-pack/plugins/fleet/common/services/package_policies_to_agent_inputs.test.ts +++ b/x-pack/plugins/fleet/common/services/package_policies_to_agent_inputs.test.ts @@ -77,6 +77,36 @@ describe('Fleet - storedPackagePoliciesToAgentInputs', () => { ], }; + const mockInput2: PackagePolicyInput = { + type: 'test-metrics', + policy_template: 'some-template', + enabled: true, + vars: { + inputVar: { value: 'input-value' }, + inputVar2: { value: undefined }, + inputVar3: { + type: 'yaml', + value: 'testField: test', + }, + inputVar4: { value: '' }, + }, + streams: [ + { + id: 'test-metrics-foo', + enabled: true, + data_stream: { dataset: 'foo', type: 'metrics' }, + vars: { + fooVar: { value: 'foo-value' }, + fooVar2: { value: [1, 2] }, + }, + compiled_stream: { + fooKey: 'fooValue1', + fooKey2: ['fooValue2'], + }, + }, + ], +}; + it('returns no inputs for package policy with no inputs, or only disabled inputs', () => { expect(storedPackagePoliciesToAgentInputs([mockPackagePolicy])).toEqual([]); @@ -146,6 +176,71 @@ describe('Fleet - storedPackagePoliciesToAgentInputs', () => { ]); }); + it('returns unique agent inputs IDs, with policy template name if one exists', () => { + expect( + storedPackagePoliciesToAgentInputs([ + { + ...mockPackagePolicy, + package: { + name: 'mock-package', + title: 'Mock package', + version: '0.0.0', + }, + inputs: [mockInput, mockInput2], + }, + ]) + ).toEqual([ + { + id: 'test-logs-some-uuid', + name: 'mock-package-policy', + revision: 1, + type: 'test-logs', + data_stream: { namespace: 'default' }, + use_output: 'default', + meta: { + package: { + name: 'mock-package', + version: '0.0.0', + }, + }, + streams: [ + { + id: 'test-logs-foo', + data_stream: { dataset: 'foo', type: 'logs' }, + fooKey: 'fooValue1', + fooKey2: ['fooValue2'], + }, + { + id: 'test-logs-bar', + data_stream: { dataset: 'bar', type: 'logs' }, + }, + ], + }, + { + id: 'test-metrics-some-template-some-uuid', + name: 'mock-package-policy', + revision: 1, + type: 'test-metrics', + data_stream: { namespace: 'default' }, + use_output: 'default', + meta: { + package: { + name: 'mock-package', + version: '0.0.0', + }, + }, + streams: [ + { + id: 'test-metrics-foo', + data_stream: { dataset: 'foo', type: 'metrics' }, + fooKey: 'fooValue1', + fooKey2: ['fooValue2'], + }, + ], + }, + ]); + }); + it('returns agent inputs without streams', () => { expect( storedPackagePoliciesToAgentInputs([