def test_valid_substitution( self, allow_ec2_mirror, platform_type, availability_zone, region, patterns, expected, ): """Test substitution works as expected.""" flag_path = ( "cloudinit.distros.ALLOW_EC2_MIRRORS_ON_NON_AWS_INSTANCE_TYPES") m_data_source = mock.Mock( availability_zone=availability_zone, region=region, platform_type=platform_type, ) mirror_info = {"search": {"primary": patterns}} with mock.patch(flag_path, allow_ec2_mirror): ret = _get_package_mirror_info( mirror_info, data_source=m_data_source, mirror_filter=lambda x: x, ) print(allow_ec2_mirror) print(platform_type) print(availability_zone) print(region) print(patterns) print(expected) assert {"primary": expected} == ret
def test_failsafe_used_if_all_search_results_filtered_out(self): """Test the failsafe option used if all search options eliminated.""" mirror_info = { 'search': {'primary': ['http://value']}, 'failsafe': {'primary': 'http://other'} } assert {'primary': 'http://other'} == _get_package_mirror_info( mirror_info, mirror_filter=lambda x: False)
def test_get_package_mirror_info_failsafe(self, mirror_info, expected): """ Test the interaction between search and failsafe inputs (This doesn't test the case where the mirror_filter removes all search options; test_failsafe_used_if_all_search_results_filtered_out covers that.) """ assert expected == _get_package_mirror_info(mirror_info, mirror_filter=lambda x: x)
def test_substitution(self, availability_zone, region, patterns, expected): """Test substitution works as expected.""" m_data_source = mock.Mock(availability_zone=availability_zone, region=region) mirror_info = {'search': {'primary': patterns}} ret = _get_package_mirror_info(mirror_info, data_source=m_data_source, mirror_filter=lambda x: x) assert {'primary': expected} == ret
def test_failsafe_used_if_all_search_results_filtered_out(self): """Test the failsafe option used if all search options eliminated.""" mirror_info = { "search": { "primary": ["http://value"] }, "failsafe": { "primary": "http://other" }, } assert { "primary": "http://other" } == _get_package_mirror_info(mirror_info, mirror_filter=lambda x: False)