@@ -211,3 +211,60 @@ async def test_get_listening_ports_error(self, mcp_client, mock_execute):
211211 match = re .compile (r"error calling tool.*raised intentionally" , flags = re .I )
212212 with pytest .raises (ToolError , match = match ):
213213 await mcp_client .call_tool ("get_listening_ports" )
214+
215+
216+ class TestGetNetworkRoutes :
217+ """Test get_network_routes function."""
218+
219+ @pytest .mark .parametrize (
220+ ("host" , "mock_output" , "expected_content" ),
221+ [
222+ pytest .param (
223+ None ,
224+ "default via 192.168.1.1 dev eth0 proto dhcp src 192.168.1.100 metric 100\n "
225+ "192.168.1.0/24 dev eth0 proto kernel scope link src 192.168.1.100\n "
226+ "172.17.0.0/16 dev docker0 proto kernel scope link src 172.17.0.1" ,
227+ ["192.168.1.1" , "eth0" , "Total routes: 3" ],
228+ id = "local" ,
229+ ),
230+ pytest .param (
231+ "remote.host" ,
232+ "default via 10.0.0.1 dev ens5 proto dhcp metric 100\n "
233+ "10.0.0.0/24 dev ens5 proto kernel scope link src 10.0.0.5" ,
234+ ["10.0.0.1" , "ens5" ],
235+ id = "remote" ,
236+ ),
237+ ],
238+ )
239+ async def test_get_network_routes_success (self , mcp_client , mock_execute , host , mock_output , expected_content ):
240+ """Test getting network routes with success."""
241+ mock_execute .return_value = (0 , mock_output , "" )
242+ result = await mcp_client .call_tool ("get_network_routes" , arguments = {"host" : host })
243+ result_text = result .content [0 ].text .casefold ()
244+
245+ assert "routing table" in result_text
246+ assert all (content .casefold () in result_text for content in expected_content ), (
247+ "Did not find all expected values"
248+ )
249+
250+ @pytest .mark .parametrize (
251+ ("return_value" ,),
252+ [
253+ pytest .param ((1 , "" , "Command not found" ), id = "command_fails" ),
254+ pytest .param ((0 , "" , "" ), id = "empty_output" ),
255+ ],
256+ )
257+ async def test_get_network_routes_failure (self , mcp_client , mock_execute , return_value ):
258+ """Test getting network routes when command fails or returns empty."""
259+ mock_execute .return_value = return_value
260+ result = await mcp_client .call_tool ("get_network_routes" )
261+ result_text = result .content [0 ].text .casefold ()
262+
263+ assert "error" in result_text
264+
265+ async def test_get_network_routes_error (self , mcp_client , mock_execute ):
266+ """Test getting network routes with general error."""
267+ mock_execute .side_effect = ValueError ("Raised intentionally" )
268+ match = re .compile (r"error calling tool.*raised intentionally" , flags = re .I )
269+ with pytest .raises (ToolError , match = match ):
270+ await mcp_client .call_tool ("get_network_routes" )
0 commit comments