|
3 | 3 | import shutil |
4 | 4 | import logging |
5 | 5 | from unittest.mock import call, Mock |
6 | | -from gitopscli.io.yaml_util import update_yaml_file |
| 6 | +from gitopscli.io.yaml_util import update_yaml_file, YAMLException |
7 | 7 | from gitopscli.git import GitRepo, GitRepoApi, GitRepoApiFactory, GitProvider |
8 | 8 | from gitopscli.gitops_config import GitOpsConfig |
9 | 9 | from gitopscli.gitops_exception import GitOpsException |
@@ -241,14 +241,64 @@ def test_create_preview_for_unknown_template(self): |
241 | 241 | call.os.path.isdir("/tmp/created-tmp-dir/.preview-templates/my-app"), |
242 | 242 | ] |
243 | 243 |
|
| 244 | + def test_create_preview_values_yaml_not_found(self): |
| 245 | + self.update_yaml_file_mock.side_effect = FileNotFoundError() |
| 246 | + |
| 247 | + try: |
| 248 | + CreatePreviewCommand(ARGS).execute() |
| 249 | + self.fail() |
| 250 | + except GitOpsException as ex: |
| 251 | + self.assertEqual("No such file: my-app-685912d3-preview/values.yaml", str(ex)) |
| 252 | + |
| 253 | + assert self.mock_manager.method_calls == [ |
| 254 | + call.load_gitops_config(ARGS, "ORGA", "REPO",), |
| 255 | + call.GitRepoApiFactory.create(ARGS, "TEAM_CONFIG_ORG", "TEAM_CONFIG_REPO",), |
| 256 | + call.GitRepo(self.git_repo_api_mock), |
| 257 | + call.GitRepo.checkout("master"), |
| 258 | + call.GitRepo.get_full_file_path("my-app-685912d3-preview"), |
| 259 | + call.os.path.isdir("/tmp/created-tmp-dir/my-app-685912d3-preview"), |
| 260 | + call.logging.info("Use existing folder for preview: %s", "my-app-685912d3-preview"), |
| 261 | + call.GitRepo.get_full_file_path("my-app-685912d3-preview/values.yaml"), |
| 262 | + call.update_yaml_file( |
| 263 | + "/tmp/created-tmp-dir/my-app-685912d3-preview/values.yaml", |
| 264 | + "image.tag", |
| 265 | + "3361723dbd91fcfae7b5b8b8b7d462fbc14187a9", |
| 266 | + ), |
| 267 | + ] |
| 268 | + |
| 269 | + def test_create_preview_values_yaml_parse_error(self): |
| 270 | + self.update_yaml_file_mock.side_effect = YAMLException() |
| 271 | + |
| 272 | + try: |
| 273 | + CreatePreviewCommand(ARGS).execute() |
| 274 | + self.fail() |
| 275 | + except GitOpsException as ex: |
| 276 | + self.assertEqual("Error loading file: my-app-685912d3-preview/values.yaml", str(ex)) |
| 277 | + |
| 278 | + assert self.mock_manager.method_calls == [ |
| 279 | + call.load_gitops_config(ARGS, "ORGA", "REPO",), |
| 280 | + call.GitRepoApiFactory.create(ARGS, "TEAM_CONFIG_ORG", "TEAM_CONFIG_REPO",), |
| 281 | + call.GitRepo(self.git_repo_api_mock), |
| 282 | + call.GitRepo.checkout("master"), |
| 283 | + call.GitRepo.get_full_file_path("my-app-685912d3-preview"), |
| 284 | + call.os.path.isdir("/tmp/created-tmp-dir/my-app-685912d3-preview"), |
| 285 | + call.logging.info("Use existing folder for preview: %s", "my-app-685912d3-preview"), |
| 286 | + call.GitRepo.get_full_file_path("my-app-685912d3-preview/values.yaml"), |
| 287 | + call.update_yaml_file( |
| 288 | + "/tmp/created-tmp-dir/my-app-685912d3-preview/values.yaml", |
| 289 | + "image.tag", |
| 290 | + "3361723dbd91fcfae7b5b8b8b7d462fbc14187a9", |
| 291 | + ), |
| 292 | + ] |
| 293 | + |
244 | 294 | def test_create_preview_with_invalid_replacement_path(self): |
245 | 295 | self.update_yaml_file_mock.side_effect = KeyError() |
246 | 296 |
|
247 | 297 | try: |
248 | 298 | CreatePreviewCommand(ARGS).execute() |
249 | 299 | self.fail() |
250 | 300 | except GitOpsException as ex: |
251 | | - self.assertEqual("Key 'image.tag' not found in 'my-app-685912d3-preview/values.yaml'", str(ex)) |
| 301 | + self.assertEqual("Key 'image.tag' not found in file: my-app-685912d3-preview/values.yaml", str(ex)) |
252 | 302 |
|
253 | 303 | assert self.mock_manager.method_calls == [ |
254 | 304 | call.load_gitops_config(ARGS, "ORGA", "REPO",), |
@@ -278,7 +328,7 @@ def test_create_new_preview_invalid_chart_template(self): |
278 | 328 | CreatePreviewCommand(ARGS).execute() |
279 | 329 | self.fail() |
280 | 330 | except GitOpsException as ex: |
281 | | - self.assertEqual("Key 'name' not found in 'my-app-685912d3-preview/Chart.yaml'", str(ex)) |
| 331 | + self.assertEqual("Key 'name' not found in file: my-app-685912d3-preview/Chart.yaml", str(ex)) |
282 | 332 |
|
283 | 333 | assert self.mock_manager.method_calls == [ |
284 | 334 | call.load_gitops_config(ARGS, "ORGA", "REPO",), |
|
0 commit comments