|
3 | 3 | # Licensed under a 3-clause BSD style license (see LICENSE) |
4 | 4 | import json |
5 | 5 | import os |
| 6 | +from contextlib import nullcontext |
6 | 7 |
|
7 | 8 | import mock |
8 | 9 | import pytest |
@@ -367,25 +368,42 @@ def fake_run_command(command, **kwargs): |
367 | 368 |
|
368 | 369 |
|
369 | 370 | class TestAssertPodStable: |
370 | | - def test_detects_uid_change(self): |
371 | | - with pytest.raises(AssertionError, match='Pod changed'): |
372 | | - assert_pod_stable(pod_state(uid='a'), pod_state(uid='b'), 1) |
373 | | - |
374 | | - def test_detects_not_running(self): |
375 | | - with pytest.raises(AssertionError, match="Pod phase is 'Pending'"): |
376 | | - assert_pod_stable(pod_state(), pod_state(phase='Pending'), 1) |
377 | | - |
378 | | - def test_detects_restart(self): |
379 | | - with pytest.raises(AssertionError, match='restart count changed'): |
380 | | - assert_pod_stable(pod_state(restart_count=0), pod_state(restart_count=1), 1) |
381 | | - |
382 | | - def test_detects_not_ready(self): |
383 | | - with pytest.raises(AssertionError, match='is not ready'): |
384 | | - assert_pod_stable(pod_state(), pod_state(ready=False), 1) |
385 | | - |
386 | | - def test_detects_oom_killed(self): |
387 | | - with pytest.raises(AssertionError, match='OOMKilled'): |
388 | | - assert_pod_stable(pod_state(), pod_state(terminated_reason='OOMKilled'), 1) |
389 | | - |
390 | | - def test_stable_pod_does_not_raise(self): |
391 | | - assert_pod_stable(pod_state(), pod_state(), 1) |
| 371 | + @pytest.mark.parametrize( |
| 372 | + ('initial', 'current', 'expectation'), |
| 373 | + [ |
| 374 | + pytest.param( |
| 375 | + pod_state(uid='a'), |
| 376 | + pod_state(uid='b'), |
| 377 | + pytest.raises(AssertionError, match='Pod changed'), |
| 378 | + id='uid_change', |
| 379 | + ), |
| 380 | + pytest.param( |
| 381 | + pod_state(), |
| 382 | + pod_state(phase='Pending'), |
| 383 | + pytest.raises(AssertionError, match="Pod phase is 'Pending'"), |
| 384 | + id='not_running', |
| 385 | + ), |
| 386 | + pytest.param( |
| 387 | + pod_state(restart_count=0), |
| 388 | + pod_state(restart_count=1), |
| 389 | + pytest.raises(AssertionError, match='restart count changed'), |
| 390 | + id='restart', |
| 391 | + ), |
| 392 | + pytest.param( |
| 393 | + pod_state(), |
| 394 | + pod_state(ready=False), |
| 395 | + pytest.raises(AssertionError, match='is not ready'), |
| 396 | + id='not_ready', |
| 397 | + ), |
| 398 | + pytest.param( |
| 399 | + pod_state(), |
| 400 | + pod_state(terminated_reason='OOMKilled'), |
| 401 | + pytest.raises(AssertionError, match='OOMKilled'), |
| 402 | + id='oom_killed', |
| 403 | + ), |
| 404 | + pytest.param(pod_state(), pod_state(), nullcontext(), id='stable'), |
| 405 | + ], |
| 406 | + ) |
| 407 | + def test_assert_pod_stable(self, initial, current, expectation): |
| 408 | + with expectation: |
| 409 | + assert_pod_stable(initial, current, 1) |
0 commit comments