From 94bb50fa7e1afb04b97e5aefad9e0ecbab89babb Mon Sep 17 00:00:00 2001 From: Brian Cain Date: Wed, 17 Oct 2018 14:14:27 -0700 Subject: [PATCH] Add test for syncing folders with docker provider --- .../action/host_machine_sync_folders.rb | 2 +- .../action/host_machine_sync_folders_test.rb | 70 +++++++++++++++++++ 2 files changed, 71 insertions(+), 1 deletion(-) create mode 100644 test/unit/plugins/providers/docker/action/host_machine_sync_folders_test.rb diff --git a/plugins/providers/docker/action/host_machine_sync_folders.rb b/plugins/providers/docker/action/host_machine_sync_folders.rb index a521293d1..38bbcc182 100644 --- a/plugins/providers/docker/action/host_machine_sync_folders.rb +++ b/plugins/providers/docker/action/host_machine_sync_folders.rb @@ -45,7 +45,7 @@ module VagrantPlugins def setup_synced_folders(host_machine, env) # Write the host machine SFID if we have one - id_path = env[:machine].data_dir.join("host_machine_sfid") + id_path = env[:machine].data_dir.join("host_machine_sfid") if !id_path.file? host_sfid = SecureRandom.uuid id_path.open("w") do |f| diff --git a/test/unit/plugins/providers/docker/action/host_machine_sync_folders_test.rb b/test/unit/plugins/providers/docker/action/host_machine_sync_folders_test.rb new file mode 100644 index 000000000..13f1e1e09 --- /dev/null +++ b/test/unit/plugins/providers/docker/action/host_machine_sync_folders_test.rb @@ -0,0 +1,70 @@ +require_relative "../../../../base" +require_relative "../../../../../../plugins/providers/docker/action/host_machine_sync_folders" + +describe VagrantPlugins::DockerProvider::Action::HostMachineSyncFolders 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], :virtualbox).tap do |m| + allow(m.provider).to receive(:driver).and_return(driver) + end + end + + let(:env) {{ machine: machine, ui: machine.ui, root_path: Pathname.new(".") }} + let(:app) { lambda { |*args| }} + let(:driver) { double("driver") } + + subject { described_class.new(app, env) } + + after do + sandbox.close + end + + describe "#call" do + it "calls the next action in the chain" do + allow(machine.provider).to receive(:host_vm?).and_return(false) + called = false + app = ->(*args) { called = true } + + action = described_class.new(app, env) + action.call(env) + + expect(called).to eq(true) + end + + context "with a host vm" do + it "calls the next action in the chain" do + allow(machine.provider).to receive(:host_vm?).and_return(true) + allow(machine.provider).to receive(:host_vm).and_return(machine) + called = false + app = ->(*args) { called = true } + + expect(machine.provider).to receive(:host_vm_lock).and_return(true) + action = described_class.new(app, env) + action.call(env) + + expect(called).to eq(true) + end + end + end + + describe "#setup_synced_folders" do + it "syncs folders on the guest machine with a given id" do + allow(Digest::MD5).to receive(:hexdigest).and_return("4e9414d72abee585b3d6263e50248e37") + expect(machine).to receive(:action).with(:sync_folders, {:synced_folders_config => anything}) + expect(env[:machine].config.vm).to receive(:synced_folder). + with("/var/lib/docker/docker_4e9414d72abee585b3d6263e50248e37", + "/vagrant", anything) + subject.send(:setup_synced_folders, machine, env) + end + end +end