From 5b4dcf944350f966f320c4b78ef476ac6f0e1567 Mon Sep 17 00:00:00 2001 From: Anders Kaseorg Date: Tue, 10 Sep 2019 14:15:41 -0700 Subject: [PATCH 1/7] providers/docker: Fix usability check MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In commit 7980178d194bb21bde2e21858fbc969e4cc7eb3f (#10879) I added a `usable?` class method to `VagrantPlugins::DockerProvider::Provider`. However, commit 34e53a5a4b208edcc3e25c1f0e3aa0ef56e8d8d9 (#10890) incorrectly changed it to an instance method. This rendered it ineffective because it’s called on the class, not an instance. Change it back to a class method. Signed-off-by: Anders Kaseorg --- plugins/providers/docker/provider.rb | 16 ++++++++-------- .../docker/action/destroy_network_test.rb | 1 + .../plugins/providers/docker/provider_test.rb | 5 ++++- test/unit/support/shared/virtualbox_context.rb | 5 +++++ 4 files changed, 18 insertions(+), 9 deletions(-) diff --git a/plugins/providers/docker/provider.rb b/plugins/providers/docker/provider.rb index acef00498..5a4779a08 100644 --- a/plugins/providers/docker/provider.rb +++ b/plugins/providers/docker/provider.rb @@ -11,6 +11,14 @@ module VagrantPlugins class Provider < Vagrant.plugin("2", :provider) @@host_vm_mutex = Mutex.new + def self.usable?(raise_error=false) + Driver.new.execute("docker", "version") + true + rescue Vagrant::Errors::CommandUnavailable, Errors::ExecuteError + raise if raise_error + return false + end + def initialize(machine) @logger = Log4r::Logger.new("vagrant::provider::docker") @machine = machine @@ -45,14 +53,6 @@ module VagrantPlugins @driver end - def usable?(raise_error=false) - driver.execute("docker", "version") - true - rescue Vagrant::Errors::CommandUnavailable, Errors::ExecuteError - raise if raise_error - return false - end - # This returns the {Vagrant::Machine} that is our host machine. # It does not perform any action on the machine or verify it is # running. diff --git a/test/unit/plugins/providers/docker/action/destroy_network_test.rb b/test/unit/plugins/providers/docker/action/destroy_network_test.rb index e6856f022..27957cbaa 100644 --- a/test/unit/plugins/providers/docker/action/destroy_network_test.rb +++ b/test/unit/plugins/providers/docker/action/destroy_network_test.rb @@ -3,6 +3,7 @@ require_relative "../../../../../../plugins/providers/docker/action/destroy_netw describe VagrantPlugins::DockerProvider::Action::DestroyNetwork do include_context "unit" + include_context "virtualbox" let(:sandbox) { isolated_environment } diff --git a/test/unit/plugins/providers/docker/provider_test.rb b/test/unit/plugins/providers/docker/provider_test.rb index 64d1f4d6d..3cb6e03cb 100644 --- a/test/unit/plugins/providers/docker/provider_test.rb +++ b/test/unit/plugins/providers/docker/provider_test.rb @@ -21,9 +21,12 @@ describe VagrantPlugins::DockerProvider::Provider do end describe ".usable?" do + subject { described_class } + it "returns true if usable" do + allow(VagrantPlugins::DockerProvider::Driver).to receive(:new).and_return(driver_obj) allow(provider_config).to receive(:compose).and_return(false) - allow(subject.driver).to receive(:execute).with("docker", "version").and_return(true) + allow(driver_obj).to receive(:execute).with("docker", "version").and_return(true) expect(subject).to be_usable end diff --git a/test/unit/support/shared/virtualbox_context.rb b/test/unit/support/shared/virtualbox_context.rb index 1909ccdc9..f28ec8420 100644 --- a/test/unit/support/shared/virtualbox_context.rb +++ b/test/unit/support/shared/virtualbox_context.rb @@ -28,6 +28,11 @@ shared_context "virtualbox" do allow(subprocess).to receive(:execute). with("VBoxManage", "showvminfo", kind_of(String), kind_of(Hash)). and_return(subprocess_result(exit_code: 0)) + + # apparently this is also used in docker tests + allow(subprocess).to receive(:execute). + with("docker", "version", an_instance_of(Hash)). + and_return(subprocess_result(exit_code: 0)) end around do |example| From ebe1f3f1c9bc478becfe3acfdaa3d5eeef948ff2 Mon Sep 17 00:00:00 2001 From: Brian Cain Date: Wed, 11 Sep 2019 07:46:40 -0700 Subject: [PATCH 2/7] Remove virtualbox context from docker tests --- .../plugins/providers/docker/action/connect_networks_test.rb | 1 - .../plugins/providers/docker/action/destroy_network_test.rb | 1 - test/unit/plugins/providers/docker/action/login_test.rb | 1 - .../plugins/providers/docker/action/prepare_networks_test.rb | 1 - test/unit/support/shared/virtualbox_context.rb | 5 ----- 5 files changed, 9 deletions(-) diff --git a/test/unit/plugins/providers/docker/action/connect_networks_test.rb b/test/unit/plugins/providers/docker/action/connect_networks_test.rb index 8d57f1d4b..16b9779cd 100644 --- a/test/unit/plugins/providers/docker/action/connect_networks_test.rb +++ b/test/unit/plugins/providers/docker/action/connect_networks_test.rb @@ -4,7 +4,6 @@ require_relative "../../../../../../plugins/providers/docker/action/connect_netw describe VagrantPlugins::DockerProvider::Action::ConnectNetworks do include_context "unit" - include_context "virtualbox" let(:sandbox) { isolated_environment } diff --git a/test/unit/plugins/providers/docker/action/destroy_network_test.rb b/test/unit/plugins/providers/docker/action/destroy_network_test.rb index 27957cbaa..e6856f022 100644 --- a/test/unit/plugins/providers/docker/action/destroy_network_test.rb +++ b/test/unit/plugins/providers/docker/action/destroy_network_test.rb @@ -3,7 +3,6 @@ require_relative "../../../../../../plugins/providers/docker/action/destroy_netw describe VagrantPlugins::DockerProvider::Action::DestroyNetwork do include_context "unit" - include_context "virtualbox" let(:sandbox) { isolated_environment } diff --git a/test/unit/plugins/providers/docker/action/login_test.rb b/test/unit/plugins/providers/docker/action/login_test.rb index 85b68897b..5ad0d0232 100644 --- a/test/unit/plugins/providers/docker/action/login_test.rb +++ b/test/unit/plugins/providers/docker/action/login_test.rb @@ -4,7 +4,6 @@ require_relative "../../../../../../plugins/providers/docker/action/login" describe VagrantPlugins::DockerProvider::Action::Login do include_context "unit" - include_context "virtualbox" let(:sandbox) { isolated_environment } 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 1a2ccb7eb..953e75b92 100644 --- a/test/unit/plugins/providers/docker/action/prepare_networks_test.rb +++ b/test/unit/plugins/providers/docker/action/prepare_networks_test.rb @@ -3,7 +3,6 @@ require_relative "../../../../../../plugins/providers/docker/action/prepare_netw describe VagrantPlugins::DockerProvider::Action::PrepareNetworks do include_context "unit" - include_context "virtualbox" let(:sandbox) { isolated_environment } diff --git a/test/unit/support/shared/virtualbox_context.rb b/test/unit/support/shared/virtualbox_context.rb index f28ec8420..1909ccdc9 100644 --- a/test/unit/support/shared/virtualbox_context.rb +++ b/test/unit/support/shared/virtualbox_context.rb @@ -28,11 +28,6 @@ shared_context "virtualbox" do allow(subprocess).to receive(:execute). with("VBoxManage", "showvminfo", kind_of(String), kind_of(Hash)). and_return(subprocess_result(exit_code: 0)) - - # apparently this is also used in docker tests - allow(subprocess).to receive(:execute). - with("docker", "version", an_instance_of(Hash)). - and_return(subprocess_result(exit_code: 0)) end around do |example| From 21db2db9acd5ea6566a518a0ded68eb668f5257f Mon Sep 17 00:00:00 2001 From: Brian Cain Date: Wed, 11 Sep 2019 08:09:26 -0700 Subject: [PATCH 3/7] Add machine config to machine double for rspec tests This commit mocks up the docker machines test config so that it doesn't actually invoke the docker driver in circle-ci --- .../providers/docker/action/connect_networks_test.rb | 9 +++++++++ .../providers/docker/action/destroy_network_test.rb | 9 +++++++++ test/unit/plugins/providers/docker/action/login_test.rb | 9 +++++++++ .../providers/docker/action/prepare_networks_test.rb | 9 +++++++++ 4 files changed, 36 insertions(+) diff --git a/test/unit/plugins/providers/docker/action/connect_networks_test.rb b/test/unit/plugins/providers/docker/action/connect_networks_test.rb index 16b9779cd..c84c76f3f 100644 --- a/test/unit/plugins/providers/docker/action/connect_networks_test.rb +++ b/test/unit/plugins/providers/docker/action/connect_networks_test.rb @@ -13,8 +13,17 @@ describe VagrantPlugins::DockerProvider::Action::ConnectNetworks do sandbox.create_vagrant_env end + let(:vm_config) { double("machine_vm_config") } + + let(:machine_config) do + double("machine_config").tap do |top_config| + allow(top_config).to receive(:vm).and_return(vm_config) + end + end + let(:machine) do iso_env.machine(iso_env.machine_names[0], :docker).tap do |m| + allow(m).to receive(:config).and_return(machine_config) allow(m).to receive(:id).and_return("12345") allow(m.provider).to receive(:driver).and_return(driver) allow(m.provider).to receive(:host_vm?).and_return(false) diff --git a/test/unit/plugins/providers/docker/action/destroy_network_test.rb b/test/unit/plugins/providers/docker/action/destroy_network_test.rb index e6856f022..96fee8bbf 100644 --- a/test/unit/plugins/providers/docker/action/destroy_network_test.rb +++ b/test/unit/plugins/providers/docker/action/destroy_network_test.rb @@ -12,8 +12,17 @@ describe VagrantPlugins::DockerProvider::Action::DestroyNetwork do sandbox.create_vagrant_env end + let(:vm_config) { double("machine_vm_config") } + + let(:machine_config) do + double("machine_config").tap do |top_config| + allow(top_config).to receive(:vm).and_return(vm_config) + end + end + let(:machine) do iso_env.machine(iso_env.machine_names[0], :docker).tap do |m| + allow(m).to receive(:config).and_return(machine_config) allow(m.provider).to receive(:driver).and_return(driver) allow(m.config.vm).to receive(:networks).and_return(networks) end diff --git a/test/unit/plugins/providers/docker/action/login_test.rb b/test/unit/plugins/providers/docker/action/login_test.rb index 5ad0d0232..503dd9afc 100644 --- a/test/unit/plugins/providers/docker/action/login_test.rb +++ b/test/unit/plugins/providers/docker/action/login_test.rb @@ -15,9 +15,18 @@ describe VagrantPlugins::DockerProvider::Action::Login do let(:provider_config) { double("provider_config", username: "docker", password: "") } + let(:vm_config) { double("machine_vm_config") } + + let(:machine_config) do + double("machine_config").tap do |top_config| + allow(top_config).to receive(:vm).and_return(vm_config) + end + end + let(:machine) do iso_env.machine(iso_env.machine_names[0], :docker).tap do |m| allow(m).to receive(:id).and_return("12345") + allow(m).to receive(:config).and_return(machine_config) allow(m).to receive(:provider_config).and_return(provider_config) allow(m.provider).to receive(:driver).and_return(driver) allow(m.provider).to receive(:host_vm?).and_return(false) 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 953e75b92..797f5a505 100644 --- a/test/unit/plugins/providers/docker/action/prepare_networks_test.rb +++ b/test/unit/plugins/providers/docker/action/prepare_networks_test.rb @@ -12,8 +12,17 @@ describe VagrantPlugins::DockerProvider::Action::PrepareNetworks do sandbox.create_vagrant_env end + let(:vm_config) { double("machine_vm_config") } + + let(:machine_config) do + double("machine_config").tap do |top_config| + allow(top_config).to receive(:vm).and_return(vm_config) + end + end + let(:machine) do iso_env.machine(iso_env.machine_names[0], :docker).tap do |m| + allow(m).to receive(:config).and_return(machine_config) allow(m.provider).to receive(:driver).and_return(driver) allow(m.config.vm).to receive(:networks).and_return(networks) end From f14cf09af6e70d645d5c87c5399b8e4a2c501ac0 Mon Sep 17 00:00:00 2001 From: Brian Cain Date: Wed, 11 Sep 2019 08:37:07 -0700 Subject: [PATCH 4/7] Add allow for docker driver execute method --- .../plugins/providers/docker/action/connect_networks_test.rb | 4 ++++ .../plugins/providers/docker/action/destroy_network_test.rb | 4 ++++ test/unit/plugins/providers/docker/action/login_test.rb | 4 ++++ .../plugins/providers/docker/action/prepare_networks_test.rb | 4 ++++ 4 files changed, 16 insertions(+) diff --git a/test/unit/plugins/providers/docker/action/connect_networks_test.rb b/test/unit/plugins/providers/docker/action/connect_networks_test.rb index c84c76f3f..e5448e4e9 100644 --- a/test/unit/plugins/providers/docker/action/connect_networks_test.rb +++ b/test/unit/plugins/providers/docker/action/connect_networks_test.rb @@ -63,6 +63,10 @@ describe VagrantPlugins::DockerProvider::Action::ConnectNetworks do subject { described_class.new(app, env) } + before do + allow(driver).to receive(:execute) { |*args| @cmd = args.join(' ') } + end + after do sandbox.close end diff --git a/test/unit/plugins/providers/docker/action/destroy_network_test.rb b/test/unit/plugins/providers/docker/action/destroy_network_test.rb index 96fee8bbf..08f7281c7 100644 --- a/test/unit/plugins/providers/docker/action/destroy_network_test.rb +++ b/test/unit/plugins/providers/docker/action/destroy_network_test.rb @@ -52,6 +52,10 @@ describe VagrantPlugins::DockerProvider::Action::DestroyNetwork do subject { described_class.new(app, env) } + before do + allow(driver).to receive(:execute) { |*args| @cmd = args.join(' ') } + end + after do sandbox.close end diff --git a/test/unit/plugins/providers/docker/action/login_test.rb b/test/unit/plugins/providers/docker/action/login_test.rb index 503dd9afc..448d959ba 100644 --- a/test/unit/plugins/providers/docker/action/login_test.rb +++ b/test/unit/plugins/providers/docker/action/login_test.rb @@ -40,6 +40,10 @@ describe VagrantPlugins::DockerProvider::Action::Login do subject { described_class.new(app, env) } + before do + allow(driver).to receive(:execute) { |*args| @cmd = args.join(' ') } + end + after do sandbox.close end 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 797f5a505..3bcb3ebe7 100644 --- a/test/unit/plugins/providers/docker/action/prepare_networks_test.rb +++ b/test/unit/plugins/providers/docker/action/prepare_networks_test.rb @@ -64,6 +64,10 @@ describe VagrantPlugins::DockerProvider::Action::PrepareNetworks do subject { described_class.new(app, env) } + before do + allow(driver).to receive(:execute) { |*args| @cmd = args.join(' ') } + end + after do sandbox.close end From e820b5df8eda0a2bbbfaee674507af7c50447a11 Mon Sep 17 00:00:00 2001 From: Brian Cain Date: Wed, 11 Sep 2019 09:01:35 -0700 Subject: [PATCH 5/7] Add vagrantfile double for environment class --- .../providers/docker/action/connect_networks_test.rb | 4 +++- .../providers/docker/action/destroy_network_test.rb | 4 +++- test/unit/plugins/providers/docker/action/login_test.rb | 4 +++- .../providers/docker/action/prepare_networks_test.rb | 8 +++----- 4 files changed, 12 insertions(+), 8 deletions(-) diff --git a/test/unit/plugins/providers/docker/action/connect_networks_test.rb b/test/unit/plugins/providers/docker/action/connect_networks_test.rb index e5448e4e9..54827ff4a 100644 --- a/test/unit/plugins/providers/docker/action/connect_networks_test.rb +++ b/test/unit/plugins/providers/docker/action/connect_networks_test.rb @@ -33,8 +33,10 @@ describe VagrantPlugins::DockerProvider::Action::ConnectNetworks do let(:docker_connects) { {0=>"vagrant_network_172.20.0.0/16", 1=>"vagrant_network_public_wlp4s0", 2=>"vagrant_network_2a02:6b8:b010:9020:1::/80"} } + let(:vagrantfile) { double("vagrantfile") } + let(:env) {{ machine: machine, ui: machine.ui, root_path: Pathname.new("."), - docker_connects: docker_connects }} + docker_connects: docker_connects, vagrantfile: vagrantfile }} let(:app) { lambda { |*args| }} let(:driver) { double("driver", create: "abcd1234") } diff --git a/test/unit/plugins/providers/docker/action/destroy_network_test.rb b/test/unit/plugins/providers/docker/action/destroy_network_test.rb index 08f7281c7..7b9b266da 100644 --- a/test/unit/plugins/providers/docker/action/destroy_network_test.rb +++ b/test/unit/plugins/providers/docker/action/destroy_network_test.rb @@ -28,7 +28,9 @@ describe VagrantPlugins::DockerProvider::Action::DestroyNetwork do end end - let(:env) {{ machine: machine, ui: machine.ui, root_path: Pathname.new(".") }} + let(:vagrantfile) { double("vagrantfile") } + + let(:env) {{ machine: machine, ui: machine.ui, root_path: Pathname.new("."), vagrantfile: vagrantfile }} let(:app) { lambda { |*args| }} let(:driver) { double("driver", create: "abcd1234") } diff --git a/test/unit/plugins/providers/docker/action/login_test.rb b/test/unit/plugins/providers/docker/action/login_test.rb index 448d959ba..c1ae5a4ec 100644 --- a/test/unit/plugins/providers/docker/action/login_test.rb +++ b/test/unit/plugins/providers/docker/action/login_test.rb @@ -33,7 +33,9 @@ describe VagrantPlugins::DockerProvider::Action::Login do end end - let(:env) {{ machine: machine, ui: machine.ui, root_path: Pathname.new(".") }} + let(:vagrantfile) { double("vagrantfile") } + + let(:env) {{ machine: machine, ui: machine.ui, root_path: Pathname.new("."), vagrantfile: vagrantfile }} let(:app) { lambda { |*args| }} let(:driver) { double("driver", create: "abcd1234") } 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 3bcb3ebe7..c98a40f6b 100644 --- a/test/unit/plugins/providers/docker/action/prepare_networks_test.rb +++ b/test/unit/plugins/providers/docker/action/prepare_networks_test.rb @@ -28,7 +28,9 @@ describe VagrantPlugins::DockerProvider::Action::PrepareNetworks do end end - let(:env) {{ machine: machine, ui: machine.ui, root_path: Pathname.new(".") }} + let(:vagrantfile) { double("vagrantfile") } + + let(:env) {{ machine: machine, ui: machine.ui, root_path: Pathname.new("."), vagrantfile: vagrantfile }} let(:app) { lambda { |*args| }} let(:driver) { double("driver", create: "abcd1234") } @@ -64,10 +66,6 @@ describe VagrantPlugins::DockerProvider::Action::PrepareNetworks do subject { described_class.new(app, env) } - before do - allow(driver).to receive(:execute) { |*args| @cmd = args.join(' ') } - end - after do sandbox.close end From d4002aa74dd083a87b1944918a310ecd7585ac6e Mon Sep 17 00:00:00 2001 From: Brian Cain Date: Wed, 11 Sep 2019 09:17:14 -0700 Subject: [PATCH 6/7] Add vagrantfile mock to iso_env machine --- .../plugins/providers/docker/action/connect_networks_test.rb | 5 +---- .../plugins/providers/docker/action/destroy_network_test.rb | 5 +---- test/unit/plugins/providers/docker/action/login_test.rb | 5 +---- .../plugins/providers/docker/action/prepare_networks_test.rb | 1 + 4 files changed, 4 insertions(+), 12 deletions(-) diff --git a/test/unit/plugins/providers/docker/action/connect_networks_test.rb b/test/unit/plugins/providers/docker/action/connect_networks_test.rb index 54827ff4a..78e2a7d34 100644 --- a/test/unit/plugins/providers/docker/action/connect_networks_test.rb +++ b/test/unit/plugins/providers/docker/action/connect_networks_test.rb @@ -23,6 +23,7 @@ describe VagrantPlugins::DockerProvider::Action::ConnectNetworks do let(:machine) do iso_env.machine(iso_env.machine_names[0], :docker).tap do |m| + allow(m).to receive(:vagrantfile).and_return(vagrantfile) allow(m).to receive(:config).and_return(machine_config) allow(m).to receive(:id).and_return("12345") allow(m.provider).to receive(:driver).and_return(driver) @@ -65,10 +66,6 @@ describe VagrantPlugins::DockerProvider::Action::ConnectNetworks do subject { described_class.new(app, env) } - before do - allow(driver).to receive(:execute) { |*args| @cmd = args.join(' ') } - end - after do sandbox.close end diff --git a/test/unit/plugins/providers/docker/action/destroy_network_test.rb b/test/unit/plugins/providers/docker/action/destroy_network_test.rb index 7b9b266da..68e8aa1bc 100644 --- a/test/unit/plugins/providers/docker/action/destroy_network_test.rb +++ b/test/unit/plugins/providers/docker/action/destroy_network_test.rb @@ -22,6 +22,7 @@ describe VagrantPlugins::DockerProvider::Action::DestroyNetwork do let(:machine) do iso_env.machine(iso_env.machine_names[0], :docker).tap do |m| + allow(m).to receive(:vagrantfile).and_return(vagrantfile) allow(m).to receive(:config).and_return(machine_config) allow(m.provider).to receive(:driver).and_return(driver) allow(m.config.vm).to receive(:networks).and_return(networks) @@ -54,10 +55,6 @@ describe VagrantPlugins::DockerProvider::Action::DestroyNetwork do subject { described_class.new(app, env) } - before do - allow(driver).to receive(:execute) { |*args| @cmd = args.join(' ') } - end - after do sandbox.close end diff --git a/test/unit/plugins/providers/docker/action/login_test.rb b/test/unit/plugins/providers/docker/action/login_test.rb index c1ae5a4ec..07c0745a1 100644 --- a/test/unit/plugins/providers/docker/action/login_test.rb +++ b/test/unit/plugins/providers/docker/action/login_test.rb @@ -28,6 +28,7 @@ describe VagrantPlugins::DockerProvider::Action::Login do allow(m).to receive(:id).and_return("12345") allow(m).to receive(:config).and_return(machine_config) allow(m).to receive(:provider_config).and_return(provider_config) + allow(m).to receive(:vagrantfile).and_return(vagrantfile) allow(m.provider).to receive(:driver).and_return(driver) allow(m.provider).to receive(:host_vm?).and_return(false) end @@ -42,10 +43,6 @@ describe VagrantPlugins::DockerProvider::Action::Login do subject { described_class.new(app, env) } - before do - allow(driver).to receive(:execute) { |*args| @cmd = args.join(' ') } - end - after do sandbox.close end 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 c98a40f6b..67ecc5470 100644 --- a/test/unit/plugins/providers/docker/action/prepare_networks_test.rb +++ b/test/unit/plugins/providers/docker/action/prepare_networks_test.rb @@ -22,6 +22,7 @@ describe VagrantPlugins::DockerProvider::Action::PrepareNetworks do let(:machine) do iso_env.machine(iso_env.machine_names[0], :docker).tap do |m| + allow(m).to receive(:vagrantfile).and_return(vagrantfile) allow(m).to receive(:config).and_return(machine_config) allow(m.provider).to receive(:driver).and_return(driver) allow(m.config.vm).to receive(:networks).and_return(networks) From c7b1f8821dd258c103dfbe217812c9bf02ac934f Mon Sep 17 00:00:00 2001 From: Brian Cain Date: Wed, 11 Sep 2019 09:36:11 -0700 Subject: [PATCH 7/7] Try to mock up docker version subprocess result in test --- .../providers/docker/action/connect_networks_test.rb | 12 ++++++++++++ .../providers/docker/action/destroy_network_test.rb | 12 ++++++++++++ .../plugins/providers/docker/action/login_test.rb | 12 ++++++++++++ .../providers/docker/action/prepare_networks_test.rb | 12 ++++++++++++ 4 files changed, 48 insertions(+) diff --git a/test/unit/plugins/providers/docker/action/connect_networks_test.rb b/test/unit/plugins/providers/docker/action/connect_networks_test.rb index 78e2a7d34..3b7dbd27b 100644 --- a/test/unit/plugins/providers/docker/action/connect_networks_test.rb +++ b/test/unit/plugins/providers/docker/action/connect_networks_test.rb @@ -66,6 +66,18 @@ describe VagrantPlugins::DockerProvider::Action::ConnectNetworks do subject { described_class.new(app, env) } + let(:subprocess_result) do + double("subprocess_result").tap do |result| + allow(result).to receive(:exit_code).and_return(0) + allow(result).to receive(:stdout).and_return("") + allow(result).to receive(:stderr).and_return("") + end + end + + before do + allow(Vagrant::Util::Subprocess).to receive(:execute).with("docker", "version", an_instance_of(Hash)).and_return(subprocess_result) + end + after do sandbox.close end diff --git a/test/unit/plugins/providers/docker/action/destroy_network_test.rb b/test/unit/plugins/providers/docker/action/destroy_network_test.rb index 68e8aa1bc..dad664dd3 100644 --- a/test/unit/plugins/providers/docker/action/destroy_network_test.rb +++ b/test/unit/plugins/providers/docker/action/destroy_network_test.rb @@ -55,6 +55,18 @@ describe VagrantPlugins::DockerProvider::Action::DestroyNetwork do subject { described_class.new(app, env) } + let(:subprocess_result) do + double("subprocess_result").tap do |result| + allow(result).to receive(:exit_code).and_return(0) + allow(result).to receive(:stdout).and_return("") + allow(result).to receive(:stderr).and_return("") + end + end + + before do + allow(Vagrant::Util::Subprocess).to receive(:execute).with("docker", "version", an_instance_of(Hash)).and_return(subprocess_result) + end + after do sandbox.close end diff --git a/test/unit/plugins/providers/docker/action/login_test.rb b/test/unit/plugins/providers/docker/action/login_test.rb index 07c0745a1..48daf10c9 100644 --- a/test/unit/plugins/providers/docker/action/login_test.rb +++ b/test/unit/plugins/providers/docker/action/login_test.rb @@ -43,6 +43,18 @@ describe VagrantPlugins::DockerProvider::Action::Login do subject { described_class.new(app, env) } + let(:subprocess_result) do + double("subprocess_result").tap do |result| + allow(result).to receive(:exit_code).and_return(0) + allow(result).to receive(:stdout).and_return("") + allow(result).to receive(:stderr).and_return("") + end + end + + before do + allow(Vagrant::Util::Subprocess).to receive(:execute).with("docker", "version", an_instance_of(Hash)).and_return(subprocess_result) + end + after do sandbox.close end 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 67ecc5470..095ca4335 100644 --- a/test/unit/plugins/providers/docker/action/prepare_networks_test.rb +++ b/test/unit/plugins/providers/docker/action/prepare_networks_test.rb @@ -67,6 +67,18 @@ describe VagrantPlugins::DockerProvider::Action::PrepareNetworks do subject { described_class.new(app, env) } + let(:subprocess_result) do + double("subprocess_result").tap do |result| + allow(result).to receive(:exit_code).and_return(0) + allow(result).to receive(:stdout).and_return("") + allow(result).to receive(:stderr).and_return("") + end + end + + before do + allow(Vagrant::Util::Subprocess).to receive(:execute).with("docker", "version", an_instance_of(Hash)).and_return(subprocess_result) + end + after do sandbox.close end