Files
runc/tests/integration/root.bats
T
Kir Kolyshkin 985546b445 tests/int: BATS_TMPDIR -> BATS_RUN_TMPDIR
It's a little known fact, but BATS_TMPDIR is just /tmp, and it is not
being cleaned by bats after the test.

BATS_RUN_TMPDIR (available since bats 1.2.1) is $BATS_TMPDIR/bats-run-$$
(i.e. it is per bats run and includes PID), and it is cleaned up after
the test (unless --no-tmpdir-cleanup is given).

Use BATS_RUN_TMPDIR for better isolation and cleanup.

[v2: check for BATS_RUN_TMPDIR, effectively requiring bats >= 1.2.1]

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2021-02-08 12:46:58 -08:00

55 lines
1.2 KiB
Bash

#!/usr/bin/env bats
load helpers
function setup() {
unset ALT_ROOT
teardown
setup_busybox
ALT_ROOT=$(mktemp -d "$BATS_RUN_TMPDIR/runc-2.XXXXXX")
}
function teardown() {
if [ -n "$ALT_ROOT" ]; then
ROOT=$ALT_ROOT teardown_running_container test_dotbox
rm -rf "$ALT_ROOT"
fi
teardown_busybox
}
@test "global --root" {
# run busybox detached using $ALT_ROOT for state
ROOT=$ALT_ROOT runc run -d --console-socket "$CONSOLE_SOCKET" test_dotbox
[ "$status" -eq 0 ]
# run busybox detached in default root
runc run -d --console-socket "$CONSOLE_SOCKET" test_busybox
[ "$status" -eq 0 ]
runc state test_busybox
[ "$status" -eq 0 ]
[[ "${output}" == *"running"* ]]
ROOT=$ALT_ROOT runc state test_dotbox
[ "$status" -eq 0 ]
[[ "${output}" == *"running"* ]]
ROOT=$ALT_ROOT runc state test_busybox
[ "$status" -ne 0 ]
runc state test_dotbox
[ "$status" -ne 0 ]
runc kill test_busybox KILL
[ "$status" -eq 0 ]
wait_for_container 10 1 test_busybox stopped
runc delete test_busybox
[ "$status" -eq 0 ]
ROOT=$ALT_ROOT runc kill test_dotbox KILL
[ "$status" -eq 0 ]
ROOT=$ALT_ROOT wait_for_container 10 1 test_dotbox stopped
ROOT=$ALT_ROOT runc delete test_dotbox
[ "$status" -eq 0 ]
}