tests/integration: rm excessive run use

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>
This commit is contained in:
Kir Kolyshkin
2020-10-22 08:04:05 -07:00
parent e32716d3da
commit 2ceb97196e
9 changed files with 36 additions and 67 deletions
+3 -6
View File
@@ -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"* ]]
}
@@ -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
@@ -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
+4 -10
View File
@@ -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
@@ -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 ]
@@ -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
+3 -6
View File
@@ -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()"* ]]
@@ -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()"* ]]
@@ -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()"* ]]
+2 -4
View File
@@ -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"
}
@@ -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"
}
+5 -8
View File
@@ -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" {
@@ -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" {
@@ -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" {
+8 -12
View File
@@ -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
@@ -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" {
+6 -8
View File
@@ -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
@@ -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
@@ -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"
@@ -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"
}
+4 -10
View File
@@ -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
@@ -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') ]]
}
+1 -3
View File
@@ -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]+ ]]
}