From 05e700af2ad346bfe9516dfd2083ac884787171c Mon Sep 17 00:00:00 2001 From: Debarshi Ray Date: Wed, 5 Jun 2024 20:10:00 +0200 Subject: [PATCH] test/system: Rewrite a test using the standard Bats helpers The test was earlier rewritten in commit b0beb68255374392 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 https://github.com/bats-core/bats-core/commit/6648e2143bffb933 https://github.com/bats-core/bats-core/issues/708 https://github.com/containers/toolbox/pull/1506 --- test/system/104-run.bats | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/test/system/104-run.bats b/test/system/104-run.bats index 642d3246f..8386d23ed 100644 --- a/test/system/104-run.bats +++ b/test/system/104-run.bats @@ -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" {