Skip to content

Commit c0be822

Browse files
committed
tests: Add and fix InterfacePciId unit test
TEST_DATA defined this already (wrongly), but it was not enabled in TEST_METHODS, so that definition was ignored. Mock the get_interface_pci() helper so that the PCI ID → interface translation works as expected.
1 parent 978330f commit c0be822

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

tests/unit/test_firewall_lib.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
"RichRule",
3030
"Source",
3131
"Interface",
32+
"InterfacePciId",
3233
"IcmpBlock",
3334
"IcmpBlockInversion",
3435
"Target",
@@ -188,13 +189,14 @@
188189
"input": {"interface_pci_id": ["600D:7C1D"]},
189190
"enabled": {
190191
"expected": {
191-
"runtime": [call("default", "600D:7C1D")],
192+
"runtime": [call("default", "eth42")],
193+
"permanent": [call("eth42")],
192194
},
193195
},
194196
"disabled": {
195197
"expected": {
196-
"runtime": [call("default", "600D:7C1D")],
197-
"permanent": [call("600D:7C1D")],
198+
"runtime": [call("default", "eth42")],
199+
"permanent": [call("eth42")],
198200
},
199201
},
200202
},
@@ -1187,6 +1189,10 @@ def test_module_parameters(method, state, input, expected):
11871189
fw_ver_patcher.start()
11881190
rich_rule_patcher = patch("firewall_lib.Rich_Rule", create=True)
11891191
rich_rule = rich_rule_patcher.start()
1192+
fw_get_pci_patcher = patch(
1193+
"firewall_lib.get_interface_pci", return_value={"600D:7C1D": ["eth42"]}
1194+
)
1195+
fw_get_pci_patcher.start()
11901196

11911197
try:
11921198
params_state = state
@@ -1203,6 +1209,11 @@ def test_module_parameters(method, state, input, expected):
12031209
"timeout": 0,
12041210
}
12051211
am.params.update(input)
1212+
1213+
# InterfacePciId uses set_interface() as well, same backend API
1214+
if method == "InterfacePciId":
1215+
method = "Interface"
1216+
12061217
if "called_mock_name" in expected:
12071218
called_mock_name = expected["called_mock_name"]
12081219
elif state == "enabled":
@@ -1252,6 +1263,7 @@ def test_module_parameters(method, state, input, expected):
12521263
has_fw_patcher.stop()
12531264
fw_ver_patcher.stop()
12541265
rich_rule_patcher.stop()
1266+
fw_get_pci_patcher.stop()
12551267

12561268

12571269
class FirewallVersionTest(unittest.TestCase):

0 commit comments

Comments
 (0)