Skip to content

Commit

Permalink
test: use pytest.raises in test_empty_jailer_id
Browse files Browse the repository at this point in the history
It's shorter and gives nicer error messages than `assert False` in a
`try` block.

Signed-off-by: Patrick Roy <[email protected]>
  • Loading branch information
roypat committed Nov 4, 2024
1 parent 1313719 commit 3e629eb
Showing 1 changed file with 7 additions and 12 deletions.
19 changes: 7 additions & 12 deletions tests/integration_tests/security/test_jail.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,19 +64,14 @@ def test_empty_jailer_id(uvm_plain):
exec_file=test_microvm.fc_binary_path,
)

# pylint: disable=W0703
try:
# If the exception is not thrown, it means that Firecracker was
# started successfully, hence there's a bug in the code due to which
# we can set an empty ID.
with pytest.raises(
ChildProcessError,
match=r"Jailer error: Invalid instance ID: Invalid len \(0\); the length must be between 1 and 64",
):
test_microvm.spawn()
# If the exception is not thrown, it means that Firecracker was
# started successfully, hence there's a bug in the code due to which
# we can set an empty ID.
assert False
except Exception as err:
expected_err = (
"Jailer error: Invalid instance ID: Invalid len (0);"
" the length must be between 1 and 64"
)
assert expected_err in str(err)


def test_exec_file_not_exist(uvm_plain, tmp_path):
Expand Down

0 comments on commit 3e629eb

Please sign in to comment.