Skip to content

Commit

Permalink
Add basic test cases for restructured packages
Browse files Browse the repository at this point in the history
  • Loading branch information
kpollich committed Aug 25, 2021
1 parent 80246de commit 5889928
Show file tree
Hide file tree
Showing 22 changed files with 444 additions and 3 deletions.
19 changes: 17 additions & 2 deletions x-pack/plugins/fleet/server/services/package_policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -911,15 +911,30 @@ export function overridePackageInputs(
): DryRunPackagePolicy {
if (!inputsOverride) return basePackagePolicy;

const availablePolicyTemplates = (packageInfo.policy_templates ?? []).map(({ name }) => name);
const availablePolicyTemplates = packageInfo.policy_templates ?? [];

const inputs = [
...basePackagePolicy.inputs.filter((input) => {
if (!input.policy_template) {
return true;
}

return availablePolicyTemplates.includes(input.policy_template);
const policyTemplate = availablePolicyTemplates.find(
({ name }) => name === input.policy_template
);

// Ignore any policy template removes in the new package version
if (!policyTemplate) {
return false;
}

// Ignore any inputs removed from this policy template in the new package version
const policyTemplateStillIncludesInput =
policyTemplate.inputs?.some(
(policyTemplateInput) => policyTemplateInput.type === input.type
) ?? false;

return policyTemplateStillIncludesInput;
}),
];

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
config.version: "2"
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
- name: data_stream.type
type: constant_keyword
description: >
Data stream type.
- name: data_stream.dataset
type: constant_keyword
description: >
Data stream dataset.
- name: data_stream.namespace
type: constant_keyword
description: >
Data stream namespace.
- name: '@timestamp'
type: date
description: >
Event timestamp.
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
title: Test stream
type: logs
streams:
- input: test_input_new
vars:
- name: test_var_new
type: text
title: Test Var New
default: Test Var New
required: true
show_user: true
- name: test_var_new_2
type: text
title: Test Var New 2
default: Test Var New 2
required: true
show_user: true
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
config.version: "2"
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
- name: data_stream.type
type: constant_keyword
description: >
Data stream type.
- name: data_stream.dataset
type: constant_keyword
description: >
Data stream dataset.
- name: data_stream.namespace
type: constant_keyword
description: >
Data stream namespace.
- name: '@timestamp'
type: date
description: >
Event timestamp.
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
title: Test stream
type: logs
streams:
- input: test_input_new_2
vars:
- name: test_input_new_2_var_1
type: text
title: Test Input New 2 Var 1
default: Test Input New 2 Var 1
required: true
show_user: true
- name: test_input_new_2_var_2
type: text
title: Test Input New 2 Var 2
default: Test Input New 2 Var 2
required: true
show_user: true
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Test package

This is a test package for testing automated upgrades for package policies
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
format_version: 1.0.0
name: package_policy_upgrade
title: Tests package policy upgrades
description: This is a test package for upgrading package policies
version: 0.5.0-restructure-inputs
categories: []
release: beta
type: integration
license: basic
requirement:
elasticsearch:
versions: '>7.7.0'
kibana:
versions: '>7.7.0'
policy_templates:
- name: package_policy_upgrade
title: Package Policy Upgrade
description: Test Package for Upgrading Package Policies
inputs:
- type: test_input_new
title: Test Input New
description: Test Input New
enabled: true
- type: test_input_new_2
title: Test Input New 2
description: Test Input New 2
enabled: true
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
config.version: "2"
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
- name: data_stream.type
type: constant_keyword
description: >
Data stream type.
- name: data_stream.dataset
type: constant_keyword
description: >
Data stream dataset.
- name: data_stream.namespace
type: constant_keyword
description: >
Data stream namespace.
- name: '@timestamp'
type: date
description: >
Event timestamp.
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
title: Test stream
type: logs
streams:
- input: test_input_new
vars:
- name: test_var_new
type: text
title: Test Var New
default: Test Var New
required: true
show_user: true
- name: test_var_new_2
type: text
title: Test Var New 2
default: Test Var New 2
required: true
show_user: true
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
config.version: "2"
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
- name: data_stream.type
type: constant_keyword
description: >
Data stream type.
- name: data_stream.dataset
type: constant_keyword
description: >
Data stream dataset.
- name: data_stream.namespace
type: constant_keyword
description: >
Data stream namespace.
- name: '@timestamp'
type: date
description: >
Event timestamp.
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
title: Test stream
type: logs
streams:
- input: test_input_new_2
vars:
- name: test_input_new_2_var_1
type: text
title: Test Input New 2 Var 1
default: Test Input New 2 Var 1
required: true
show_user: true
- name: test_input_new_2_var_2
type: text
title: Test Input New 2 Var 2
default: Test Input New 2 Var 2
required: true
show_user: true
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Test package

This is a test package for testing automated upgrades for package policies
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
format_version: 1.0.0
name: package_policy_upgrade
title: Tests package policy upgrades
description: This is a test package for upgrading package policies
version: 0.6.0-restructure-policy-templates
categories: []
release: beta
type: integration
license: basic
requirement:
elasticsearch:
versions: '>7.7.0'
kibana:
versions: '>7.7.0'
policy_templates:
- name: package_policy_upgrade_new
title: Package Policy Upgrade New
description: Test Package for Upgrading Package Policies
inputs:
- type: test_input_new
title: Test Input New
description: Test Input New
enabled: true
- type: test_input_new_2
title: Test Input New 2
description: Test Input New 2
enabled: true
Loading

0 comments on commit 5889928

Please sign in to comment.