|
15 | 15 | Test 'stratisd'. |
16 | 16 | """ |
17 | 17 |
|
| 18 | +# isort: STDLIB |
| 19 | +from unittest.mock import patch |
| 20 | + |
18 | 21 | # isort: THIRDPARTY |
19 | 22 | import dbus |
20 | 23 |
|
21 | 24 | # isort: LOCAL |
22 | | -from stratis_cli import StratisCliErrorCodes |
| 25 | +from stratis_cli import StratisCliErrorCodes, run |
| 26 | +from stratis_cli._errors import StratisCliStratisdVersionError |
23 | 27 |
|
24 | 28 | from ._misc import RUNNER, TEST_RUNNER, RunTestCase, SimTestCase |
25 | 29 |
|
@@ -60,3 +64,55 @@ def test_not_propagate(self): |
60 | 64 | command_line = ["daemon", "version"] |
61 | 65 | with self.assertRaises(SystemExit): |
62 | 66 | RUNNER(command_line) |
| 67 | + |
| 68 | + |
| 69 | +class StratisdVersionTestCase(SimTestCase): |
| 70 | + """ |
| 71 | + Test behavior of stratis on incompatible versions of stratisd. |
| 72 | + """ |
| 73 | + |
| 74 | + def test_outdated_stratisd_version(self): |
| 75 | + """ |
| 76 | + Verify that an outdated version of stratisd will produce a |
| 77 | + StratisCliStratisdVersionError. |
| 78 | + """ |
| 79 | + # pylint: disable=import-outside-toplevel |
| 80 | + # isort: LOCAL |
| 81 | + from stratis_cli._actions import _data |
| 82 | + |
| 83 | + command_line = ["--propagate", "daemon", "version"] |
| 84 | + |
| 85 | + # pylint: disable=protected-access |
| 86 | + with patch.object( |
| 87 | + _data.Manager0.Properties.Version, |
| 88 | + "Get", |
| 89 | + return_value="1.0.0", |
| 90 | + ): |
| 91 | + self.check_error(StratisCliStratisdVersionError, command_line, _ERROR) |
| 92 | + |
| 93 | + |
| 94 | +class KeyboardInterruptTestCase(SimTestCase): |
| 95 | + """ |
| 96 | + Test behavior of stratis on KeyboardInterrupt. |
| 97 | + """ |
| 98 | + |
| 99 | + def test_catch_keyboard_exception(self): |
| 100 | + """ |
| 101 | + Verify that the KeyboardInterrupt is propagated by the run() method. |
| 102 | + ./bin/stratis contains a try block at the outermost level which |
| 103 | + then catches the KeyboardInterrupt and exits with an error message. |
| 104 | + The KeyboardInterrupt is most likely raised in the dbus-python |
| 105 | + method which is actually communicating on the D-Bus, but it is |
| 106 | + fairly difficult to get at that method. Instead settle for getting |
| 107 | + at the calling method generated by dbus-python-client-gen. |
| 108 | + """ |
| 109 | + |
| 110 | + # pylint: disable=import-outside-toplevel |
| 111 | + # isort: LOCAL |
| 112 | + from stratis_cli._actions import _data |
| 113 | + |
| 114 | + with patch.object( |
| 115 | + _data.Manager0.Properties.Version, "Get", side_effect=KeyboardInterrupt() |
| 116 | + ): |
| 117 | + with self.assertRaises(KeyboardInterrupt): |
| 118 | + run()(["daemon", "version"]) |
0 commit comments