Skip to content

Commit

Permalink
test/system: Limit the scope of temporary files used by a single test
Browse files Browse the repository at this point in the history
BATS_TMPDIR is the base directory used by Bats for all temporary files
and directories, and BATS_TEST_TMPDIR is unique to each test [1].  It's
better to limit the scope of the tests' temporary files as much as
possible to avoid unexpected collisions with Bats' own internal
temporary files.

[1] https://bats-core.readthedocs.io/en/stable/writing-tests.html

containers#1327
  • Loading branch information
debarshiray committed Jun 30, 2023
1 parent c43cf5d commit ea91335
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions test/system/104-run.bats
Original file line number Diff line number Diff line change
Expand Up @@ -166,11 +166,11 @@ teardown() {
@test "run: 'sudo id' inside the default container" {
create_default_container

output="$($TOOLBOX --verbose run sudo id 2>$BATS_TMPDIR/stderr)"
output="$($TOOLBOX --verbose run sudo id 2>$BATS_TEST_TMPDIR/stderr)"
status="$?"

echo "# stderr"
cat $BATS_TMPDIR/stderr
cat $BATS_TEST_TMPDIR/stderr
echo "# stdout"
echo $output

Expand Down
6 changes: 3 additions & 3 deletions test/system/libs/helpers.bash
Original file line number Diff line number Diff line change
Expand Up @@ -227,9 +227,9 @@ function _clean_docker_registry() {


function build_image_without_name() {
echo -e "FROM scratch\n\nLABEL com.github.containers.toolbox=\"true\"" > "$BATS_TMPDIR"/Containerfile
echo -e "FROM scratch\n\nLABEL com.github.containers.toolbox=\"true\"" > "$BATS_TEST_TMPDIR"/Containerfile

run $PODMAN build "$BATS_TMPDIR"
run $PODMAN build "$BATS_TEST_TMPDIR"

assert_success
assert_line --index 0 --partial "FROM scratch"
Expand All @@ -239,7 +239,7 @@ function build_image_without_name() {
last=$((${#lines[@]}-1))
assert_line --index "$last" --regexp "^[a-f0-9]{64}$"

rm -f "$BATS_TMPDIR"/Containerfile
rm -f "$BATS_TEST_TMPDIR"/Containerfile

echo "${lines[$last]}"
}
Expand Down

0 comments on commit ea91335

Please sign in to comment.