From faed0bac0a8744d79d44eec439ae6707991f2ee8 Mon Sep 17 00:00:00 2001 From: jakub-nt <175944085+jakub-nt@users.noreply.github.com> Date: Fri, 20 Jun 2025 16:45:41 +0200 Subject: [PATCH] Add testing for added_by field updating Signed-off-by: jakub-nt <175944085+jakub-nt@users.noreply.github.com> --- tests/shell/035_cfbs_build_compatibility_1.sh | 2 +- .../shell/039_add_added_by_field_update_1.sh | 23 +++++++++++++++++++ .../shell/040_add_added_by_field_update_2.sh | 17 ++++++++++++++ tests/shell/all.sh | 2 ++ 4 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 tests/shell/039_add_added_by_field_update_1.sh create mode 100644 tests/shell/040_add_added_by_field_update_2.sh diff --git a/tests/shell/035_cfbs_build_compatibility_1.sh b/tests/shell/035_cfbs_build_compatibility_1.sh index 0d7b5b93..8a3fc142 100644 --- a/tests/shell/035_cfbs_build_compatibility_1.sh +++ b/tests/shell/035_cfbs_build_compatibility_1.sh @@ -6,7 +6,7 @@ cd ./tmp/ rm -rf ./* # The purpose of this test is to ensure that older CFEngine Build projects -# still buid in newer versions of cfbs +# still build 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 diff --git a/tests/shell/039_add_added_by_field_update_1.sh b/tests/shell/039_add_added_by_field_update_1.sh new file mode 100644 index 00000000..4e89f82a --- /dev/null +++ b/tests/shell/039_add_added_by_field_update_1.sh @@ -0,0 +1,23 @@ +set -e +set -x +cd tests/ +mkdir -p ./tmp/ +cd ./tmp/ +touch cfbs.json && rm cfbs.json +rm -rf .git + +cfbs --non-interactive init + +# Ensure adding a module during initialization is treated as adding manually +cat cfbs.json | grep -F "added_by" | grep -F "cfbs init" +# TODO: the case of custom non-masterfiles module(s) should also be tested + +# Manually adding a module then manually adding its dependency should update the latter's `"added_by"` field in `cfbs.json` + +cfbs --non-interactive add package-method-winget +cat cfbs.json | grep -F "added_by" | grep -F "package-method-winget" +[ "$(cat cfbs.json | grep -F "added_by" | grep -F "cfbs add" -c)" -eq 1 ] + +cfbs --non-interactive add powershell-execution-policy +! ( cat cfbs.json | grep -F "added_by" | grep -F "package-method-winget" ) +[ "$(cat cfbs.json | grep -F "added_by" | grep -F "cfbs add" -c)" -eq 2 ] diff --git a/tests/shell/040_add_added_by_field_update_2.sh b/tests/shell/040_add_added_by_field_update_2.sh new file mode 100644 index 00000000..1ede9509 --- /dev/null +++ b/tests/shell/040_add_added_by_field_update_2.sh @@ -0,0 +1,17 @@ +set -e +set -x +cd tests/ +mkdir -p ./tmp/ +cd ./tmp/ +touch cfbs.json && rm cfbs.json +rm -rf .git + +cfbs --non-interactive init + +# Manually adding a dependency of a module then manually adding that module should not update the latter's `"added_by"` field in `cfbs.json` + +cfbs --non-interactive add powershell-execution-policy +cat cfbs.json | grep -F "added_by" | grep -F "cfbs add" + +cfbs --non-interactive add package-method-winget +! ( cat cfbs.json | grep -F "added_by" | grep -F "package-method-winget" ) diff --git a/tests/shell/all.sh b/tests/shell/all.sh index c6b55ec2..58a2fe48 100644 --- a/tests/shell/all.sh +++ b/tests/shell/all.sh @@ -42,5 +42,7 @@ bash tests/shell/035_cfbs_build_compatibility_1.sh bash tests/shell/036_cfbs_build_compatibility_2.sh bash tests/shell/037_cfbs_validate.sh bash tests/shell/038_global_dir.sh +bash tests/shell/039_add_added_by_field_update_1.sh +bash tests/shell/040_add_added_by_field_update_2.sh echo "All cfbs shell tests completed successfully!"