|
| 1 | +"""Tests for OperatorDeployer operator-image tag and registry resolution.""" |
| 2 | + |
| 3 | +import unittest |
| 4 | +from unittest.mock import MagicMock, patch |
| 5 | + |
| 6 | +from operator_deployer import OperatorDeployer |
| 7 | + |
| 8 | + |
| 9 | +def _make_deployer(repo_owner='opendatahub-io', |
| 10 | + target_branch='master', |
| 11 | + operator_image_tag=''): |
| 12 | + """Create an OperatorDeployer with stubbed dependencies.""" |
| 13 | + args = MagicMock() |
| 14 | + args.operator_image_tag = operator_image_tag |
| 15 | + args.deploy_external_argo = False |
| 16 | + deployment_manager = MagicMock() |
| 17 | + deployment_manager.wait_for_resource.return_value = True |
| 18 | + deployer = OperatorDeployer( |
| 19 | + args=args, |
| 20 | + deployment_manager=deployment_manager, |
| 21 | + repo_owner=repo_owner, |
| 22 | + target_branch=target_branch, |
| 23 | + temp_dir='/tmp/test', |
| 24 | + operator_namespace='opendatahub', |
| 25 | + ) |
| 26 | + deployer.operator_repo_path = '/tmp/test/data-science-pipelines-operator' |
| 27 | + return deployer |
| 28 | + |
| 29 | + |
| 30 | +def _resolve_operator_image(deployer): |
| 31 | + """Call deploy_operator and return the IMG value passed to make.""" |
| 32 | + with patch.object(deployer, '_patch_params_for_kind'): |
| 33 | + deployer.deploy_operator() |
| 34 | + for call in deployer.deployment_manager.run_command.call_args_list: |
| 35 | + args = call[0][0] |
| 36 | + for arg in args: |
| 37 | + if isinstance(arg, str) and arg.startswith('IMG='): |
| 38 | + return arg.split('=', 1)[1] |
| 39 | + raise AssertionError('No IMG= argument found in run_command calls') |
| 40 | + |
| 41 | + |
| 42 | +class TestOperatorImageResolution(unittest.TestCase): |
| 43 | + |
| 44 | + def test_odh_master_uses_odh_main_tag(self): |
| 45 | + deployer = _make_deployer( |
| 46 | + repo_owner='opendatahub-io', target_branch='master') |
| 47 | + image = _resolve_operator_image(deployer) |
| 48 | + self.assertEqual( |
| 49 | + image, |
| 50 | + 'quay.io/opendatahub/data-science-pipelines-operator:odh-main') |
| 51 | + |
| 52 | + def test_odh_stable_uses_odh_stable_tag(self): |
| 53 | + deployer = _make_deployer( |
| 54 | + repo_owner='opendatahub-io', target_branch='stable') |
| 55 | + image = _resolve_operator_image(deployer) |
| 56 | + self.assertEqual( |
| 57 | + image, |
| 58 | + 'quay.io/opendatahub/data-science-pipelines-operator:odh-stable') |
| 59 | + |
| 60 | + def test_rhds_master_uses_main_tag(self): |
| 61 | + deployer = _make_deployer( |
| 62 | + repo_owner='red-hat-data-services', target_branch='master') |
| 63 | + image = _resolve_operator_image(deployer) |
| 64 | + self.assertEqual( |
| 65 | + image, |
| 66 | + 'quay.io/opendatahub/data-science-pipelines-operator:main') |
| 67 | + |
| 68 | + def test_rhds_rhoai_branch_uses_branch_name_as_tag(self): |
| 69 | + deployer = _make_deployer( |
| 70 | + repo_owner='red-hat-data-services', target_branch='rhoai-2.16') |
| 71 | + image = _resolve_operator_image(deployer) |
| 72 | + self.assertEqual( |
| 73 | + image, |
| 74 | + 'quay.io/opendatahub/data-science-pipelines-operator:rhoai-2.16') |
| 75 | + |
| 76 | + def test_explicit_tag_overrides_branch_logic(self): |
| 77 | + deployer = _make_deployer( |
| 78 | + repo_owner='opendatahub-io', |
| 79 | + target_branch='master', |
| 80 | + operator_image_tag='custom-tag') |
| 81 | + image = _resolve_operator_image(deployer) |
| 82 | + self.assertEqual( |
| 83 | + image, |
| 84 | + 'quay.io/opendatahub/data-science-pipelines-operator:custom-tag') |
| 85 | + |
| 86 | + def test_odh_unknown_branch_uses_branch_name_as_tag(self): |
| 87 | + deployer = _make_deployer( |
| 88 | + repo_owner='opendatahub-io', target_branch='feature-x') |
| 89 | + image = _resolve_operator_image(deployer) |
| 90 | + self.assertEqual( |
| 91 | + image, |
| 92 | + 'quay.io/opendatahub/data-science-pipelines-operator:feature-x') |
| 93 | + |
| 94 | + def test_rhds_stable_uses_odh_stable_tag(self): |
| 95 | + deployer = _make_deployer( |
| 96 | + repo_owner='red-hat-data-services', target_branch='stable') |
| 97 | + image = _resolve_operator_image(deployer) |
| 98 | + self.assertEqual( |
| 99 | + image, |
| 100 | + 'quay.io/opendatahub/data-science-pipelines-operator:odh-stable') |
| 101 | + |
| 102 | + |
| 103 | +if __name__ == '__main__': |
| 104 | + unittest.main() |
0 commit comments