Skip to content

Commit

Permalink
Fix test_traceroute unit test.
Browse files Browse the repository at this point in the history
Not all calls to `salt.utils.path.which` should return `traceroute`
  • Loading branch information
s0undt3ch authored and Ch3LL committed Mar 3, 2021
1 parent de4d93a commit 780a223
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion tests/unit/modules/test_network.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import logging
import os.path
import shutil
import socket

import salt.config
Expand Down Expand Up @@ -121,7 +122,20 @@ def test_traceroute(self):
"""
Test for Performs a traceroute to a 3rd party host
"""
with patch("salt.utils.path.which", MagicMock(return_value="traceroute")):

def patched_which(binary):
binary_path = shutil.which(binary)
if binary_path:
# The path exists, just return it
return binary_path
if binary == "traceroute":
# The path doesn't exist but we mock it on the test.
# Return the binary name
return binary
# The binary does not exist
return binary_path

with patch("salt.utils.path.which", patched_which):
with patch.dict(network.__salt__, {"cmd.run": MagicMock(return_value="")}):
self.assertListEqual(network.traceroute("gentoo.org"), [])

Expand Down

0 comments on commit 780a223

Please sign in to comment.