Skip to content

Commit

Permalink
Update unit test for testing interface updates
Browse files Browse the repository at this point in the history
Co-authored-by: Rich Megginson <[email protected]>
  • Loading branch information
rlenferink and richm committed Oct 22, 2024
1 parent f52f79f commit 55bc540
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion tests/unit/test_firewall_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -785,7 +785,7 @@ def test_nm_integration_interfaces(
):
am = am_class.return_value
am.params = {
"interface": "eth0",
"interface": ["eth0"],
"zone": "public",
"permanent": True,
}
Expand All @@ -799,6 +799,13 @@ def test_nm_integration_interfaces(

fw_config = Mock()
fw_config.getZoneNames.return_value = available_zones
fw_config.getServiceNames.return_value = ["ssh"]
fw_zone = Mock()
fw_config.getZoneByName.return_value = fw_zone
fw_settings = Mock()
fw_settings.queryService.return_value = False
fw_settings.addService = Mock()
fw_zone.getSettings.return_value = fw_settings
fw.config.return_value = fw_config

return_values = [(True, True), (True, False)]
Expand All @@ -809,6 +816,18 @@ def test_nm_integration_interfaces(
firewall_lib.main()
am.exit_json.assert_called_with(changed=rv[1], __firewall_changed=rv[1])

# now try with some other change in the mix
# main should always return True due to the service change
# regardless of the zone interface change
return_values = [(True, True), (True, False)]
for state in ["enabled", "disabled"]:
am.params["state"] = state
am.params["service"] = ["ssh"]
for rv in return_values:
try_set_zone_of_interface.return_value = rv
firewall_lib.main()
am.exit_json.assert_called_with(changed=True, __firewall_changed=True)

@patch("firewall_lib.HAS_FIREWALLD", True)
@patch("firewall_lib.FW_VERSION", "0.9.0", create=True)
def test_ipset_operation_with_services_set(self, am_class):
Expand Down

0 comments on commit 55bc540

Please sign in to comment.