From fe4743a22b75c2cb5fceac303a8beee3385b5885 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dan=20=C4=8Cerm=C3=A1k?= Date: Thu, 24 Oct 2019 12:29:43 +0200 Subject: [PATCH] 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. --- .../providers/docker/action/prepare_networks_test.rb | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) 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 524db9533..df864d88d 100644 --- a/test/unit/plugins/providers/docker/action/prepare_networks_test.rb +++ b/test/unit/plugins/providers/docker/action/prepare_networks_test.rb @@ -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