Skip to content

Commit 05e700a

Browse files
committed
test/system: Rewrite a test using the standard Bats helpers
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
1 parent 8fbd601 commit 05e700a

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

test/system/104-run.bats

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -203,16 +203,18 @@ teardown() {
203203
@test "run: 'sudo id' inside the default container" {
204204
create_default_container
205205

206-
output="$("$TOOLBX" run sudo id 2>"$BATS_TEST_TMPDIR/stderr")"
207-
status="$?"
208-
209-
echo "# stderr"
210-
cat "$BATS_TEST_TMPDIR/stderr"
211-
echo "# stdout"
212-
echo "$output"
206+
run --keep-empty-lines --separate-stderr "$TOOLBX" run sudo id
213207

214208
assert_success
215-
assert_output --partial "uid=0(root)"
209+
assert_line --index 0 "uid=0(root) gid=0(root) groups=0(root)"
210+
211+
if check_bats_version 1.10.0; then
212+
assert [ ${#lines[@]} -eq 1 ]
213+
else
214+
assert [ ${#lines[@]} -eq 2 ]
215+
fi
216+
217+
assert [ ${#stderr_lines[@]} -eq 0 ]
216218
}
217219

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

0 commit comments

Comments
 (0)