From 91e351b9373879b87f2589b4c25bcc362f9cedd6 Mon Sep 17 00:00:00 2001 From: Brian Cain Date: Mon, 4 Feb 2019 11:12:55 -0800 Subject: [PATCH] Add unit test for dockers compare_synced_folders --- .../action/compare_synced_folders_test.rb | 89 +++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 test/unit/plugins/providers/docker/action/compare_synced_folders_test.rb diff --git a/test/unit/plugins/providers/docker/action/compare_synced_folders_test.rb b/test/unit/plugins/providers/docker/action/compare_synced_folders_test.rb new file mode 100644 index 000000000..27ff19d83 --- /dev/null +++ b/test/unit/plugins/providers/docker/action/compare_synced_folders_test.rb @@ -0,0 +1,89 @@ +require_relative "../../../../base" +require_relative "../../../../../../plugins/providers/docker/action/compare_synced_folders" + +describe VagrantPlugins::DockerProvider::Action::CompareSyncedFolders 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 + let(:cached) { {:docker=>{"/vagrant"=>{:guestpath=>"/vagrant", :hostpath=>"/home/hashicorp/code/vagrant-sandbox", :disabled=>false, :__vagrantfile=>true}}} } + let(:fresh) { {:docker=>{"/vagrant"=>{:guestpath=>"/vagrant", :hostpath=>".", :disabled=>false, :__vagrantfile=>true}}} } + + let(:existing) { {"/vagrant"=>"/home/hashicorp/code/vagrant-sandbox"} } + + + 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 "invalid or existing entries" do + let(:cached) { {:docker=>{"/vagrant"=>{:guestpath=>"/not-real", :hostpath=>"/home/hashicorp/code/vagrant-sandbox", :disabled=>false, :__vagrantfile=>true}}} } + let(:fresh) { {:docker=>{"/vagrant"=>{:guestpath=>"/vagrant", :hostpath=>".", :disabled=>false, :__vagrantfile=>true}}} } + it "shows a warning" do + allow(machine.provider).to receive(:host_vm?).and_return(false) + + called = false + app = ->(*args) { called = true } + action = described_class.new(app, env) + + expect(action).to receive(:synced_folders). + with(machine, cached: true).and_return(cached) + expect(action).to receive(:synced_folders). + with(machine).and_return(fresh) + + expect(machine.ui).to receive(:warn) + + action.call(env) + expect(called).to eq(true) + end + end + + it "shows no warning comparing synced folders" do + allow(machine.provider).to receive(:host_vm?).and_return(false) + + called = false + app = ->(*args) { called = true } + action = described_class.new(app, env) + + expect(action).to receive(:synced_folders). + with(machine, cached: true).and_return(cached) + expect(action).to receive(:synced_folders). + with(machine).and_return(fresh) + + action.call(env) + expect(machine.ui).not_to receive(:warn) + expect(called).to eq(true) + end + end +end