|
8 | 8 | from resc_helm_wizard import constants
|
9 | 9 | from resc_helm_wizard.helm_utilities import (
|
10 | 10 | add_helm_repository,
|
| 11 | + get_deployment_status_from_installed_chart, |
11 | 12 | get_version_from_downloaded_chart,
|
12 |
| - get_version_from_installed_chart, |
13 | 13 | install_or_upgrade_helm_release,
|
14 |
| - is_chart_version_already_installed, |
15 |
| - update_helm_repository |
| 14 | + is_chart_already_installed, |
| 15 | + update_helm_repository, |
| 16 | + validate_helm_deployment_status |
16 | 17 | )
|
17 | 18 |
|
18 | 19 | sys.path.insert(0, "src")
|
@@ -40,45 +41,37 @@ def test_install_or_upgrade_helm_release_failure(mock_error_log):
|
40 | 41 | mock_error_log.assert_called_with(expected_error_log)
|
41 | 42 |
|
42 | 43 |
|
43 |
| -@patch("resc_helm_wizard.helm_utilities.get_version_from_downloaded_chart") |
44 |
| -@patch("resc_helm_wizard.helm_utilities.get_version_from_installed_chart") |
45 |
| -def test_is_chart_version_already_installed_is_true(get_version_from_installed_chart, |
46 |
| - get_version_from_downloaded_chart): |
47 |
| - get_version_from_installed_chart.return_value = "1.0.0" |
48 |
| - get_version_from_downloaded_chart.return_value = "1.0.0" |
49 |
| - already_installed = is_chart_version_already_installed() |
50 |
| - get_version_from_installed_chart.assert_called_once_with() |
51 |
| - get_version_from_downloaded_chart.assert_called_once_with() |
| 44 | +@patch("resc_helm_wizard.helm_utilities.get_deployment_status_from_installed_chart") |
| 45 | +def test_is_chart_already_installed_is_true(get_deployment_status_from_installed_chart): |
| 46 | + get_deployment_status_from_installed_chart.return_value = "deployed" |
| 47 | + already_installed = is_chart_already_installed() |
| 48 | + get_deployment_status_from_installed_chart.assert_called_once_with() |
52 | 49 | assert already_installed is True
|
53 | 50 |
|
54 | 51 |
|
55 |
| -@patch("resc_helm_wizard.helm_utilities.get_version_from_downloaded_chart") |
56 |
| -@patch("resc_helm_wizard.helm_utilities.get_version_from_installed_chart") |
57 |
| -def test_is_chart_version_already_installed_is_false(get_version_from_installed_chart, |
58 |
| - get_version_from_downloaded_chart): |
59 |
| - get_version_from_installed_chart.return_value = "1.0.0" |
60 |
| - get_version_from_downloaded_chart.return_value = "1.0.1" |
61 |
| - already_installed = is_chart_version_already_installed() |
62 |
| - get_version_from_installed_chart.assert_called_once_with() |
63 |
| - get_version_from_downloaded_chart.assert_called_once_with() |
| 52 | +@patch("resc_helm_wizard.helm_utilities.get_deployment_status_from_installed_chart") |
| 53 | +def test_is_chart_already_installed_is_false(get_deployment_status_from_installed_chart): |
| 54 | + get_deployment_status_from_installed_chart.return_value = None |
| 55 | + already_installed = is_chart_already_installed() |
| 56 | + get_deployment_status_from_installed_chart.assert_called_once_with() |
64 | 57 | assert already_installed is False
|
65 | 58 |
|
66 | 59 |
|
67 | 60 | @patch("subprocess.check_output")
|
68 |
| -def test_get_version_from_installed_chart_success(mock_check_output): |
| 61 | +def test_get_deployment_status_from_installed_chart_success(mock_check_output): |
69 | 62 | expected_output = b'[{"name":"resc","namespace":"resc","revision":"1",' \
|
70 | 63 | b'"updated":"2023-03-30 10:16:56.211749 +0200 CEST","status":"deployed",' \
|
71 | 64 | b'"chart":"resc-1.1.0","app_version":"1.1.0"}]\n'
|
72 | 65 | mock_check_output.return_value = expected_output
|
73 |
| - actual_output = get_version_from_installed_chart() |
74 |
| - assert actual_output == "1.1.0" |
| 66 | + actual_output = get_deployment_status_from_installed_chart() |
| 67 | + assert actual_output == "deployed" |
75 | 68 |
|
76 | 69 |
|
77 | 70 | @patch("subprocess.check_output")
|
78 |
| -def test_get_version_from_installed_chart_failure(mock_check_output): |
| 71 | +def test_get_deployment_status_from_installed_chart_failure(mock_check_output): |
79 | 72 | expected_output = b'{}'
|
80 | 73 | mock_check_output.return_value = expected_output
|
81 |
| - actual_output = get_version_from_installed_chart() |
| 74 | + actual_output = get_deployment_status_from_installed_chart() |
82 | 75 | assert actual_output is None
|
83 | 76 |
|
84 | 77 |
|
@@ -141,3 +134,30 @@ def test_update_helm_repository_failure(mock_error_log):
|
141 | 134 | mock_error_log.assert_called_with(expected_error_log)
|
142 | 135 | mock_check_output.assert_called_once_with(cmd, check=True)
|
143 | 136 | mock_sys_exit.assert_called_once_with(1)
|
| 137 | + |
| 138 | + |
| 139 | +@patch("subprocess.run") |
| 140 | +@patch("logging.Logger.info") |
| 141 | +def test_validate_helm_deployment_status_success(mock_info_log, mock_check_output): |
| 142 | + cmd = ['helm', 'status', constants.RELEASE_NAME, "-n", constants.NAMESPACE] |
| 143 | + expected_output = "RELEASE STATUS: deployed" |
| 144 | + expected_info_log = "The deployment was successful. Visit http://127.0.0.1:30000 to get started with RESC!" |
| 145 | + mock_check_output.return_value.stdout = expected_output |
| 146 | + validate_helm_deployment_status() |
| 147 | + assert mock_check_output.called |
| 148 | + mock_check_output.assert_called_once_with(cmd, capture_output=True, check=True, text=True) |
| 149 | + mock_info_log.assert_called_with(expected_info_log) |
| 150 | + |
| 151 | + |
| 152 | +@patch("logging.Logger.error") |
| 153 | +def test_validate_helm_deployment_status_failure(mock_error_log): |
| 154 | + cmd = ['helm', 'status', constants.RELEASE_NAME, "-n", constants.NAMESPACE] |
| 155 | + expected_error_log = "An error occurred during deployment." |
| 156 | + with mock.patch("subprocess.run") as mock_check_output, \ |
| 157 | + mock.patch("sys.exit") as mock_sys_exit: |
| 158 | + mock_check_output.side_effect = subprocess.CalledProcessError(returncode=1, cmd=cmd) |
| 159 | + validate_helm_deployment_status() |
| 160 | + assert mock_check_output.called |
| 161 | + mock_error_log.assert_called_with(expected_error_log) |
| 162 | + mock_check_output.assert_called_once_with(cmd, capture_output=True, check=True, text=True) |
| 163 | + mock_sys_exit.assert_called_once_with(1) |
0 commit comments