ENT-13699: Add shell test framework and migrate all tests#304
ENT-13699: Add shell test framework and migrate all tests#304larsewi wants to merge 50 commits intocfengine:masterfrom
Conversation
Introduced tests/shell/testlib.sh with lifecycle functions (test_init, test_finish, skip_unless_unsafe), assertion helpers, and capture utilities for gradual migration of shell tests. Updated tests/shell/all.sh to report per-test timing, pass/fail/skip status, and a summary. Ticket: ENT-13699 Signed-off-by: Lars Erik Wik <lars.erik.wik@northern.tech> Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
… and assert_git_no_diffs Ticket: ENT-13699 Signed-off-by: Lars Erik Wik <lars.erik.wik@northern.tech> Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Ticket: ENT-13699 Signed-off-by: Lars Erik Wik <lars.erik.wik@northern.tech> Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Ticket: ENT-13699 Signed-off-by: Lars Erik Wik <lars.erik.wik@northern.tech> Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Ticket: ENT-13699 Signed-off-by: Lars Erik Wik <lars.erik.wik@northern.tech> Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Ticket: ENT-13699 Signed-off-by: Lars Erik Wik <lars.erik.wik@northern.tech> Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Ticket: ENT-13699 Signed-off-by: Lars Erik Wik <lars.erik.wik@northern.tech> Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Ticket: ENT-13699 Signed-off-by: Lars Erik Wik <lars.erik.wik@northern.tech> Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Ticket: ENT-13699 Signed-off-by: Lars Erik Wik <lars.erik.wik@northern.tech> Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Ticket: ENT-13699 Signed-off-by: Lars Erik Wik <lars.erik.wik@northern.tech> Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Ticket: ENT-13699 Signed-off-by: Lars Erik Wik <lars.erik.wik@northern.tech> Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Ticket: ENT-13699 Signed-off-by: Lars Erik Wik <lars.erik.wik@northern.tech> Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Ticket: ENT-13699 Signed-off-by: Lars Erik Wik <lars.erik.wik@northern.tech> Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Ticket: ENT-13699 Signed-off-by: Lars Erik Wik <lars.erik.wik@northern.tech> Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Ticket: ENT-13699 Signed-off-by: Lars Erik Wik <lars.erik.wik@northern.tech> Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Ticket: ENT-13699 Signed-off-by: Lars Erik Wik <lars.erik.wik@northern.tech> Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Ticket: ENT-13699 Signed-off-by: Lars Erik Wik <lars.erik.wik@northern.tech> Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Ticket: ENT-13699 Signed-off-by: Lars Erik Wik <lars.erik.wik@northern.tech> Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Ticket: ENT-13699 Signed-off-by: Lars Erik Wik <lars.erik.wik@northern.tech> Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Ticket: ENT-13699 Signed-off-by: Lars Erik Wik <lars.erik.wik@northern.tech> Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Ticket: ENT-13699 Signed-off-by: Lars Erik Wik <lars.erik.wik@northern.tech> Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Ticket: ENT-13699 Signed-off-by: Lars Erik Wik <lars.erik.wik@northern.tech> Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Ticket: ENT-13699 Signed-off-by: Lars Erik Wik <lars.erik.wik@northern.tech> Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Ticket: ENT-13699 Signed-off-by: Lars Erik Wik <lars.erik.wik@northern.tech> Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Ticket: ENT-13699 Signed-off-by: Lars Erik Wik <lars.erik.wik@northern.tech> Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Ticket: ENT-13699 Signed-off-by: Lars Erik Wik <lars.erik.wik@northern.tech> Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Ticket: ENT-13699 Signed-off-by: Lars Erik Wik <lars.erik.wik@northern.tech> Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Ticket: ENT-13699 Signed-off-by: Lars Erik Wik <lars.erik.wik@northern.tech> Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Ticket: ENT-13699 Signed-off-by: Lars Erik Wik <lars.erik.wik@northern.tech> Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Ticket: ENT-13699 Signed-off-by: Lars Erik Wik <lars.erik.wik@northern.tech> Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Ticket: ENT-13699 Signed-off-by: Lars Erik Wik <lars.erik.wik@northern.tech> Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Ticket: ENT-13699 Signed-off-by: Lars Erik Wik <lars.erik.wik@northern.tech> Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Ticket: ENT-13699 Signed-off-by: Lars Erik Wik <lars.erik.wik@northern.tech> Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Ticket: ENT-13699 Signed-off-by: Lars Erik Wik <lars.erik.wik@northern.tech> Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Ticket: ENT-13699 Signed-off-by: Lars Erik Wik <lars.erik.wik@northern.tech> Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Ticket: ENT-13699 Signed-off-by: Lars Erik Wik <lars.erik.wik@northern.tech> Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Ticket: ENT-13699 Signed-off-by: Lars Erik Wik <lars.erik.wik@northern.tech> Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Ticket: ENT-13699 Signed-off-by: Lars Erik Wik <lars.erik.wik@northern.tech> Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Ticket: ENT-13699 Signed-off-by: Lars Erik Wik <lars.erik.wik@northern.tech> Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Ticket: ENT-13699 Signed-off-by: Lars Erik Wik <lars.erik.wik@northern.tech> Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Ticket: ENT-13699 Signed-off-by: Lars Erik Wik <lars.erik.wik@northern.tech> Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Ticket: ENT-13699 Signed-off-by: Lars Erik Wik <lars.erik.wik@northern.tech> Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Ticket: ENT-13699 Signed-off-by: Lars Erik Wik <lars.erik.wik@northern.tech> Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Ticket: ENT-13699 Signed-off-by: Lars Erik Wik <lars.erik.wik@northern.tech> Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Ticket: ENT-13699 Signed-off-by: Lars Erik Wik <lars.erik.wik@northern.tech> Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Ticket: ENT-13699 Signed-off-by: Lars Erik Wik <lars.erik.wik@northern.tech> Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Ticket: ENT-13699 Signed-off-by: Lars Erik Wik <lars.erik.wik@northern.tech> Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Ticket: ENT-13699 Signed-off-by: Lars Erik Wik <lars.erik.wik@northern.tech> Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Ticket: ENT-13699 Signed-off-by: Lars Erik Wik <lars.erik.wik@northern.tech> Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Ticket: ENT-13699 Signed-off-by: Lars Erik Wik <lars.erik.wik@northern.tech> Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
ba33364 to
de17ea3
Compare
|
@cf-bottom Jenkins please :) |
|
Sure, I triggered a build: Jenkins: https://ci.cfengine.com/job/pr-pipeline/13396/ Packages: http://buildcache.cfengine.com/packages/testing-pr/jenkins-pr-pipeline-13396/ |
There was a problem hiding this comment.
I can't say I love this PR. There is a lot of change and now the scripts can't be written free-hand in bash... you must refer to the testlib often to know what functions to use.
Also, I am not sure how much is improved other than maybe silencing "good" outputs to make analysis easier... which is a welcome change so +1 on that account.
I think all the migrated commits could be squashed into one for easier review... #next-time
| _failed=$((_failed + 1)) | ||
| _failures="${_failures} ${test_name}\n" | ||
| echo "--- FAIL: $test_name (${elapsed}s)" | ||
| echo "$output" | tail -30 |
There was a problem hiding this comment.
In order to debug fully it would be nice to save the complete output to an artifacts directory that is then slurped up and archived with the github workflow.
| # --- Lifecycle --- | ||
|
|
||
| skip_unless_unsafe() { | ||
| if [ "x${UNSAFE_TESTS:-}" != x1 ]; then |
There was a problem hiding this comment.
is shellcheck running on this? It should complain about x-prefix comparisons that are not generally needed.
| ! grep -qF "$2" "$1" || _test_fail "Expected file '$1' to NOT contain: $2" | ||
| } | ||
|
|
||
| assert_file_matches() { |
There was a problem hiding this comment.
assert_file_matches_regex() would be more descriptive... I was thinking "entire file match" as-is.
| || _test_fail "Expected files to differ but they are identical: $1 vs $2" | ||
| } | ||
|
|
||
| assert_count() { |
There was a problem hiding this comment.
maybe assert_string_occurrences() to be clear: not a regex (string instead) and check the number of matches.
| { | ||
| reports: | ||
| "Hello from $(this.bundle)"; | ||
| "Hello from \$(this.bundle)"; |
There was a problem hiding this comment.
why this change? The result of the change would add a prefixed backslash for no reason right?
R: Hello from \foo
| { | ||
| reports: | ||
| "Hello from $(this.bundle)"; | ||
| "Hello from \$(this.bundle)"; |
There was a problem hiding this comment.
probably don't need this prefixed backslash in the output.
There was a problem hiding this comment.
and at no time are we testing the output of this policy so pretty inconsequential either way.
Summary
tests/shell/testlib.shwith lifecycle functions (test_init,test_finish,skip_unless_unsafe), assertion helpers (assert_file_exists,assert_file_contains,assert_failure,assert_equal, etc.), and capture utilities (run,run_expect_failure)tests/shell/all.shrunner with per-test timing, pass/fail/skip reporting, and summary outputcommon.shgit helpers intotestlib.shasassert_git_tracksandassert_git_no_diffs🤖 Generated with Claude Code
Example output:
If a test fails it will look like this: