From e0364ec6330a926455b41b216b9859908357c4a2 Mon Sep 17 00:00:00 2001 From: Antonio Murdaca Date: Sat, 8 Oct 2016 14:24:16 +0200 Subject: [PATCH] add containers restore test Signed-off-by: Antonio Murdaca --- test/ctr.bats | 4 ++-- test/helpers.bash | 17 +++++++++-------- test/pod.bats | 4 ++-- test/restore.bats | 41 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 54 insertions(+), 12 deletions(-) create mode 100644 test/restore.bats diff --git a/test/ctr.bats b/test/ctr.bats index 0ede579c..c39285ef 100644 --- a/test/ctr.bats +++ b/test/ctr.bats @@ -33,8 +33,8 @@ function teardown() { run ocic pod remove --id "$pod_id" echo "$output" [ "$status" -eq 0 ] - stop_ocid cleanup_pods + stop_ocid } @test "ctr lifecycle" { @@ -103,6 +103,6 @@ function teardown() { run ocic ctr list echo "$output" [ "$status" -eq 0 ] - stop_ocid cleanup_pods + stop_ocid } diff --git a/test/helpers.bash b/test/helpers.bash index ddcc81f5..13bced98 100644 --- a/test/helpers.bash +++ b/test/helpers.bash @@ -77,21 +77,22 @@ function start_ocid() { } function cleanup_pods() { - run ocic pod list + run ocic pod list --quiet if [ "$status" -eq 0 ]; then - printf '%s\n' "$output" | while IFS= read -r line - do - pod=$(echo "$line" | sed -e 's/ID: //g') - ocic pod stop --id "$pod" - ocic pod remove --id "$pod" - done + if [ "$output" != "" ]; then + printf '%s\n' "$output" | while IFS= read -r line + do + ocic pod stop --id "$line" + ocic pod remove --id "$line" + done + fi fi } # Stop ocid. function stop_ocid() { if [ "$OCID_PID" != "" ]; then - kill "$OCID_PID" >/dev/null 2>&1 + kill -9 "$OCID_PID" >/dev/null 2>&1 fi } diff --git a/test/pod.bats b/test/pod.bats index 9b8f918a..25f14b7a 100644 --- a/test/pod.bats +++ b/test/pod.bats @@ -35,8 +35,8 @@ function teardown() { run ocic pod remove --id "$id" echo "$output" [ "$status" -eq 0 ] - stop_ocid cleanup_pods + stop_ocid } @test "pod remove" { @@ -60,6 +60,6 @@ function teardown() { run ocic pod remove --id "$pod_id" echo "$output" [ "$status" -eq 0 ] - stop_ocid cleanup_pods + stop_ocid } diff --git a/test/restore.bats b/test/restore.bats new file mode 100644 index 00000000..88a6a19e --- /dev/null +++ b/test/restore.bats @@ -0,0 +1,41 @@ +#!/usr/bin/env bats + +load helpers + +function teardown() { + cleanup_test +} + +@test "ocid restore" { + # this test requires docker, thus it can't yet be run in a container + if [ "$TRAVIS" = "true" ]; then # instead of $TRAVIS, add a function is_containerized to skip here + skip "cannot yet run this test in a container, use sudo make localintegration" + fi + + start_ocid + run ocic pod create --config "$TESTDATA"/sandbox_config.json + echo "$output" + [ "$status" -eq 0 ] + pod_id="$output" + + run ocic ctr create --config "$TESTDATA"/container_config.json --pod "$pod_id" + echo "$output" + [ "$status" -eq 0 ] + ctr_id="$output" + + stop_ocid + + start_ocid + run ocic pod list + echo "$output" + [ "$status" -eq 0 ] + #[[ "${output}" == *'${pod_id}'* ]] + + run ocic ctr list + echo "$output" + [ "$status" -eq 0 ] + #[[ "${output}" == *'${pod_id}'* ]] + + cleanup_pods + stop_ocid +}