tests/int: stop reusing HELLO_BUNDLE for alt root

Overloading $HELLO_BUNDLE with a second purpose of having an alternative
runc root is confusing.

Instead, let's create a temp directory in setup() and clean it up in
teardown().

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
This commit is contained in:
Kir Kolyshkin
2021-01-21 11:22:20 -08:00
parent 76532fac03
commit 85d5fea468
2 changed files with 28 additions and 18 deletions
+15 -10
View File
@@ -3,49 +3,54 @@
load helpers
function setup() {
unset ALT_ROOT
teardown
setup_busybox
ALT_ROOT=$(mktemp -d "$BATS_TMPDIR/runc-2.XXXXXX")
}
function teardown() {
ROOT="$HELLO_BUNDLE" teardown_running_container test_box1
ROOT="$HELLO_BUNDLE" teardown_running_container test_box2
ROOT="$HELLO_BUNDLE" teardown_running_container test_box3
if [ -n "$ALT_ROOT" ]; then
ROOT="$ALT_ROOT" teardown_running_container test_box1
ROOT="$ALT_ROOT" teardown_running_container test_box2
ROOT="$ALT_ROOT" teardown_running_container test_box3
rm -rf "$ALT_ROOT"
fi
teardown_busybox
}
@test "list" {
# run a few busyboxes detached
ROOT=$HELLO_BUNDLE runc run -d --console-socket "$CONSOLE_SOCKET" test_box1
ROOT=$ALT_ROOT runc run -d --console-socket "$CONSOLE_SOCKET" test_box1
[ "$status" -eq 0 ]
ROOT=$HELLO_BUNDLE runc run -d --console-socket "$CONSOLE_SOCKET" test_box2
ROOT=$ALT_ROOT runc run -d --console-socket "$CONSOLE_SOCKET" test_box2
[ "$status" -eq 0 ]
ROOT=$HELLO_BUNDLE runc run -d --console-socket "$CONSOLE_SOCKET" test_box3
ROOT=$ALT_ROOT runc run -d --console-socket "$CONSOLE_SOCKET" test_box3
[ "$status" -eq 0 ]
ROOT=$HELLO_BUNDLE runc list
ROOT=$ALT_ROOT runc list
[ "$status" -eq 0 ]
[[ ${lines[0]} =~ ID\ +PID\ +STATUS\ +BUNDLE\ +CREATED+ ]]
[[ "${lines[1]}" == *"test_box1"*[0-9]*"running"*$BUSYBOX_BUNDLE*[0-9]* ]]
[[ "${lines[2]}" == *"test_box2"*[0-9]*"running"*$BUSYBOX_BUNDLE*[0-9]* ]]
[[ "${lines[3]}" == *"test_box3"*[0-9]*"running"*$BUSYBOX_BUNDLE*[0-9]* ]]
ROOT=$HELLO_BUNDLE runc list -q
ROOT=$ALT_ROOT runc list -q
[ "$status" -eq 0 ]
[[ "${lines[0]}" == "test_box1" ]]
[[ "${lines[1]}" == "test_box2" ]]
[[ "${lines[2]}" == "test_box3" ]]
ROOT=$HELLO_BUNDLE runc list --format table
ROOT=$ALT_ROOT runc list --format table
[ "$status" -eq 0 ]
[[ ${lines[0]} =~ ID\ +PID\ +STATUS\ +BUNDLE\ +CREATED+ ]]
[[ "${lines[1]}" == *"test_box1"*[0-9]*"running"*$BUSYBOX_BUNDLE*[0-9]* ]]
[[ "${lines[2]}" == *"test_box2"*[0-9]*"running"*$BUSYBOX_BUNDLE*[0-9]* ]]
[[ "${lines[3]}" == *"test_box3"*[0-9]*"running"*$BUSYBOX_BUNDLE*[0-9]* ]]
ROOT=$HELLO_BUNDLE runc list --format json
ROOT=$ALT_ROOT runc list --format json
[ "$status" -eq 0 ]
[[ "${lines[0]}" == [\[][\{]"\"ociVersion\""[:]"\""*[0-9][\.]*[0-9][\.]*[0-9]*"\""[,]"\"id\""[:]"\"test_box1\""[,]"\"pid\""[:]*[0-9][,]"\"status\""[:]*"\"running\""[,]"\"bundle\""[:]*$BUSYBOX_BUNDLE*[,]"\"rootfs\""[:]"\""*"\""[,]"\"created\""[:]*[0-9]*[\}]* ]]
[[ "${lines[0]}" == *[,][\{]"\"ociVersion\""[:]"\""*[0-9][\.]*[0-9][\.]*[0-9]*"\""[,]"\"id\""[:]"\"test_box2\""[,]"\"pid\""[:]*[0-9][,]"\"status\""[:]*"\"running\""[,]"\"bundle\""[:]*$BUSYBOX_BUNDLE*[,]"\"rootfs\""[:]"\""*"\""[,]"\"created\""[:]*[0-9]*[\}]* ]]
+13 -8
View File
@@ -3,18 +3,23 @@
load helpers
function setup() {
unset ALT_ROOT
teardown
setup_busybox
ALT_ROOT=$(mktemp -d "$BATS_TMPDIR/runc-2.XXXXXX")
}
function teardown() {
ROOT="$HELLO_BUNDLE" teardown_running_container test_dotbox
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 $HELLO_BUNDLE for state
ROOT=$HELLO_BUNDLE runc run -d --console-socket "$CONSOLE_SOCKET" test_dotbox
# 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
@@ -25,11 +30,11 @@ function teardown() {
[ "$status" -eq 0 ]
[[ "${output}" == *"running"* ]]
ROOT=$HELLO_BUNDLE runc state test_dotbox
ROOT=$ALT_ROOT runc state test_dotbox
[ "$status" -eq 0 ]
[[ "${output}" == *"running"* ]]
ROOT=$HELLO_BUNDLE runc state test_busybox
ROOT=$ALT_ROOT runc state test_busybox
[ "$status" -ne 0 ]
runc state test_dotbox
@@ -41,9 +46,9 @@ function teardown() {
runc delete test_busybox
[ "$status" -eq 0 ]
ROOT=$HELLO_BUNDLE runc kill test_dotbox KILL
ROOT=$ALT_ROOT runc kill test_dotbox KILL
[ "$status" -eq 0 ]
ROOT=$HELLO_BUNDLE wait_for_container 10 1 test_dotbox stopped
ROOT=$HELLO_BUNDLE runc delete test_dotbox
ROOT=$ALT_ROOT wait_for_container 10 1 test_dotbox stopped
ROOT=$ALT_ROOT runc delete test_dotbox
[ "$status" -eq 0 ]
}