From 88a18fe2c5f2cee5eb1686eaa9a43709b1868038 Mon Sep 17 00:00:00 2001 From: Brian Cain Date: Thu, 21 Mar 2019 16:06:11 -0700 Subject: [PATCH] Add public network tests for docker provider --- plugins/providers/docker/errors.rb | 4 ++++ templates/locales/providers_docker.yml | 3 +++ .../docker/action/prepare_networks_test.rb | 15 +++++++++++++++ 3 files changed, 22 insertions(+) diff --git a/plugins/providers/docker/errors.rb b/plugins/providers/docker/errors.rb index 84b5e8f4e..11ae6fd68 100644 --- a/plugins/providers/docker/errors.rb +++ b/plugins/providers/docker/errors.rb @@ -69,6 +69,10 @@ module VagrantPlugins error_key(:network_name_undefined) end + class NetworkNoInterfaces < DockerError + error_key(:network_no_interfaces) + end + class PackageNotSupported < DockerError error_key(:package_not_supported) end diff --git a/templates/locales/providers_docker.yml b/templates/locales/providers_docker.yml index 00c929e8f..5c6b00018 100644 --- a/templates/locales/providers_docker.yml +++ b/templates/locales/providers_docker.yml @@ -252,6 +252,9 @@ en: The Docker provider was unable to configure networking using the provided network name `%{network_name}`. Please ensure the network name is correct and exists, then try again. + network_no_interfaces: |- + The Docker provider was unable to list any available interfaces to bridge + the public network with. network_subnet_invalid: |- The configured network subnet is not valid for the defined network. Please update the network settings and try again. diff --git a/test/unit/plugins/providers/docker/action/prepare_networks_test.rb b/test/unit/plugins/providers/docker/action/prepare_networks_test.rb index 4f42e84f3..f4e1504e0 100644 --- a/test/unit/plugins/providers/docker/action/prepare_networks_test.rb +++ b/test/unit/plugins/providers/docker/action/prepare_networks_test.rb @@ -281,6 +281,21 @@ describe VagrantPlugins::DockerProvider::Action::PrepareNetworks do end describe "#process_public_network" do + let(:options) { {:ip=>"172.30.130.2", :subnet=>"172.30.0.0/16", :driver=>"bridge", :id=>"30e017d5-488f-5a2f-a3ke-k8dce8246b60"} } + + it "raises an error if there are no network interfaces" do + expect(subject).to receive(:list_interfaces).and_return([]) + + expect{subject.process_public_network(options, {}, env)}. + to raise_error(VagrantPlugins::DockerProvider::Errors::NetworkNoInterfaces) + end + + it "generates a network name and configuration" do + allow(machine.ui).to receive(:ask).and_return("1") + + network_name, network_options = subject.process_public_network(options, {}, env) + expect(network_name).to eq("vagrant_network_public") + end end describe "#request_public_gateway" do