Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
c263e0e
Added shell test framework and improved test runner reporting
larsewi Feb 17, 2026
f55e591
Moved git helpers from common.sh into testlib.sh as assert_git_tracks…
larsewi Feb 17, 2026
d0a3809
Migrated 001_init.sh to testlib.sh
larsewi Feb 17, 2026
6d155a4
Migrated 002_add.sh to testlib.sh
larsewi Feb 17, 2026
7f6e3c2
Migrated 003_download.sh to testlib.sh
larsewi Feb 17, 2026
b1cc23e
Migrated 004_build.sh to testlib.sh
larsewi Feb 17, 2026
2548a8e
Migrated 005_alias.sh to testlib.sh
larsewi Feb 17, 2026
27ee3e1
Migrated 006_search.sh to testlib.sh
larsewi Feb 17, 2026
5c3a3e4
Migrated 007_install.sh to testlib.sh
larsewi Feb 17, 2026
8b6eb4a
Migrated 008_remove.sh to testlib.sh
larsewi Feb 17, 2026
9502c29
Migrated 009_clean.sh to testlib.sh
larsewi Feb 17, 2026
916194c
Migrated 010_local_add.sh to testlib.sh
larsewi Feb 17, 2026
faf1a3a
Migrated 011_update.sh to testlib.sh
larsewi Feb 17, 2026
d295107
Migrated 012_prepend_dot_slash.sh to testlib.sh
larsewi Feb 17, 2026
a8a429e
Migrated 013_add_url_commit.sh to testlib.sh
larsewi Feb 17, 2026
59a8a74
Migrated 014_add_nonexistent.sh to testlib.sh
larsewi Feb 17, 2026
9cb00b3
Migrated 015_add_version.sh to testlib.sh
larsewi Feb 17, 2026
efe29a3
Migrated 016_add_folders.sh to testlib.sh
larsewi Feb 17, 2026
8c1842c
Migrated 017_info.sh to testlib.sh
larsewi Feb 17, 2026
7540ed9
Migrated 018_update_input_one_variable.sh to testlib.sh
larsewi Feb 17, 2026
ab385d6
Migrated 019_update_input_two_variables.sh to testlib.sh
larsewi Feb 17, 2026
7401baf
Migrated 020_update_input_list.sh to testlib.sh
larsewi Feb 17, 2026
4c5c29e
Migrated 021_update_input_list_with_keys.sh to testlib.sh
larsewi Feb 17, 2026
4d7ee69
Migrated 022_update_input_fail_variable.sh to testlib.sh
larsewi Feb 17, 2026
1c1212d
Migrated 023_update_input_fail_number.sh to testlib.sh
larsewi Feb 17, 2026
4880bd0
Migrated 024_update_input_fail_bundle.sh to testlib.sh
larsewi Feb 17, 2026
1a6fbd2
Migrated 025_add_input_remove.sh to testlib.sh
larsewi Feb 17, 2026
aa5089d
Migrated 026_init_no_masterfiles.sh to testlib.sh
larsewi Feb 17, 2026
b8d61b4
Migrated 027_init_masterfiles_version_master.sh to testlib.sh
larsewi Feb 17, 2026
861c06c
Migrated 028_init_masterfiles_version_3.18.2.sh to testlib.sh
larsewi Feb 17, 2026
2f77cd6
Migrated 029_init_masterfiles_version_3.18.1-1.sh to testlib.sh
larsewi Feb 17, 2026
8965fc9
Migrated 030_get_set_input.sh to testlib.sh
larsewi Feb 17, 2026
bef684d
Migrated 031_get_set_input_pipe.sh to testlib.sh
larsewi Feb 17, 2026
396c2f1
Migrated 032_set_input_unordered.sh to testlib.sh
larsewi Feb 17, 2026
a8a2bbc
Migrated 033_add_commits_local_files.sh to testlib.sh
larsewi Feb 17, 2026
2d69607
Migrated 034_git_user_name_git_user_email.sh to testlib.sh
larsewi Feb 17, 2026
48f9197
Migrated 035_cfbs_build_compatibility_1.sh to testlib.sh
larsewi Feb 17, 2026
5bc79a8
Migrated 036_cfbs_build_compatibility_2.sh to testlib.sh
larsewi Feb 17, 2026
8c05687
Migrated 037_cfbs_validate.sh to testlib.sh
larsewi Feb 17, 2026
35fa012
Removed trailing whitespace in 047_absolute_path_modules.sh
larsewi Feb 17, 2026
80f44e9
Migrated 038_global_dir.sh to testlib.sh
larsewi Feb 17, 2026
06ab575
Migrated 039_add_added_by_field_update_1.sh to testlib.sh
larsewi Feb 17, 2026
3c4691d
Migrated 040_add_added_by_field_update_2.sh to testlib.sh
larsewi Feb 17, 2026
6b8dcc1
Migrated 041_add_multidep.sh to testlib.sh
larsewi Feb 17, 2026
e2589e2
Migrated 042_update_from_url.sh to testlib.sh
larsewi Feb 17, 2026
9b13823
Migrated 043_replace_version.sh to testlib.sh
larsewi Feb 17, 2026
c1fc155
Migrated 044_replace.sh to testlib.sh
larsewi Feb 17, 2026
6ddf5d8
Migrated 045_update_from_url_branch_uptodate.sh to testlib.sh
larsewi Feb 17, 2026
3d9c4d7
Migrated 046_update_from_url_branch.sh to testlib.sh
larsewi Feb 17, 2026
fa37d9d
Migrated 047_absolute_path_modules.sh to testlib.sh
larsewi Feb 17, 2026
4ff81a5
Renamed assert_file_matches() to assert_file_matches_regex()
larsewi Feb 23, 2026
5afaf49
Renamed assert_count() to assert_num_string_occurrences()
larsewi Feb 23, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 5 additions & 8 deletions tests/shell/001_init.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
set -e
set -x
cd tests/
mkdir -p ./tmp/
cd ./tmp/
touch cfbs.json && rm cfbs.json
rm -rf .git
source "$(dirname "$0")/testlib.sh"
test_init

