Skip to content

Commit

Permalink
test/system: Rewrite a test using the standard Bats helpers
Browse files Browse the repository at this point in the history
The test was earlier rewritten in commit b0beb68 with custom
code in the hope that it would make it more reliable.  The test has
proven to be reliable in recent times, and the cause for its past
unreliability is unclear.  Therefore, it will be better to remove the
custom code in favour of the standard Bats helpers for the sake of
consistency and readability.

Until Bats 1.10.0, 'run --keep-empty-lines' had a bug where it counted
the trailing newline on the last line as a separate line [1].  However,
Bats 1.10.0 is only available in Fedora >= 39 and is absent from Fedora
38.

[1] Bats commit 6648e2143bffb933
    bats-core/bats-core@6648e2143bffb933
    bats-core/bats-core#708

containers#1506
  • Loading branch information
debarshiray committed Jun 5, 2024
1 parent 8fbd601 commit 05e700a
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions test/system/104-run.bats
Original file line number Diff line number Diff line change
Expand Up @@ -203,16 +203,18 @@ teardown() {
@test "run: 'sudo id' inside the default container" {
create_default_container

output="$("$TOOLBX" run sudo id 2>"$BATS_TEST_TMPDIR/stderr")"
status="$?"

echo "# stderr"
cat "$BATS_TEST_TMPDIR/stderr"
echo "# stdout"
echo "$output"
run --keep-empty-lines --separate-stderr "$TOOLBX" run sudo id

assert_success
assert_output --partial "uid=0(root)"
assert_line --index 0 "uid=0(root) gid=0(root) groups=0(root)"

if check_bats_version 1.10.0; then
assert [ ${#lines[@]} -eq 1 ]
else
assert [ ${#lines[@]} -eq 2 ]
fi

assert [ ${#stderr_lines[@]} -eq 0 ]
}

@test "run: Ensure that /run/.containerenv exists" {
Expand Down

0 comments on commit 05e700a

Please sign in to comment.