Merge pull request #9550 from chrisroberts/f-vbox-hostnet

When matching hostonly adapter name, force common types
This commit is contained in:
Chris Roberts 2018-03-09 14:30:49 -08:00 committed by GitHub
commit 030a08f869
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 43 additions and 2 deletions

View File

@ -480,7 +480,7 @@ module VagrantPlugins
return interface if config[:name] && config[:name] == interface[:name]
#if a config name is specified, we should only look for that.
if config[:name] != ""
if config[:name].to_s != ""
next
end

View File

@ -181,4 +181,45 @@ describe VagrantPlugins::ProviderVirtualBox::Action::Network do
end
end
end
describe "#hostonly_find_matching_network" do
let(:ip){ "192.168.55.2" }
let(:config){ {ip: ip, netmask: "255.255.255.0"} }
let(:interfaces){ [] }
before do
allow(driver).to receive(:read_host_only_interfaces).and_return(interfaces)
subject.instance_variable_set(:@env, env)
end
context "with no defined host interfaces" do
it "should return nil" do
expect(subject.hostonly_find_matching_network(config)).to be_nil
end
end
context "with matching host interface" do
let(:interfaces){ [{ip: "192.168.55.1", netmask: "255.255.255.0", name: "vnet"}] }
it "should return matching interface" do
expect(subject.hostonly_find_matching_network(config)).to eq(interfaces.first)
end
context "with matching name" do
let(:config){ {ip: ip, netmask: "255.255.255.0", name: "vnet"} }
it "should return matching interface" do
expect(subject.hostonly_find_matching_network(config)).to eq(interfaces.first)
end
end
context "with non-matching name" do
let(:config){ {ip: ip, netmask: "255.255.255.0", name: "unknown"} }
it "should return nil" do
expect(subject.hostonly_find_matching_network(config)).to be_nil
end
end
end
end
end