Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions test/04-runtime.bats
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ teardown() {
assert_file_exists $TEST_TMPDIR/syncpipe-output
run cat $TEST_TMPDIR/syncpipe-output
CONTAINER_PID=$(cat "$PID_FILE")
assert "${output}" =~ "\"pid\": $CONTAINER_PID"
assert_json "${output}" =~ "\"pid\": $CONTAINER_PID"
}

@test "runtime: runc error with _OCI_SYNCPIPE defined" {
Expand Down Expand Up @@ -121,7 +121,7 @@ teardown() {
# Check that the error is sent to the sync pipe.
assert_file_exists $TEST_TMPDIR/syncpipe-output
run cat $TEST_TMPDIR/syncpipe-output
assert "${output}" =~ "\"pid\": -1"
assert "${output}" =~ "\"message\":"
assert "${output}" =~ "runc create failed"
assert_json "${output}" =~ "\"pid\": -1"
assert_json "${output}" =~ "\"message\":"
assert_json "${output}" =~ "runc create failed"
}
8 changes: 4 additions & 4 deletions test/08-exec.bats
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ teardown() {
# Check that the conmon wrote something back.
assert_file_exists $TEST_TMPDIR/attachpipe-output
run cat $TEST_TMPDIR/attachpipe-output
assert "${output}" =~ '"data": 0'
assert_json "${output}" =~ '"data": 0'
}

@test "exec: --exec-attach with _OCI_STARTPIPE" {
Expand Down Expand Up @@ -156,7 +156,7 @@ teardown() {
# Check that the conmon wrote something back.
assert_file_exists $TEST_TMPDIR/syncpipe-output
run cat $TEST_TMPDIR/syncpipe-output
assert "${output}" =~ '"exit_code": 0'
assert_json "${output}" =~ '"exit_code": 0'
}

@test "exec: --exec --api-version=1 with _OCI_SYNCPIPE defined" {
Expand All @@ -178,7 +178,7 @@ teardown() {
assert_file_exists $TEST_TMPDIR/syncpipe-output
run cat $TEST_TMPDIR/syncpipe-output
CONTAINER_PID=$(cat "$PID_FILE")
assert "${output}" =~ "\"data\": $CONTAINER_PID"
assert "${output}" =~ '"data": 0'
assert_json "${output}" =~ "\"data\": $CONTAINER_PID"
assert_json "${output}" =~ '"data": 0'
}

12 changes: 12 additions & 0 deletions test/test_helper.bash
Original file line number Diff line number Diff line change
Expand Up @@ -643,3 +643,15 @@ function die() {
echo "#\\^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^" >&2
bail-now
}

# Helper function wrapping the `assert`. It expects json as a first
# argument and normalizes it so it is exactly the same no matter what
# generated it.
assert_json() {
echo "$1"
if ! normalized_json=$(printf '%s' "$1" | jq -S .); then
die "Invalid JSON passed to assert_json: $normalized_json"
fi
echo "$normalized_json"
assert "$normalized_json" "$2" "$3" "$4"
}
Loading