Skip to content

Commit

Permalink
Add unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
jen-huang committed Mar 9, 2022
1 parent c872a78 commit 39ff528
Showing 1 changed file with 95 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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([]);

Expand Down Expand Up @@ -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([
Expand Down

0 comments on commit 39ff528

Please sign in to comment.