Add unit test for dockers compare_synced_folders

This commit is contained in:
Brian Cain 2019-02-04 11:12:55 -08:00
parent 80705c4804
commit 91e351b937
No known key found for this signature in database
GPG Key ID: 9FC4639B2E4510A0
1 changed files with 89 additions and 0 deletions

View File

@ -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