test: tweak halpers

Signed-off-by: Antonio Murdaca <runcom@redhat.com>
This commit is contained in:
Antonio Murdaca 2016-09-21 11:03:57 +02:00
parent 857aaa7816
commit aebd365cf4
No known key found for this signature in database
GPG key ID: B2BEAD150DE936B9
2 changed files with 18 additions and 12 deletions

View file

@ -15,8 +15,16 @@ OCID_BINARY=${OCID_BINARY:-${OCID_ROOT}/ocid/ocid}
OCIC_BINARY=${OCIC_BINARY:-${OCID_ROOT}/ocid/ocic} OCIC_BINARY=${OCIC_BINARY:-${OCID_ROOT}/ocid/ocic}
# Path of the conmon binary. # Path of the conmon binary.
CONMON_BINARY=${CONMON_BINARY:-${OCID_ROOT}/ocid/conmon/conmon} CONMON_BINARY=${CONMON_BINARY:-${OCID_ROOT}/ocid/conmon/conmon}
# Path of the runc binary.
RUNC_PATH=$(command -v runc || true)
RUNC_BINARY=${RUNC_PATH:-/usr/local/sbin/runc}
PATH=$PATH:$BATS_TMPDIR TESTDIR=$(mktemp -d)
OCID_SOCKET="$TESTDIR/ocid.sock"
cp "$CONMON_BINARY" "$TESTDIR/conmon"
PATH=$PATH:$TESTDIR
# Run ocid using the binary specified by $OCID_BINARY. # Run ocid using the binary specified by $OCID_BINARY.
# This must ONLY be run on engines created with `start_ocid`. # This must ONLY be run on engines created with `start_ocid`.
@ -26,7 +34,7 @@ function ocid() {
# Run ocic using the binary specified by $OCID_BINARY. # Run ocic using the binary specified by $OCID_BINARY.
function ocic() { function ocic() {
"$OCIC_BINARY" "$@" "$OCIC_BINARY" --socket "$OCID_SOCKET" "$@"
} }
# Communicate with Docker on the host machine. # Communicate with Docker on the host machine.
@ -57,24 +65,21 @@ function retry() {
# Waits until the given ocid becomes reachable. # Waits until the given ocid becomes reachable.
function wait_until_reachable() { function wait_until_reachable() {
retry 15 1 "$OCIC_BINARY" runtimeversion retry 15 1 ocic runtimeversion
} }
# Start ocid. # Start ocid.
function start_ocid() { function start_ocid() {
cp "$CONMON_BINARY" "$BATS_TMPDIR/conmon" "$OCID_BINARY" --debug --socket "$TESTDIR/ocid.sock" --runtime "$RUNC_BINARY" --root "$TESTDIR/ocid" & OCID_PID=$!
mkdir -p "$BATS_TMPDIR/ocid/containers"
mkdir -p "$BATS_TMPDIR/ocid/sandboxes"
"$OCID_BINARY" --debug --runtime /usr/local/bin/runc --containerdir "$BATS_TMPDIR/ocid/containers" --sandboxdir "$BATS_TMPDIR/ocid/sandboxes" & OCID_PID=$!
wait_until_reachable wait_until_reachable
} }
# Stop ocid. # Stop ocid.
function stop_ocid() { function stop_ocid() {
# TODO(runcom): why a greceful kill doesn't work?! kill "$OCID_PID"
kill -9 "$OCID_PID" }
# TODO(runcom): remove the whole /var/lib/ocid
rm -rf "$BATS_TMPDIR/ocid/{containers,sandboxes}" function cleanup_test() {
rm -rf "$TESTDIR"
# TODO(runcom): runc list and kill/delete everything! # TODO(runcom): runc list and kill/delete everything!
} }

View file

@ -4,6 +4,7 @@ load helpers
function teardown() { function teardown() {
stop_ocid stop_ocid
cleanup_test
} }
@test "ocic runtimeversion" { @test "ocic runtimeversion" {