mirror of
https://github.com/discourse/discourse.git
synced 2024-12-02 22:33:55 +08:00
DEV: Introduce stub_ip_lookup
spec helper (#20571)
This commit is contained in:
parent
f6dc6da3f8
commit
749a4c5937
|
@ -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
|
||||||
|
|
|
@ -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
|
||||||
|
|
Loading…
Reference in New Issue
Block a user