Merge pull request #11116 from briancain/DOCKER-LIST-INTERFACES
Only return interfaces where addr is not nil
This commit is contained in:
commit
33a53d0c4e
|
@ -34,7 +34,7 @@ module VagrantPlugins
|
|||
# @return [Array<Socket::Ifaddr>] interface list
|
||||
def list_interfaces
|
||||
Socket.getifaddrs.find_all do |i|
|
||||
i.addr.ip? && !i.addr.ipv4_loopback? &&
|
||||
!i.addr.nil? && i.addr.ip? && !i.addr.ipv4_loopback? &&
|
||||
!i.addr.ipv6_loopback? && !i.addr.ipv6_linklocal?
|
||||
end
|
||||
end
|
||||
|
|
|
@ -197,6 +197,25 @@ describe VagrantPlugins::DockerProvider::Action::PrepareNetworks do
|
|||
end
|
||||
end
|
||||
|
||||
describe "#list_interfaces" do
|
||||
let(:interfaces){ ["192.168.1.2", "192.168.10.10"] }
|
||||
|
||||
it "returns an array of interfaces to use" do
|
||||
allow(Socket).to receive(:getifaddrs).
|
||||
and_return(interfaces.map{|i| double(:socket, addr: Addrinfo.ip(i))})
|
||||
interfaces = subject.list_interfaces
|
||||
|
||||
expect(subject.list_interfaces.size).to eq(2)
|
||||
end
|
||||
|
||||
it "does not include an interface with the address is nil" do
|
||||
allow(Socket).to receive(:getifaddrs).
|
||||
and_return(interfaces.map{|i| double(:socket, addr: nil)})
|
||||
|
||||
expect(subject.list_interfaces.size).to eq(0)
|
||||
end
|
||||
end
|
||||
|
||||
describe "#generate_create_cli_arguments" do
|
||||
let(:network_options) {
|
||||
{:ip=>"172.20.128.2",
|
||||
|
|
Loading…
Reference in New Issue