DEV: Introduce stub_ip_lookup spec helper (#20571)

This commit is contained in:
Alan Guo Xiang Tan 2023-03-08 09:28:09 +08:00
parent f6dc6da3f8
commit 749a4c5937
2 changed files with 9 additions and 9 deletions

View File

@ -25,15 +25,6 @@ describe FinalDestination::HTTP do
end end
end end
def stub_ip_lookup(stub_addr, ips)
Addrinfo
.stubs(:getaddrinfo)
.with { |addr, _| addr == stub_addr }
.returns(
ips.map { |ip| Addrinfo.new([IPAddr.new(ip).ipv6? ? "AF_INET6" : "AF_INET", 80, nil, ip]) },
)
end
def stub_tcp_to_raise(stub_addr, exception) def stub_tcp_to_raise(stub_addr, exception)
TCPSocket.stubs(:open).with { |addr| addr == stub_addr }.once.raises(exception) TCPSocket.stubs(:open).with { |addr| addr == stub_addr }.once.raises(exception)
end end

View File

@ -192,4 +192,13 @@ module Helpers
queries queries
end end
def stub_ip_lookup(stub_addr, ips)
Addrinfo
.stubs(:getaddrinfo)
.with { |addr, _| addr == stub_addr }
.returns(
ips.map { |ip| Addrinfo.new([IPAddr.new(ip).ipv6? ? "AF_INET6" : "AF_INET", 80, nil, ip]) },
)
end
end end