Skip to content

Commit

Permalink
Improving unit tests for qvm-check
Browse files Browse the repository at this point in the history
  • Loading branch information
alimirjamali committed Jul 11, 2024
1 parent 06bfde3 commit 7a4b498
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
17 changes: 17 additions & 0 deletions qubesadmin/tests/tools/qvm_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,3 +245,20 @@ def test_013_networked_multi(self):
self.assertEqual(logger.output,
['INFO:qvm-check:some-vm2: networked'])
self.assertAllCalled()

def test_014_does_not_exist(self):
self.app.expected_calls[
('dom0', 'admin.vm.List', None, None)] = \
b'0\x00some-vm class=AppVM state=Running\n'
with self.assertLogs() as logger:
self.assertEqual(
qubesadmin.tools.qvm_check.main(['invalid-vm'], app=self.app), 1)
self.assertEqual(logger.output,
['WARNING:qvm-check:invalid-vm: non-existent!'])

def test_15_custom_argparse_error_handling(self):
self.app.expected_calls[
('dom0', 'admin.vm.List', None, None)] = \
b'0\x00some-vm class=AppVM state=Running\n'
with self.assertRaises(SystemExit):
qubesadmin.tools.qvm_check.main(['--invalid-option'], app=self.app)
2 changes: 1 addition & 1 deletion qubesadmin/tools/qvm_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def __init__(self, description, vmname_nargs):

def error(self, message):
if message.startswith('no such domain: '):
self._invalid_domains.append(message[17:])
self._invalid_domains.append(message[17:-1])
else:
super().error(message)

Expand Down

0 comments on commit 7a4b498

Please sign in to comment.