cfbs --non-interactive init
ls cfbs.json
assert_file_exists cfbs.json

test_finish
13 changes: 5 additions & 8 deletions tests/shell/002_add.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
set -e
set -x
cd tests/
mkdir -p ./tmp/
cd ./tmp/
touch cfbs.json && rm cfbs.json
rm -rf .git
source "$(dirname "$0")/testlib.sh"
test_init

cfbs --non-interactive init
cfbs --non-interactive add autorun
grep masterfiles cfbs.json
assert_file_contains cfbs.json masterfiles

test_finish
13 changes: 5 additions & 8 deletions tests/shell/003_download.sh
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
set -e
set -x
cd tests/
mkdir -p ./tmp/
cd ./tmp/
touch cfbs.json && rm cfbs.json
rm -rf .git
source "$(dirname "$0")/testlib.sh"
test_init

cfbs --non-interactive init
cfbs download

ls ~/.cfengine/cfbs/downloads/*
assert_file_exists ~/.cfengine/cfbs/downloads/*

test_finish
13 changes: 5 additions & 8 deletions tests/shell/004_build.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
set -e
set -x
cd tests/
mkdir -p ./tmp/
cd ./tmp/
touch cfbs.json && rm cfbs.json
rm -rf .git
source "$(dirname "$0")/testlib.sh"
test_init

cfbs --non-interactive init
cfbs --non-interactive add autorun
Expand All @@ -13,4 +8,6 @@ cfbs --non-interactive add git
cfbs --non-interactive add ansible
cfbs build

ls out/
assert_file_exists out/

test_finish
17 changes: 7 additions & 10 deletions tests/shell/005_alias.sh
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
set -e
set -x
cd tests/
mkdir -p ./tmp/
cd ./tmp/
touch cfbs.json && rm cfbs.json
rm -rf .git
source "$(dirname "$0")/testlib.sh"
test_init

cfbs --non-interactive init
cfbs --non-interactive add groups > output.log
run cfbs --non-interactive add groups

grep "alias" output.log
grep "Added module" output.log
assert_output_contains "alias"
assert_output_contains "Added module"

test_finish
27 changes: 13 additions & 14 deletions tests/shell/006_search.sh
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
set -e
set -x
cd tests/
mkdir -p ./tmp/
cd ./tmp/
touch cfbs.json && rm cfbs.json
rm -rf .git
source "$(dirname "$0")/testlib.sh"
test_init

cfbs --non-interactive init
cfbs search > all.log
cfbs search mpf > mpf.log
cfbs search masterfiles > masterfiles.log

grep "python" all.log
! grep "python" mpf.log
grep "masterfiles" mpf.log
grep "masterfiles" masterfiles.log
run cfbs search
assert_output_contains "python"

run cfbs search mpf
assert_output_not_contains "python"
assert_output_contains "masterfiles"

run cfbs search masterfiles
assert_output_contains "masterfiles"

test_finish
22 changes: 6 additions & 16 deletions tests/shell/007_install.sh
Original file line number Diff line number Diff line change
@@ -1,23 +1,13 @@
if [ x"$UNSAFE_TESTS" = x1 ]
then
echo "Unsafe tests are enabled - running install test"
else
echo "Warning: Unsafe tests are disabled - skipping install test"
exit 0
fi

set -e
set -x
cd tests/
mkdir -p ./tmp/
cd ./tmp/
touch cfbs.json && rm cfbs.json
rm -rf .git
source "$(dirname "$0")/testlib.sh"
skip_unless_unsafe
test_init
rm -rf ~/.cfagent/inputs/

cfbs --non-interactive init
cfbs --non-interactive add autorun
cfbs install

ls ~/.cfagent/inputs/def.json
assert_file_exists ~/.cfagent/inputs/def.json
rm -rf ~/.cfagent/inputs/

test_finish
15 changes: 6 additions & 9 deletions tests/shell/008_remove.sh
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
set -e
set -x
cd tests/
mkdir -p ./tmp/
cd ./tmp/
touch cfbs.json && rm cfbs.json
rm -rf .git
source "$(dirname "$0")/testlib.sh"
test_init

cfbs --non-interactive init
grep '"name": "masterfiles"' cfbs.json
assert_file_contains cfbs.json '"name": "masterfiles"'
cfbs --non-interactive remove masterfiles --non-interactive
! grep '"name": "masterfiles"' cfbs.json
assert_file_not_contains cfbs.json '"name": "masterfiles"'

test_finish
21 changes: 9 additions & 12 deletions tests/shell/009_clean.sh
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
set -e
set -x
cd tests/
mkdir -p ./tmp/
cd ./tmp/
touch cfbs.json && rm cfbs.json
rm -rf .git
source "$(dirname "$0")/testlib.sh"
test_init

cfbs --non-interactive init
cfbs --non-interactive add promise-type-git
grep '"name": "library-for-promise-types-in-python"' cfbs.json
grep '"name": "promise-type-git"' cfbs.json
assert_file_contains cfbs.json '"name": "library-for-promise-types-in-python"'
assert_file_contains cfbs.json '"name": "promise-type-git"'
cfbs --non-interactive remove promise-type-git --non-interactive
! grep '"name": "library-for-promise-types-in-python"' cfbs.json
! grep '"name": "promise-type-git"' cfbs.json
assert_file_not_contains cfbs.json '"name": "library-for-promise-types-in-python"'
assert_file_not_contains cfbs.json '"name": "promise-type-git"'

# Check that clean does nothing:
cat cfbs.json > before.json
cfbs --non-interactive clean
diff cfbs.json before.json
assert_diff cfbs.json before.json

test_finish
29 changes: 13 additions & 16 deletions tests/shell/010_local_add.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
set -e
set -x
cd tests/
mkdir -p ./tmp/
cd ./tmp/
touch cfbs.json && rm cfbs.json
rm -rf .git
source "$(dirname "$0")/testlib.sh"
test_init

cfbs --non-interactive init
cfbs status
Expand All @@ -18,18 +13,20 @@ echo 'bundle agent bogus_bundle {

cfbs --non-interactive add ./bogus_file.cf

grep '"name": "./bogus_file.cf"' cfbs.json
grep '"copy ./bogus_file.cf services/cfbs/bogus_file.cf"' cfbs.json
grep '"policy_files services/cfbs/bogus_file.cf"' cfbs.json
grep '"bundles bogus_bundle"' cfbs.json
assert_file_contains cfbs.json '"name": "./bogus_file.cf"'
assert_file_contains cfbs.json '"copy ./bogus_file.cf services/cfbs/bogus_file.cf"'
assert_file_contains cfbs.json '"policy_files services/cfbs/bogus_file.cf"'
assert_file_contains cfbs.json '"bundles bogus_bundle"'

cfbs status
cfbs build

grep '"inputs"' out/masterfiles/def.json
grep 'bogus_file.cf' out/masterfiles/def.json
assert_file_contains out/masterfiles/def.json '"inputs"'
assert_file_contains out/masterfiles/def.json 'bogus_file.cf'

grep '"control_common_bundlesequence_end"' out/masterfiles/def.json
grep '"bogus_bundle"' out/masterfiles/def.json
assert_file_contains out/masterfiles/def.json '"control_common_bundlesequence_end"'
assert_file_contains out/masterfiles/def.json '"bogus_bundle"'

ls out/masterfiles/services/cfbs/bogus_file.cf
assert_file_exists out/masterfiles/services/cfbs/bogus_file.cf

test_finish
69 changes: 32 additions & 37 deletions tests/shell/011_update.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
set -e
set -x
cd tests/
mkdir -p ./tmp/
cd ./tmp/
touch cfbs.json && rm cfbs.json
rm -rf .git
source "$(dirname "$0")/testlib.sh"
test_init

cfbs --non-interactive init
cfbs --non-interactive add promise-type-ansible@0.1.1
Expand All @@ -16,37 +11,37 @@ cfbs --non-interactive update
# Also, it should not break on new commits(!)
# TODO: Use jq, a python script, cfbs validate or something similar

cat cfbs.json | grep -F "name" | grep -F "Example"
cat cfbs.json | grep -F "type" | grep -F "policy-set"
cat cfbs.json | grep -F "description" | grep -F "Example description"

cat cfbs.json | grep -F "name" | grep -F "promise-type-ansible"
cat cfbs.json | grep -F "version" | grep -F "."
cat cfbs.json | grep -F "commit"
cat cfbs.json | grep -F "added_by" | grep -F "cfbs add"
cat cfbs.json | grep -F "steps"
cat cfbs.json | grep -F "copy ansible_promise.py modules/promises/"
cat cfbs.json | grep -F "append enable.cf services/init.cf"
cat cfbs.json | grep -F "tags" | grep -F "supported" | grep -F "promise-type"
cat cfbs.json | grep -F "by" | grep -F "https://github.com/tranchitella"
cat cfbs.json | grep -F "repo" | grep -F "https://github.com/cfengine/modules"
cat cfbs.json | grep -F "subdirectory" | grep -F "promise-types/ansible"
cat cfbs.json | grep -F "dependencies" | grep -F "library-for-promise-types-in-python"
cat cfbs.json | grep -F "description" | grep -F "Promise type to run ansible playbooks"

cat cfbs.json | grep -F "name" | grep -F "library-for-promise-types-in-python"
cat cfbs.json | grep -F "description" | grep -F "Library enabling promise types implemented in python"
cat cfbs.json | grep -F "tags" | grep -F "supported" | grep -F "library"
cat cfbs.json | grep -F "repo" | grep -F "https://github.com/cfengine/modules"
cat cfbs.json | grep -F "by" | grep -F "https://github.com/cfengine"
cat cfbs.json | grep -F "version" | grep -F "."
cat cfbs.json | grep -F "commit"
cat cfbs.json | grep -F "subdirectory" | grep -F "libraries/python"
cat cfbs.json | grep -F "added_by" | grep -F "promise-type-ansible"
cat cfbs.json | grep -F "copy cfengine_module_library.py modules/promises/cfengine_module_library.py"
assert_file_matches_regex cfbs.json '"name".*"Example'
assert_file_matches_regex cfbs.json '"type".*"policy-set"'
assert_file_matches_regex cfbs.json '"description".*"Example description"'

assert_file_matches_regex cfbs.json '"name".*"promise-type-ansible"'
assert_file_matches_regex cfbs.json '"version":.*[0-9]+\.[0-9]+'
assert_file_contains cfbs.json '"commit"'
assert_file_matches_regex cfbs.json '"added_by".*"cfbs add"'
assert_file_contains cfbs.json '"steps"'
assert_file_contains cfbs.json 'copy ansible_promise.py modules/promises/'
assert_file_contains cfbs.json 'append enable.cf services/init.cf'
assert_file_matches_regex cfbs.json '"tags".*"supported"'
assert_file_matches_regex cfbs.json '"by".*"https://github.com/tranchitella"'
assert_file_matches_regex cfbs.json '"repo".*"https://github.com/cfengine/modules"'
assert_file_matches_regex cfbs.json '"subdirectory".*"promise-types/ansible"'
assert_file_matches_regex cfbs.json '"dependencies".*"library-for-promise-types-in-python"'
assert_file_matches_regex cfbs.json '"description".*"Promise type to run ansible playbooks'

assert_file_matches_regex cfbs.json '"name".*"library-for-promise-types-in-python"'
assert_file_matches_regex cfbs.json '"description".*"Library enabling promise types implemented in python'
assert_file_matches_regex cfbs.json '"tags".*"library"'
assert_file_matches_regex cfbs.json '"repo".*"https://github.com/cfengine/modules"'
assert_file_matches_regex cfbs.json '"by".*"https://github.com/cfengine"'
assert_file_matches_regex cfbs.json '"subdirectory".*"libraries/python"'
assert_file_matches_regex cfbs.json '"added_by".*"promise-type-ansible"'
assert_file_contains cfbs.json 'copy cfengine_module_library.py modules/promises/cfengine_module_library.py'

cfbs status
cfbs build

ls out/masterfiles/promises.cf
ls out/masterfiles/modules/promises/ansible_promise.py
assert_file_exists out/masterfiles/promises.cf
assert_file_exists out/masterfiles/modules/promises/ansible_promise.py

test_finish
9 changes: 4 additions & 5 deletions tests/shell/012_prepend_dot_slash.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
set -e
set -x
cd tests/
mkdir -p ./tmp/
cd ./tmp/
source "$(dirname "$0")/testlib.sh"
test_init

echo '
bundle agent test_bundle
Expand Down Expand Up @@ -38,3 +35,5 @@ rm -rf .git
cfbs --non-interactive init
cfbs --non-interactive add test_policy.cf
cfbs --non-interactive remove ./test_policy.cf --non-interactive

test_finish
29 changes: 13 additions & 16 deletions tests/shell/013_add_url_commit.sh
Original file line number Diff line number Diff line change
@@ -1,21 +1,16 @@
set -e
set -x
cd tests/
mkdir -p ./tmp/
cd ./tmp/
touch cfbs.json && rm cfbs.json
rm -rf .git
source "$(dirname "$0")/testlib.sh"
test_init

cfbs --non-interactive init
cfbs --non-interactive add https://github.com/basvandervlies/cf_surfsara_lib@09e07dda690f5806d5f17be8e71d9fdcc51bbdf1

grep https://github.com/basvandervlies/cf_surfsara_lib cfbs.json
grep 09e07dda690f5806d5f17be8e71d9fdcc51bbdf1 cfbs.json
grep scl cfbs.json
assert_file_contains cfbs.json https://github.com/basvandervlies/cf_surfsara_lib
assert_file_contains cfbs.json 09e07dda690f5806d5f17be8e71d9fdcc51bbdf1
assert_file_contains cfbs.json scl

cfbs build
ls out/masterfiles/lib/scl/
grep scl_dmidecode_example out/masterfiles/scl_example.json
assert_file_exists out/masterfiles/lib/scl/
assert_file_contains out/masterfiles/scl_example.json scl_dmidecode_example

# Build should be possible to do on another machine
# so let's test that it works after deleting the things which
Expand All @@ -27,14 +22,16 @@ rm -rf out/
rm -rf ~/.cfengine/cfbs

cfbs build
ls out/masterfiles/lib/scl/
grep scl_dmidecode_example out/masterfiles/scl_example.json
assert_file_exists out/masterfiles/lib/scl/
assert_file_contains out/masterfiles/scl_example.json scl_dmidecode_example

# Finally, let's also test that we can build it again (now with the cached
# files)

rm -rf out/

cfbs build
ls out/masterfiles/lib/scl/
grep scl_dmidecode_example out/masterfiles/scl_example.json
assert_file_exists out/masterfiles/lib/scl/
assert_file_contains out/masterfiles/scl_example.json scl_dmidecode_example

test_finish
Loading