Ensure variable names exist in method
This commit is contained in:
parent
6ce453ab70
commit
8c169714c5
|
@ -42,12 +42,13 @@ module VagrantPlugins
|
|||
# Validates that a network name exists. If it does not
|
||||
# exist, an exception is raised.
|
||||
#
|
||||
# @param [String] name Name of existing network
|
||||
# @param [String] network_name Name of existing network
|
||||
# @param [Hash] env Local call env
|
||||
# @return [Boolean]
|
||||
def validate_network_name!(name)
|
||||
def validate_network_name!(network_name, env)
|
||||
if !env[:machine].provider.driver.existing_named_network?(network_name)
|
||||
raise Errors::NetworkNameUndefined,
|
||||
network_name: name
|
||||
network_name: network_name
|
||||
end
|
||||
true
|
||||
end
|
||||
|
@ -83,7 +84,7 @@ module VagrantPlugins
|
|||
# @param [Hash] env Local call env
|
||||
# @return [String, Hash] Network name and updated network_options
|
||||
def process_private_network(root_options, network_options, env)
|
||||
if root_options[:name] && validate_network_name!(root_options[:name])
|
||||
if root_options[:name] && validate_network_name!(root_options[:name], env)
|
||||
network_name = root_options[:name]
|
||||
end
|
||||
|
||||
|
@ -150,7 +151,7 @@ module VagrantPlugins
|
|||
# @param [Hash] env Local call env
|
||||
# @return [String, Hash] Network name and updated network_options
|
||||
def process_public_network(root_options, net_options, env)
|
||||
if root_options[:name] && validate_network_name!(root_options[:name])
|
||||
if root_options[:name] && validate_network_name!(root_options[:name], env)
|
||||
network_name = root_options[:name]
|
||||
end
|
||||
if !network_name
|
||||
|
|
|
@ -105,7 +105,6 @@ describe VagrantPlugins::DockerProvider::Action::PrepareNetworks do
|
|||
expect(driver).to receive(:create_network).
|
||||
with("vagrant_network_2a02:6b8:b010:9020:1::/80", ["--ipv6", "--subnet", "2a02:6b8:b010:9020:1::/80"])
|
||||
|
||||
|
||||
subject.call(env)
|
||||
|
||||
expect(env[:docker_connects]).to eq({0=>"vagrant_network_172.20.128.0/24", 1=>"vagrant_network_public_wlp4s0", 2=>"vagrant_network_2a02:6b8:b010:9020:1::/80"})
|
||||
|
@ -193,10 +192,22 @@ describe VagrantPlugins::DockerProvider::Action::PrepareNetworks do
|
|||
end
|
||||
end
|
||||
|
||||
describe "#list_interfaces" do
|
||||
end
|
||||
|
||||
describe "#validate_network_name!" do
|
||||
let(:netname) { "vagrant_network" }
|
||||
|
||||
it "returns true if name exists" do
|
||||
allow(driver).to receive(:existing_named_network?).with(netname).
|
||||
and_return(true)
|
||||
|
||||
expect(subject.validate_network_name!(netname, env)).to be_truthy
|
||||
end
|
||||
|
||||
it "raises an error if name does not exist" do
|
||||
allow(driver).to receive(:existing_named_network?).with(netname).
|
||||
and_return(false)
|
||||
|
||||
expect{subject.validate_network_name!(netname, env)}.to raise_error(VagrantPlugins::DockerProvider::Errors::NetworkNameUndefined)
|
||||
end
|
||||
end
|
||||
|
||||
describe "#validate_network_configuration!" do
|
||||
|
|
Loading…
Reference in New Issue