|
1 | 1 | import copy |
2 | 2 | import unittest |
| 3 | +from unittest.mock import patch |
| 4 | +from staging_small_apply import maintenance |
3 | 5 | from staging_small_apply import validate, APP, INGRESS, DATABASE, WORKERS, DATABASE_POOL, Blocked |
4 | 6 | from test_staging_idle_apply import step, preview |
5 | 7 |
|
@@ -56,3 +58,17 @@ def test_never_changes_other_resources(self): |
56 | 58 | validate(preview(step('unrelated', {}, {})), phase) |
57 | 59 | with self.assertRaises(Blocked): |
58 | 60 | validate({'steps': []}, phase) |
| 61 | + |
| 62 | + |
| 63 | +class MaintenanceRestoration(unittest.TestCase): |
| 64 | + def test_exact_previous_window_or_absence_is_restored(self): |
| 65 | + previous = {('default', 'registry-pg'): None, ('monitoring', 'grafana-pg'): {'inProgress': False, 'reusePVC': False}} |
| 66 | + with patch('staging_small_apply.kube', return_value={}) as call: |
| 67 | + maintenance(None, {}, previous) |
| 68 | + args = [c.args[0] for c in call.call_args_list] |
| 69 | + self.assertEqual(len(args), 2) |
| 70 | + import json |
| 71 | + first = json.loads(args[0][args[0].index('-p')+1]) |
| 72 | + second = json.loads(args[1][args[1].index('-p')+1]) |
| 73 | + self.assertEqual(first, [{'op': 'remove', 'path': '/spec/nodeMaintenanceWindow'}]) |
| 74 | + self.assertEqual(second[0]['value'], previous[('monitoring', 'grafana-pg')]) |
0 commit comments