|
15 | 15 | Test 'add'. |
16 | 16 | """ |
17 | 17 |
|
| 18 | +# isort: STDLIB |
| 19 | +from unittest.mock import patch |
| 20 | + |
18 | 21 | # isort: FIRSTPARTY |
19 | 22 | from dbus_client_gen import DbusClientUniqueResultError |
20 | 23 |
|
21 | 24 | # isort: LOCAL |
22 | 25 | from stratis_cli import StratisCliErrorCodes |
23 | 26 | from stratis_cli._errors import ( |
24 | 27 | StratisCliEngineError, |
| 28 | + StratisCliIncoherenceError, |
25 | 29 | StratisCliInUseOtherTierError, |
26 | 30 | StratisCliInUseSameTierError, |
27 | 31 | StratisCliPartialChangeError, |
@@ -114,6 +118,26 @@ def test_add_data_again(self): |
114 | 118 | command_line = self._MENU + [self._POOLNAME] + self._DEVICES |
115 | 119 | self.check_error(StratisCliPartialChangeError, command_line, _ERROR) |
116 | 120 |
|
| 121 | + def test_add_data_again_mock_check(self): |
| 122 | + """ |
| 123 | + Test that trying to add the same devices twice results in a |
| 124 | + StratisCliIncoherenceError exception. |
| 125 | + There are 0 target resources that would change. |
| 126 | + There is 1 target resource that would not change. |
| 127 | + """ |
| 128 | + command_line = self._MENU + [self._POOLNAME] + self._DEVICES |
| 129 | + # isort: LOCAL |
| 130 | + import stratis_cli # pylint: disable=import-outside-toplevel |
| 131 | + |
| 132 | + with patch.object( |
| 133 | + # pylint: disable=protected-access |
| 134 | + stratis_cli._actions._pool, # pyright: ignore |
| 135 | + "_check_same_tier", |
| 136 | + autospec=True, |
| 137 | + return_value=None, |
| 138 | + ): |
| 139 | + self.check_error(StratisCliIncoherenceError, command_line, _ERROR) |
| 140 | + |
117 | 141 | def test_add_data_cache(self): |
118 | 142 | """ |
119 | 143 | Test that adding 1 data device that is already in the cache tier raises |
@@ -226,6 +250,29 @@ def test_add_cache_again(self): |
226 | 250 | RUNNER(command_line) |
227 | 251 | self.check_error(StratisCliPartialChangeError, command_line, _ERROR) |
228 | 252 |
|
| 253 | + def test_add_cache_again_mock_check(self): |
| 254 | + """ |
| 255 | + Test that trying to add the same devices twice results in a |
| 256 | + StratisCliIncoherence exception. |
| 257 | + There are 0 target resources that would change. |
| 258 | + There is 1 target resource that would not change. |
| 259 | + """ |
| 260 | + devices = _DEVICE_STRATEGY() |
| 261 | + command_line = self._MENU + [self._POOLNAME] + devices |
| 262 | + RUNNER(command_line) |
| 263 | + |
| 264 | + # isort: LOCAL |
| 265 | + import stratis_cli # pylint: disable=import-outside-toplevel |
| 266 | + |
| 267 | + with patch.object( |
| 268 | + # pylint: disable=protected-access |
| 269 | + stratis_cli._actions._pool, # pyright: ignore |
| 270 | + "_check_same_tier", |
| 271 | + autospec=True, |
| 272 | + return_value=None, |
| 273 | + ): |
| 274 | + self.check_error(StratisCliIncoherenceError, command_line, _ERROR) |
| 275 | + |
229 | 276 | def test_add_cache_data(self): |
230 | 277 | """ |
231 | 278 | Test that adding 1 cache device that is already in the data tier raises |
|
0 commit comments