Skip to content

Commit

Permalink
tests/integration: rm excessive run use
Browse files Browse the repository at this point in the history
Bats' run should only be used when we want to check both the command
output and its non-zero exit status.

Otherwise, we can rely on implicit exit code check (as the tests are
run with set -e), or use if, etc.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
  • Loading branch information
kolyshkin committed Oct 27, 2020
1 parent d3ed331 commit ac8e585
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 67 deletions.
9 changes: 3 additions & 6 deletions tests/integration/checkpoint.bats
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ function check_pipes() {
echo Ping >&${in_w}
exec {in_w}>&-
exec {out_w}>&-
run cat <&${out_r}
[ "$status" -eq 0 ]
output=$(cat <&${out_r})
[[ "${output}" == *"ponG Ping"* ]]
}

Expand Down Expand Up @@ -159,8 +158,7 @@ function simple_cr() {

@test "checkpoint --lazy-pages and restore" {
# check if lazy-pages is supported
run "${CRIU}" check --feature uffd-noncoop
if [ "$status" -eq 1 ]; then
if ! "${CRIU}" check --feature uffd-noncoop; then
skip "this criu does not support lazy migration"
fi

Expand Down Expand Up @@ -218,8 +216,7 @@ function simple_cr() {

@test "checkpoint and restore in external network namespace" {
# check if external_net_ns is supported; only with criu 3.10++
run "${CRIU}" check --feature external_net_ns
if [ "$status" -eq 1 ]; then
if ! "${CRIU}" check --feature external_net_ns; then
# this criu does not support external_net_ns; skip the test
skip "this criu does not support external network namespaces"
fi
Expand Down
14 changes: 4 additions & 10 deletions tests/integration/create.bats
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,7 @@ function teardown() {
# check pid.txt was generated
[ -e pid.txt ]

run cat pid.txt
[ "$status" -eq 0 ]
[[ ${lines[0]} == $(__runc state test_busybox | jq '.pid') ]]
[[ $(cat pid.txt) == $(__runc state test_busybox | jq '.pid') ]]

# start the command
runc start test_busybox
Expand All @@ -64,10 +62,8 @@ function teardown() {

@test "runc create --pid-file with new CWD" {
# create pid_file directory as the CWD
run mkdir pid_file
[ "$status" -eq 0 ]
run cd pid_file
[ "$status" -eq 0 ]
mkdir pid_file
cd pid_file

runc create --pid-file pid.txt -b "$BUSYBOX_BUNDLE" --console-socket "$CONSOLE_SOCKET" test_busybox
[ "$status" -eq 0 ]
Expand All @@ -77,9 +73,7 @@ function teardown() {
# check pid.txt was generated
[ -e pid.txt ]

run cat pid.txt
[ "$status" -eq 0 ]
[[ ${lines[0]} == $(__runc state test_busybox | jq '.pid') ]]
[[ $(cat pid.txt) == $(__runc state test_busybox | jq '.pid') ]]

# start the command
runc start test_busybox
Expand Down
9 changes: 3 additions & 6 deletions tests/integration/debug.bats
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ function teardown() {
[ -e log.out ]

# check expected debug output was sent to log.out
run cat log.out
[ "$status" -eq 0 ]
output=$(cat log.out)
[[ "${output}" == *"level=debug"* ]]
[[ "${output}" == *"nsexec started"* ]]
[[ "${output}" == *"child process in init()"* ]]
Expand All @@ -54,8 +53,7 @@ function teardown() {
[ -e log.out ]

# check expected debug output was sent to log.out
run cat log.out
[ "$status" -eq 0 ]
output=$(cat log.out)
[[ "${output}" == *"level=debug"* ]]
[[ "${output}" == *"nsexec started"* ]]
[[ "${output}" == *"child process in init()"* ]]
Expand All @@ -73,8 +71,7 @@ function teardown() {
[ -e log.out ]

# check expected debug output was sent to log.out
run cat log.out
[ "$status" -eq 0 ]
output=$(cat log.out)
[[ "${output}" == *'"level":"debug"'* ]]
[[ "${output}" == *"nsexec started"* ]]
[[ "${output}" == *"child process in init()"* ]]
Expand Down
6 changes: 2 additions & 4 deletions tests/integration/delete.bats
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ function teardown() {
runc state testbusyboxdelete
[ "$status" -ne 0 ]

run find /sys/fs/cgroup -wholename '*testbusyboxdelete*' -type d
[ "$status" -eq 0 ]
output=$(find /sys/fs/cgroup -wholename '*testbusyboxdelete*' -type d)
[ "$output" = "" ] || fail "cgroup not cleaned up correctly: $output"
}

Expand Down Expand Up @@ -99,8 +98,7 @@ EOF
runc state test_busybox
[ "$status" -ne 0 ]

run find /sys/fs/cgroup -wholename '*testbusyboxdelete*' -type d
[ "$status" -eq 0 ]
output=$(find /sys/fs/cgroup -wholename '*testbusyboxdelete*' -type d)
[ "$output" = "" ] || fail "cgroup not cleaned up correctly: $output"
}

Expand Down
13 changes: 5 additions & 8 deletions tests/integration/events.bats
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,9 @@ function teardown() {

[ -e events.log ]

run cat events.log
[ "$status" -eq 0 ]
[[ "${lines[0]}" == [\{]"\"type\""[:]"\"stats\""[,]"\"id\""[:]"\"test_busybox\""[,]* ]]
[[ "${lines[0]}" == *"data"* ]]
output=$(head -1 events.log)
[[ "$output" == [\{]"\"type\""[:]"\"stats\""[,]"\"id\""[:]"\"test_busybox\""[,]* ]]
[[ "$output" == *"data"* ]]
}

@test "events --interval 1s" {
Expand All @@ -78,8 +77,7 @@ function teardown() {

[ -e events.log ]

run eval "grep -q 'test_busybox' events.log"
[ "$status" -eq 0 ]
grep -q 'test_busybox' events.log
}

@test "events --interval 100ms" {
Expand Down Expand Up @@ -108,8 +106,7 @@ function teardown() {

[ -e events.log ]

run eval "grep -q 'test_busybox' events.log"
[ "$status" -eq 0 ]
grep -q 'test_busybox' events.log
}

@test "events oom" {
Expand Down
20 changes: 8 additions & 12 deletions tests/integration/exec.bats
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,15 @@ function teardown() {
# check pid.txt was generated
[ -e pid.txt ]

run cat pid.txt
[ "$status" -eq 0 ]
[[ ${lines[0]} =~ [0-9]+ ]]
[[ ${lines[0]} != $(__runc state test_busybox | jq '.pid') ]]
output=$(cat pid.txt)
[[ "$output" =~ [0-9]+ ]]
[[ "$output" != $(__runc state test_busybox | jq '.pid') ]]
}

@test "runc exec --pid-file with new CWD" {
# create pid_file directory as the CWD
run mkdir pid_file
[ "$status" -eq 0 ]
run cd pid_file
[ "$status" -eq 0 ]
mkdir pid_file
cd pid_file

# run busybox detached
runc run -d -b "$BUSYBOX_BUNDLE" --console-socket "$CONSOLE_SOCKET" test_busybox
Expand All @@ -60,10 +57,9 @@ function teardown() {
# check pid.txt was generated
[ -e pid.txt ]

run cat pid.txt
[ "$status" -eq 0 ]
[[ ${lines[0]} =~ [0-9]+ ]]
[[ ${lines[0]} != $(__runc state test_busybox | jq '.pid') ]]
output=$(cat pid.txt)
[[ "$output" =~ [0-9]+ ]]
[[ "$output" != $(__runc state test_busybox | jq '.pid') ]]
}

@test "runc exec ls -la" {
Expand Down
14 changes: 6 additions & 8 deletions tests/integration/helpers.bash
Original file line number Diff line number Diff line change
Expand Up @@ -423,8 +423,7 @@ function teardown_recvtty() {

function setup_busybox() {
setup_recvtty
run mkdir "$BUSYBOX_BUNDLE"
run mkdir "$BUSYBOX_BUNDLE"/rootfs
mkdir -p "$BUSYBOX_BUNDLE"/rootfs
if [ -e "/testdata/busybox.tar" ]; then
BUSYBOX_IMAGE="/testdata/busybox.tar"
fi
Expand All @@ -438,8 +437,7 @@ function setup_busybox() {

function setup_hello() {
setup_recvtty
run mkdir "$HELLO_BUNDLE"
run mkdir "$HELLO_BUNDLE"/rootfs
mkdir -p "$HELLO_BUNDLE"/rootfs
tar --exclude './dev/*' -C "$HELLO_BUNDLE"/rootfs -xf "$HELLO_IMAGE"
cd "$HELLO_BUNDLE"
runc_spec
Expand All @@ -453,7 +451,7 @@ function setup_debian() {
fi

setup_recvtty
run mkdir "$DEBIAN_BUNDLE"
mkdir -p "$DEBIAN_BUNDLE"

if [ ! -d "$DEBIAN_ROOTFS/rootfs" ]; then
get_and_extract_debian "$DEBIAN_BUNDLE"
Expand All @@ -479,19 +477,19 @@ function teardown_busybox() {
cd "$INTEGRATION_ROOT"
teardown_recvtty
teardown_running_container test_busybox
run rm -f -r "$BUSYBOX_BUNDLE"
rm -f -r "$BUSYBOX_BUNDLE"
}

function teardown_hello() {
cd "$INTEGRATION_ROOT"
teardown_recvtty
teardown_running_container test_hello
run rm -f -r "$HELLO_BUNDLE"
rm -f -r "$HELLO_BUNDLE"
}

function teardown_debian() {
cd "$INTEGRATION_ROOT"
teardown_recvtty
teardown_running_container test_debian
run rm -f -r "$DEBIAN_BUNDLE"
rm -f -r "$DEBIAN_BUNDLE"
}
14 changes: 4 additions & 10 deletions tests/integration/start_detached.bats
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,13 @@ function teardown() {
# check pid.txt was generated
[ -e pid.txt ]

run cat pid.txt
[ "$status" -eq 0 ]
[[ ${lines[0]} == $(__runc state test_busybox | jq '.pid') ]]
[[ "$(cat pid.txt)" == $(__runc state test_busybox | jq '.pid') ]]
}

@test "runc run detached --pid-file with new CWD" {
# create pid_file directory as the CWD
run mkdir pid_file
[ "$status" -eq 0 ]
run cd pid_file
[ "$status" -eq 0 ]
mkdir pid_file
cd pid_file

# run busybox detached
runc run --pid-file pid.txt -d -b "$BUSYBOX_BUNDLE" --console-socket "$CONSOLE_SOCKET" test_busybox
Expand All @@ -70,7 +66,5 @@ function teardown() {
# check pid.txt was generated
[ -e pid.txt ]

run cat pid.txt
[ "$status" -eq 0 ]
[[ ${lines[0]} == $(__runc state test_busybox | jq '.pid') ]]
[[ "$(cat pid.txt)" == $(__runc state test_busybox | jq '.pid') ]]
}
4 changes: 1 addition & 3 deletions tests/integration/start_hello.bats
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,5 @@ function teardown() {
# check pid.txt was generated
[ -e pid.txt ]

run cat pid.txt
[ "$status" -eq 0 ]
[[ ${lines[0]} =~ [0-9]+ ]]
[[ "$(cat pid.txt)" =~ [0-9]+ ]]
}

0 comments on commit ac8e585

Please sign in to comment.