From 1b12e30a05388fdf20b7af206a2cee238a1522e7 Mon Sep 17 00:00:00 2001 From: Ole Herman Schumacher Elgesem Date: Fri, 1 Dec 2023 20:47:57 +0100 Subject: [PATCH] Added tests for backwards compatibility of cfbs build Ticket: CFE-4290 Signed-off-by: Ole Herman Schumacher Elgesem --- tests/shell/035_cfbs_build_compatibility_1.sh | 56 +++++++++ tests/shell/036_cfbs_build_compatibility_2.sh | 111 ++++++++++++++++++ tests/shell/all.sh | 2 + 3 files changed, 169 insertions(+) create mode 100644 tests/shell/035_cfbs_build_compatibility_1.sh create mode 100644 tests/shell/036_cfbs_build_compatibility_2.sh diff --git a/tests/shell/035_cfbs_build_compatibility_1.sh b/tests/shell/035_cfbs_build_compatibility_1.sh new file mode 100644 index 00000000..59ba418b --- /dev/null +++ b/tests/shell/035_cfbs_build_compatibility_1.sh @@ -0,0 +1,56 @@ +set -e +set -x +cd tests/ +mkdir -p ./tmp/ +cd ./tmp/ +rm -rf ./* + +# The purpose of this test is to ensure that older CFEngine Build projects +# still buid in newer versions of cfbs + +# The below cfbs.json file was generated using cfbs 3.2.7 +# which is the cfbs version shipped with CFEngine Enterprise 3.21.0 + +cat '{ + "name": "backwards-compatibility-test-1", + "type": "policy-set", + "description": "This project was set up to ensure projects created with CFEngine 3.21.0 / cfbs 3.2.7 still build as expected", + "build": [ + { + "name": "masterfiles", + "version": "3.21.0", + "description": "Official CFEngine Masterfiles Policy Framework (MPF).", + "tags": ["supported", "base"], + "repo": "https://github.com/cfengine/masterfiles", + "by": "https://github.com/cfengine", + "commit": "379c69aa71ab3069b2ef1c0cca526192fa77b864", + "subdirectory": "", + "added_by": "cfbs add", + "steps": ["run ./prepare.sh -y", "copy ./ ./"] + } + ], + "git": true +} +' >> cfbs.json + +# Most important, let's test that build works: +cfbs build + +# Look for some proof that the build actually did something: +grep 'bundle common inventory' out/masterfiles/promises.cf + +# These other commands should also work: +cfbs status + +cfbs validate + +# Once more, but let's do download and build as separate steps: +rm -rf out/ +rm -rf ~/.cfengine/cfbs + +cfbs download + +cfbs build + +# Perform same checks again: +grep 'bundle common inventory' out/masterfiles/promises.cf diff --git a/tests/shell/036_cfbs_build_compatibility_2.sh b/tests/shell/036_cfbs_build_compatibility_2.sh new file mode 100644 index 00000000..c831f280 --- /dev/null +++ b/tests/shell/036_cfbs_build_compatibility_2.sh @@ -0,0 +1,111 @@ +set -e +set -x +cd tests/ +mkdir -p ./tmp/ +cd ./tmp/ +rm -rf ./* + +# This test is identical to the previous test, except it has more modules. + +cat '{ + "name": "backwards-compatibility-test-2", + "type": "policy-set", + "description": "This project was set up to ensure projects created with CFEngine 3.21.0 / cfbs 3.2.7 still build as expected", + "build": [ + { + "name": "masterfiles", + "version": "3.21.0", + "description": "Official CFEngine Masterfiles Policy Framework (MPF).", + "tags": ["supported", "base"], + "repo": "https://github.com/cfengine/masterfiles", + "by": "https://github.com/cfengine", + "commit": "379c69aa71ab3069b2ef1c0cca526192fa77b864", + "subdirectory": "", + "added_by": "cfbs add", + "steps": ["run ./prepare.sh -y", "copy ./ ./"] + }, + { + "name": "autorun", + "version": "1.0.0", + "description": "Enables autorun functionality.", + "tags": ["supported", "management"], + "repo": "https://github.com/cfengine/modules", + "by": "https://github.com/olehermanse", + "commit": "be3bc015f6a19e945bb7a9fa0ed78c97e2cecf61", + "subdirectory": "management/autorun", + "added_by": "cfbs add", + "steps": ["json def.json def.json"] + }, + { + "name": "inventory-systemd", + "description": "Adds reporting data (inventory) for interesting things from systemd.", + "tags": ["supported", "inventory", "systemd"], + "repo": "https://github.com/nickanderson/cfengine-inventory-systemd", + "by": "https://github.com/nickanderson", + "version": "0.1.0", + "commit": "4b9c0708173d3b5f0855a76063781e2258465788", + "added_by": "cfbs add", + "steps": [ + "copy ./policy/main.cf services/inventory-systemd/main.cf", + "json cfbs/def.json def.json" + ] + }, + { + "name": "every-minute", + "description": "Makes policy fetching, evaluation, and reporting happen every minute.", + "tags": ["management", "experimental"], + "repo": "https://github.com/cfengine/modules", + "by": "https://github.com/olehermanse", + "version": "1.0.0-1", + "commit": "74b6776ca4e120285f9c44e68ccf79eef84accfd", + "subdirectory": "management/every-minute", + "added_by": "demo", + "steps": ["json def.json def.json"] + }, + { + "name": "demo", + "description": "Enables convenient and insecure settings for demoing CFEngine.", + "tags": ["management", "experimental"], + "repo": "https://github.com/cfengine/modules", + "by": "https://github.com/olehermanse", + "version": "1.0.0", + "commit": "05bf5e5b1c014018a7b93a524e035c1a21bcffa4", + "subdirectory": "management/demo", + "dependencies": ["autorun", "every-minute"], + "added_by": "cfbs add", + "steps": ["json def.json def.json"] + } + ], + "git": true +} +' >> cfbs.json + +# Most important, let's test that build works: +cfbs build + +# Look for some proof that these modules are actually being built into the policy set: +grep 'services_autorun' out/masterfiles/def.json +grep '"control_executor_splaytime": "1",' out/masterfiles/def.json +grep 'inventory_systemd_service_units_running' out/masterfiles/def.json +grep 'bundle common inventory' out/masterfiles/promises.cf +grep '$(paths.systemctl) list-units --type=service --state=running' out/masterfiles/services/inventory-systemd/main.cf + +# These other commands should also work: +cfbs status + +cfbs validate + +# Once more, but let's do download and build as separate steps: +rm -rf out/ +rm -rf ~/.cfengine/cfbs + +cfbs download + +cfbs build + +# Perform same checks again: +grep 'services_autorun' out/masterfiles/def.json +grep '"control_executor_splaytime": "1",' out/masterfiles/def.json +grep 'inventory_systemd_service_units_running' out/masterfiles/def.json +grep 'bundle common inventory' out/masterfiles/promises.cf +grep '$(paths.systemctl) list-units --type=service --state=running' out/masterfiles/services/inventory-systemd/main.cf diff --git a/tests/shell/all.sh b/tests/shell/all.sh index 5283542c..1992d51c 100644 --- a/tests/shell/all.sh +++ b/tests/shell/all.sh @@ -38,5 +38,7 @@ bash tests/shell/031_get_set_input_pipe.sh bash tests/shell/032_set_input_unordered.sh bash tests/shell/033_add_commits_local_files.sh bash tests/shell/034_git_user_name_git_user_email.sh +bash tests/shell/035_cfbs_build_compatibility_1.sh +bash tests/shell/036_cfbs_build_compatibility_2.sh echo "All cfbs shell tests completed successfully!"