File tree Expand file tree Collapse file tree 3 files changed +20
-8
lines changed
Expand file tree Collapse file tree 3 files changed +20
-8
lines changed Original file line number Diff line number Diff line change @@ -89,7 +89,7 @@ teardown() {
8989 assert_file_exists $TEST_TMPDIR /syncpipe-output
9090 run cat $TEST_TMPDIR /syncpipe-output
9191 CONTAINER_PID=$( cat " $PID_FILE " )
92- assert " ${output} " =~ " \" pid\" : $CONTAINER_PID "
92+ assert_json " ${output} " =~ " \" pid\" : $CONTAINER_PID "
9393}
9494
9595@test " runtime: runc error with _OCI_SYNCPIPE defined" {
@@ -121,7 +121,7 @@ teardown() {
121121 # Check that the error is sent to the sync pipe.
122122 assert_file_exists $TEST_TMPDIR /syncpipe-output
123123 run cat $TEST_TMPDIR /syncpipe-output
124- assert " ${output} " =~ " \" pid\" : -1"
125- assert " ${output} " =~ " \" message\" :"
126- assert " ${output} " =~ " runc create failed"
124+ assert_json " ${output} " =~ " \" pid\" : -1"
125+ assert_json " ${output} " =~ " \" message\" :"
126+ assert_json " ${output} " =~ " runc create failed"
127127}
Original file line number Diff line number Diff line change @@ -86,7 +86,7 @@ teardown() {
8686 # Check that the conmon wrote something back.
8787 assert_file_exists $TEST_TMPDIR /attachpipe-output
8888 run cat $TEST_TMPDIR /attachpipe-output
89- assert " ${output} " =~ ' "data": 0'
89+ assert_json " ${output} " =~ ' "data": 0'
9090}
9191
9292@test " exec: --exec-attach with _OCI_STARTPIPE" {
@@ -156,7 +156,7 @@ teardown() {
156156 # Check that the conmon wrote something back.
157157 assert_file_exists $TEST_TMPDIR /syncpipe-output
158158 run cat $TEST_TMPDIR /syncpipe-output
159- assert " ${output} " =~ ' "exit_code": 0'
159+ assert_json " ${output} " =~ ' "exit_code": 0'
160160}
161161
162162@test " exec: --exec --api-version=1 with _OCI_SYNCPIPE defined" {
@@ -178,7 +178,7 @@ teardown() {
178178 assert_file_exists $TEST_TMPDIR /syncpipe-output
179179 run cat $TEST_TMPDIR /syncpipe-output
180180 CONTAINER_PID=$( cat " $PID_FILE " )
181- assert " ${output} " =~ " \" data\" : $CONTAINER_PID "
182- assert " ${output} " =~ ' "data": 0'
181+ assert_json " ${output} " =~ " \" data\" : $CONTAINER_PID "
182+ assert_json " ${output} " =~ ' "data": 0'
183183}
184184
Original file line number Diff line number Diff line change @@ -643,3 +643,15 @@ function die() {
643643 echo " #\\ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^" >&2
644644 bail-now
645645}
646+
647+ # Helper function wrapping the `assert`. It expects json as a first
648+ # argument and normalizes it so it is exactly the same no matter what
649+ # generated it.
650+ assert_json () {
651+ echo " $1 "
652+ if ! normalized_json=$( printf ' %s' " $1 " | jq -S .) ; then
653+ die " Invalid JSON passed to assert_json: $normalized_json "
654+ fi
655+ echo " $normalized_json "
656+ assert " $normalized_json " " $2 " " $3 " " $4 "
657+ }
You can’t perform that action at this time.
0 commit comments