Add beginning of connect network tests for docker provider

This commit is contained in:
Brian Cain 2019-03-21 16:06:24 -07:00
parent 88a18fe2c5
commit 6bffdca972
No known key found for this signature in database
GPG Key ID: 9FC4639B2E4510A0
2 changed files with 96 additions and 2 deletions

View File

@ -1,6 +1,8 @@
require 'ipaddr' require 'ipaddr'
require 'log4r' require 'log4r'
require 'vagrant/util/scoped_hash_override'
module VagrantPlugins module VagrantPlugins
module DockerProvider module DockerProvider
module Action module Action
@ -20,9 +22,9 @@ module VagrantPlugins
def generate_connect_cli_arguments(options) def generate_connect_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

View File

@ -0,0 +1,92 @@
require_relative "../../../../base"
require_relative "../../../../../../plugins/providers/docker/action/connect_networks"
describe VagrantPlugins::DockerProvider::Action::ConnectNetworks do
include_context "unit"
include_context "virtualbox"
let(:sandbox) { isolated_environment }
let(:iso_env) do
# We have to create a Vagrantfile so there is a root path
sandbox.vagrantfile("")
sandbox.create_vagrant_env
end
let(:machine) do
iso_env.machine(iso_env.machine_names[0], :docker).tap do |m|
allow(m.provider).to receive(:driver).and_return(driver)
allow(m.config.vm).to receive(:networks).and_return(networks)
end
end
let(:docker_connects) { {0=>"vagrant_network_172.20.128.0/24", 1=>"vagrant_network_public_wlp4s0", 2=>"vagrant_network_2a02:6b8:b010:9020:1::/80"} }
let(:env) {{ machine: machine, ui: machine.ui, root_path: Pathname.new("."),
docker_connects: docker_connects }}
let(:app) { lambda { |*args| }}
let(:driver) { double("driver", create: "abcd1234") }
let(:networks) { [[:private_network,
{: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"}],
[:public_network,
{:ip=>"172.30.130.2",
:subnet=>"172.30.0.0/16",
:driver=>"bridge",
:id=>"30e017d5-488f-5a2f-a3ke-k8dce8246b60"}],
[:private_network,
{:type=>"dhcp",
:ipv6=>"true",
:subnet=>"2a02:6b8:b010:9020:1::/80",
:protocol=>"tcp",
:id=>"b8f23054-38d5-45c3-99ea-d33fc5d1b9f2"}],
[:forwarded_port,
{:guest=>22, :host=>2200, :host_ip=>"127.0.0.1", :id=>"ssh", :auto_correct=>true, :protocol=>"tcp"}]]
}
subject { described_class.new(app, env) }
after do
sandbox.close
end
describe "#call" do
it "calls the next action in the chain" do
allow(driver).to receive(:host_vm?).and_return(false)
allow(driver).to receive(:connect_network).and_return(true)
called = false
app = ->(*args) { called = true }
action = described_class.new(app, env)
action.call(env)
expect(called).to eq(true)
end
it "connects all of the avaiable networks to a container" do
end
it "raises an error if the network name is missing" do
end
end
describe "#generate_connect_cli_arguments" do
it "removes false values" do
end
it "removes true and leaves flag value in arguments" do
end
it "takes options and generates cli flags" do
end
end
end