Fix how options to cli args are handled
Since options could also be defined as strings, convert it all to string and compare those instead
This commit is contained in:
parent
5215354d16
commit
96a19aa00c
|
@ -20,13 +20,13 @@ module VagrantPlugins
|
||||||
# Generate CLI arguments for creating the docker network.
|
# Generate CLI arguments for creating the docker network.
|
||||||
#
|
#
|
||||||
# @param [Hash] options Options from the network config
|
# @param [Hash] options Options from the network config
|
||||||
# @returns[Array<String> Network create arguments
|
# @returns[Array<String>] Network create arguments
|
||||||
def generate_create_cli_arguments(options)
|
def generate_create_cli_arguments(options)
|
||||||
options.map do |key, value|
|
options.map do |key, value|
|
||||||
# If value is false, option is not set
|
# If value is false, option is not set
|
||||||
next if value == false
|
next if value.to_s == "false"
|
||||||
# If value is true, consider feature flag with no value
|
# If value is true, consider feature flag with no value
|
||||||
opt = value == true ? [] : [value]
|
opt = value.to_s == "true" ? [] : [value]
|
||||||
opt.unshift("--#{key.to_s.tr("_", "-")}")
|
opt.unshift("--#{key.to_s.tr("_", "-")}")
|
||||||
end.flatten.compact
|
end.flatten.compact
|
||||||
end
|
end
|
||||||
|
|
|
@ -163,22 +163,6 @@ describe VagrantPlugins::DockerProvider::Action::PrepareNetworks do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "#generate_connect_cli_arguments" do
|
|
||||||
let(:network_options) {
|
|
||||||
{:ip=>"172.20.128.2",
|
|
||||||
:subnet=>"172.20.0.0/16",
|
|
||||||
:driver=>"bridge",
|
|
||||||
:internal=>"true",
|
|
||||||
:alias=>"mynetwork",
|
|
||||||
:protocol=>"tcp",
|
|
||||||
:id=>"80e017d5-388f-4a2f-a3de-f8dce8156a58"} }
|
|
||||||
|
|
||||||
it "returns an array of cli arguments" do
|
|
||||||
cli_args = subject.generate_connect_cli_arguments(network_options)
|
|
||||||
expect(cli_args).to eq(["--ip", "172.20.128.2", "--alias=mynetwork"])
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
describe "#generate_create_cli_arguments" do
|
describe "#generate_create_cli_arguments" do
|
||||||
let(:network_options) {
|
let(:network_options) {
|
||||||
{:ip=>"172.20.128.2",
|
{:ip=>"172.20.128.2",
|
||||||
|
@ -189,9 +173,23 @@ describe VagrantPlugins::DockerProvider::Action::PrepareNetworks do
|
||||||
:protocol=>"tcp",
|
:protocol=>"tcp",
|
||||||
:id=>"80e017d5-388f-4a2f-a3de-f8dce8156a58"} }
|
:id=>"80e017d5-388f-4a2f-a3de-f8dce8156a58"} }
|
||||||
|
|
||||||
|
let(:false_network_options) {
|
||||||
|
{:ip=>"172.20.128.2",
|
||||||
|
:subnet=>"172.20.0.0/16",
|
||||||
|
:driver=>"bridge",
|
||||||
|
:internal=>"false",
|
||||||
|
:alias=>"mynetwork",
|
||||||
|
:protocol=>"tcp",
|
||||||
|
:id=>"80e017d5-388f-4a2f-a3de-f8dce8156a58"} }
|
||||||
|
|
||||||
it "returns an array of cli arguments" do
|
it "returns an array of cli arguments" do
|
||||||
cli_args = subject.generate_create_cli_arguments(network_options)
|
cli_args = subject.generate_create_cli_arguments(network_options)
|
||||||
expect(cli_args).to eq(["--subnet=172.20.0.0/16", "--driver=bridge", "--internal=true"])
|
expect(cli_args).to eq( ["--ip", "172.20.128.2", "--subnet", "172.20.0.0/16", "--driver", "bridge", "--internal", "--alias", "mynetwork", "--protocol", "tcp", "--id", "80e017d5-388f-4a2f-a3de-f8dce8156a58"])
|
||||||
|
end
|
||||||
|
|
||||||
|
it "removes option if set to false" do
|
||||||
|
cli_args = subject.generate_create_cli_arguments(false_network_options)
|
||||||
|
expect(cli_args).to eq( ["--ip", "172.20.128.2", "--subnet", "172.20.0.0/16", "--driver", "bridge", "--alias", "mynetwork", "--protocol", "tcp", "--id", "80e017d5-388f-4a2f-a3de-f8dce8156a58"])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue