Improve platform mocking
Patch out charmhelpers.osplatform.get_platform() and charmhelpers.core.host.lsb_release() globally in the unit tests to insulate the unit tests from the platform that the unit tests are being run on. Change-Id: I2cc91999ccad52c8e42797a3d5ffbf65f9cb36d2
This commit is contained in:
parent
a6c5567354
commit
94cedb6840
@ -23,3 +23,15 @@ sys.modules['apt_pkg'] = mock.MagicMock()
|
|||||||
sys.path.append('actions/')
|
sys.path.append('actions/')
|
||||||
sys.path.append('hooks/')
|
sys.path.append('hooks/')
|
||||||
sys.path.append('unit_tests')
|
sys.path.append('unit_tests')
|
||||||
|
|
||||||
|
# Patch out lsb_release() and get_platform() as unit tests should be fully
|
||||||
|
# insulated from the underlying platform. Unit tests assume that the system is
|
||||||
|
# ubuntu jammy.
|
||||||
|
mock.patch(
|
||||||
|
'charmhelpers.osplatform.get_platform', return_value='ubuntu'
|
||||||
|
).start()
|
||||||
|
mock.patch(
|
||||||
|
'charmhelpers.core.host.lsb_release',
|
||||||
|
return_value={
|
||||||
|
'DISTRIB_CODENAME': 'jammy'
|
||||||
|
}).start()
|
||||||
|
@ -385,7 +385,7 @@ class HAProxyContextTest(CharmTestCase):
|
|||||||
with patch('builtins.__import__'):
|
with patch('builtins.__import__'):
|
||||||
self.assertTrue('units' not in hap_ctxt())
|
self.assertTrue('units' not in hap_ctxt())
|
||||||
|
|
||||||
@patch.object(charmhelpers.contrib.network.ip, 'is_ipv6_disabled')
|
@patch.object(charmhelpers.contrib.openstack.context, 'is_ipv6_disabled')
|
||||||
@patch.object(charmhelpers.contrib.openstack.context, 'get_relation_ip')
|
@patch.object(charmhelpers.contrib.openstack.context, 'get_relation_ip')
|
||||||
@patch.object(charmhelpers.contrib.openstack.context, 'mkdir')
|
@patch.object(charmhelpers.contrib.openstack.context, 'mkdir')
|
||||||
@patch.object(
|
@patch.object(
|
||||||
@ -445,7 +445,7 @@ class HAProxyContextTest(CharmTestCase):
|
|||||||
'default_backend': '10.10.10.11',
|
'default_backend': '10.10.10.11',
|
||||||
'service_ports': service_ports,
|
'service_ports': service_ports,
|
||||||
'neutron_bind_port': 9686,
|
'neutron_bind_port': 9686,
|
||||||
'ipv6_enabled': True,
|
'ipv6_enabled': False,
|
||||||
'https': False,
|
'https': False,
|
||||||
'backend_options': backend_options,
|
'backend_options': backend_options,
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user