From 3849ce250d309640ed215d075a84a91ffc995508 Mon Sep 17 00:00:00 2001 From: Ali Mirjamali Date: Thu, 11 Jul 2024 11:10:00 +0330 Subject: [PATCH] Improving unit tests for qvm-check (cherry picked from commit 7a4b4984ea98e71740759868501607a36d3c9a2b) --- qubesadmin/tests/tools/qvm_check.py | 17 +++++++++++++++++ qubesadmin/tools/qvm_check.py | 2 +- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/qubesadmin/tests/tools/qvm_check.py b/qubesadmin/tests/tools/qvm_check.py index 4404a0b06..bcb26f698 100644 --- a/qubesadmin/tests/tools/qvm_check.py +++ b/qubesadmin/tests/tools/qvm_check.py @@ -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) diff --git a/qubesadmin/tools/qvm_check.py b/qubesadmin/tools/qvm_check.py index 0274be9ba..bf7fc9daf 100644 --- a/qubesadmin/tools/qvm_check.py +++ b/qubesadmin/tools/qvm_check.py @@ -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)