Skip to content

Commit

Permalink
Update test to check args to getaddrinfo
Browse files Browse the repository at this point in the history
  • Loading branch information
bwhaley committed Apr 15, 2024
1 parent 950e770 commit 3e98ddf
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions functions/replace-route/tests/test_replace_route.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,13 +209,11 @@ class Context:


def test_disable_ipv6():
results = socket.getaddrinfo("google.com", 80)
families = [family for family, _, _, _, _ in results]
assert socket.AF_INET6 in families, "Unable to find a non-IPv4 address family in getaddrinfo results before patching getaddrinfo"

from app import disable_ipv6
disable_ipv6()
results = socket.getaddrinfo("google.com", 80)
for family, _, _, _, _ in results:
assert family == socket.AF_INET, "Found a non-IPv4 address family in getaddrinfo results"

with mock.patch('socket.getaddrinfo') as mock_getaddrinfo:
from app import disable_ipv6
disable_ipv6()
socket.getaddrinfo('example.com', 80)
mock_getaddrinfo.assert_called()
call_args = mock_getaddrinfo.call_args.args
assert len(call_args) == 3, f"With IPv6 disabled, expected 3 arguments to getaddrinfo, found {len(call_args)}"
assert call_args[2] == socket.AF_INET, "Did not find AF_INET family in args to getaddrinfo"

0 comments on commit 3e98ddf

Please sign in to comment.