|
| 1 | +import copy |
1 | 2 | import shutil |
2 | 3 | import os |
| 4 | +import tempfile |
3 | 5 |
|
4 | 6 | from ch_cli_tools.helm import * |
5 | 7 | from ch_cli_tools.preprocessing import * |
@@ -72,3 +74,58 @@ def test_generate_hash_based_image_tags_uses_merged_content(): |
72 | 74 | assert image_before != image_after |
73 | 75 |
|
74 | 76 | shutil.rmtree(MERGE_BUILD_DIR) |
| 77 | + |
| 78 | + |
| 79 | +def test_task_file_changes_trigger_different_tag(): |
| 80 | + """Modifying a file under applications/*/tasks/*/* must produce a different |
| 81 | + hash-based tag for the corresponding task image.""" |
| 82 | + |
| 83 | + values = create_helm_chart( |
| 84 | + [CLOUDHARNESS_ROOT], output_path=OUT, include=['workflows'], |
| 85 | + domain="my.local", namespace='test', env='dev', local=False, |
| 86 | + tag=None, registry='reg', |
| 87 | + ) |
| 88 | + |
| 89 | + # Pick a task image that lives under applications/workflows/tasks/ |
| 90 | + task_key = 'workflows-notify-queue' |
| 91 | + assert task_key in values[KEY_TASK_IMAGES], ( |
| 92 | + f"Expected '{task_key}' in task-images; got {list(values[KEY_TASK_IMAGES].keys())}" |
| 93 | + ) |
| 94 | + |
| 95 | + # --- first run: compute tags on the original tree --- |
| 96 | + preprocess_build_overrides( |
| 97 | + root_paths=[CLOUDHARNESS_ROOT], helm_values=values, |
| 98 | + merge_build_path=MERGE_BUILD_DIR, |
| 99 | + ) |
| 100 | + values_before = copy.deepcopy(values) |
| 101 | + generate_hash_based_image_tags( |
| 102 | + root_paths=[CLOUDHARNESS_ROOT], helm_values=values_before, |
| 103 | + merge_build_path=MERGE_BUILD_DIR, |
| 104 | + ) |
| 105 | + tag_before = values_before[KEY_TASK_IMAGES][task_key] |
| 106 | + |
| 107 | + # --- mutate a task file and recompute --- |
| 108 | + task_dir = os.path.join( |
| 109 | + CLOUDHARNESS_ROOT, 'applications', 'workflows', 'tasks', 'notify-queue', |
| 110 | + ) |
| 111 | + tmp_file = os.path.join(task_dir, '_tag_test_tmp_file') |
| 112 | + try: |
| 113 | + with open(tmp_file, 'w') as f: |
| 114 | + f.write('trigger-tag-change') |
| 115 | + |
| 116 | + values_after = copy.deepcopy(values) |
| 117 | + generate_hash_based_image_tags( |
| 118 | + root_paths=[CLOUDHARNESS_ROOT], helm_values=values_after, |
| 119 | + merge_build_path=MERGE_BUILD_DIR, |
| 120 | + ) |
| 121 | + tag_after = values_after[KEY_TASK_IMAGES][task_key] |
| 122 | + finally: |
| 123 | + if os.path.exists(tmp_file): |
| 124 | + os.remove(tmp_file) |
| 125 | + if os.path.exists(MERGE_BUILD_DIR): |
| 126 | + shutil.rmtree(MERGE_BUILD_DIR) |
| 127 | + |
| 128 | + assert tag_before != tag_after, ( |
| 129 | + f"Task image tag for '{task_key}' did not change after modifying task files. " |
| 130 | + f"Before: {tag_before}, After: {tag_after}" |
| 131 | + ) |
0 commit comments