Mock call to PrepareNetworks.list_interfaces in docker prepare_networks_test

The test "generates a network name and configuration" calls at the end
`process_public_network()`, which can return an empty list if the currently
executing machine has no usable network interfaces (this is typically the case
for workers that build rpm packages in OBS or Koji). This results in an
exception of type Errors::NetworkNoInterfaces to be thrown and causing this test
to fail.

This commit adds a mock of the PrepareNetworks.list_interfaces call that returns
a single entry with just the required defaults.
This commit is contained in:
Dan Čermák 2019-10-24 12:29:43 +02:00
parent d70e3eb828
commit fe4743a22b
No known key found for this signature in database
GPG Key ID: E632C3380610D1C5
1 changed files with 10 additions and 2 deletions

View File

@ -324,8 +324,11 @@ describe VagrantPlugins::DockerProvider::Action::PrepareNetworks do
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"} }
let(:addr) { double("addr", ip: true, ip_address: "192.168.1.139") }
let(:netmask) { double("netmask", ip_unpack: ["255.255.255.0"]) }
let(:ipaddr) { double("ipaddr", prefix: 22, succ: "10.1.10.2", ipv4?: true,
ipv6?: false, to_i: 4294967040) }
ipv6?: false, to_i: 4294967040, name: "ens20u1u2",
addr: addr, netmask: netmask) }
it "raises an error if there are no network interfaces" do
expect(subject).to receive(:list_interfaces).and_return([])
@ -343,7 +346,12 @@ describe VagrantPlugins::DockerProvider::Action::PrepareNetworks do
allow(driver).to receive(:network_containing_address).
with("10.1.10.2").and_return("vagrant_network_public")
network_name, network_options = subject.process_public_network(options, {}, env)
# mock the call to PrepareNetworks.list_interfaces so that we don't depend
# on the current network interfaces
allow(subject).to receive(:list_interfaces).
and_return([ipaddr])
network_name, _network_options = subject.process_public_network(options, {}, env)
expect(network_name).to eq("vagrant_network_public")
end
end