diff --git a/test/ctr.bats b/test/ctr.bats index c39285ef..2244eda5 100644 --- a/test/ctr.bats +++ b/test/ctr.bats @@ -33,6 +33,7 @@ function teardown() { run ocic pod remove --id "$pod_id" echo "$output" [ "$status" -eq 0 ] + cleanup_ctrs cleanup_pods stop_ocid } @@ -103,6 +104,7 @@ function teardown() { run ocic ctr list echo "$output" [ "$status" -eq 0 ] + cleanup_ctrs cleanup_pods stop_ocid } diff --git a/test/helpers.bash b/test/helpers.bash index 13bced98..17bbe3af 100644 --- a/test/helpers.bash +++ b/test/helpers.bash @@ -76,6 +76,19 @@ function start_ocid() { wait_until_reachable } +function cleanup_ctrs() { + run ocic ctr list --quiet + if [ "$status" -eq 0 ]; then + if [ "$output" != "" ]; then + printf '%s\n' "$output" | while IFS= read -r line + do + ocic ctr stop --id "$line" + ocic ctr remove --id "$line" + done + fi + fi +} + function cleanup_pods() { run ocic pod list --quiet if [ "$status" -eq 0 ]; then @@ -92,7 +105,7 @@ function cleanup_pods() { # Stop ocid. function stop_ocid() { if [ "$OCID_PID" != "" ]; then - kill -9 "$OCID_PID" >/dev/null 2>&1 + kill "$OCID_PID" >/dev/null 2>&1 fi } diff --git a/test/pod.bats b/test/pod.bats index 25f14b7a..c6b719d4 100644 --- a/test/pod.bats +++ b/test/pod.bats @@ -35,6 +35,7 @@ function teardown() { run ocic pod remove --id "$id" echo "$output" [ "$status" -eq 0 ] + cleanup_ctrs cleanup_pods stop_ocid } @@ -60,6 +61,7 @@ function teardown() { run ocic pod remove --id "$pod_id" echo "$output" [ "$status" -eq 0 ] + cleanup_ctrs cleanup_pods stop_ocid } diff --git a/test/restore.bats b/test/restore.bats index 88a6a19e..b3b206a9 100644 --- a/test/restore.bats +++ b/test/restore.bats @@ -29,13 +29,16 @@ function teardown() { run ocic pod list echo "$output" [ "$status" -eq 0 ] - #[[ "${output}" == *'${pod_id}'* ]] + [[ "${output}" != "" ]] + [[ "${output}" =~ "${pod_id}" ]] run ocic ctr list echo "$output" [ "$status" -eq 0 ] - #[[ "${output}" == *'${pod_id}'* ]] + [[ "${output}" != "" ]] + [[ "${output}" =~ "${pod_id}" ]] + cleanup_ctrs cleanup_pods stop_ocid }