2014-01-11 01:40:29 +00:00
|
|
|
require_relative "../../../base"
|
|
|
|
|
|
|
|
require Vagrant.source_root.join("plugins/synced_folders/rsync/synced_folder")
|
|
|
|
|
|
|
|
describe VagrantPlugins::SyncedFolderRSync::SyncedFolder do
|
|
|
|
include_context "unit"
|
|
|
|
|
|
|
|
let(:iso_env) do
|
|
|
|
# We have to create a Vagrantfile so there is a root path
|
|
|
|
env = isolated_environment
|
|
|
|
env.vagrantfile("")
|
|
|
|
env.create_vagrant_env
|
|
|
|
end
|
|
|
|
|
2014-01-11 01:51:44 +00:00
|
|
|
let(:guest) { double("guest") }
|
2014-01-11 01:40:29 +00:00
|
|
|
let(:host) { double("host") }
|
|
|
|
let(:machine) { iso_env.machine(iso_env.machine_names[0], :dummy) }
|
|
|
|
|
2014-01-13 19:01:50 +00:00
|
|
|
let(:helper_class) { VagrantPlugins::SyncedFolderRSync::RsyncHelper }
|
|
|
|
|
2014-01-11 01:40:29 +00:00
|
|
|
before do
|
|
|
|
machine.env.stub(host: host)
|
2014-01-11 01:51:44 +00:00
|
|
|
machine.stub(guest: guest)
|
2014-01-11 01:40:29 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
describe "#usable?" do
|
|
|
|
it "is usable if rsync can be found" do
|
|
|
|
Vagrant::Util::Which.should_receive(:which).with("rsync").and_return(true)
|
|
|
|
expect(subject.usable?(machine)).to be_true
|
|
|
|
end
|
|
|
|
|
|
|
|
it "is not usable if rsync cant be found" do
|
|
|
|
Vagrant::Util::Which.should_receive(:which).with("rsync").and_return(false)
|
|
|
|
expect(subject.usable?(machine)).to be_false
|
|
|
|
end
|
|
|
|
|
|
|
|
it "raises an exception if asked to" do
|
|
|
|
Vagrant::Util::Which.should_receive(:which).with("rsync").and_return(false)
|
|
|
|
expect { subject.usable?(machine, true) }.
|
|
|
|
to raise_error(Vagrant::Errors::RSyncNotFound)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "#enable" do
|
2014-01-11 04:37:11 +00:00
|
|
|
let(:ssh_info) {{
|
|
|
|
private_key_path: [],
|
|
|
|
}}
|
2014-01-11 01:40:29 +00:00
|
|
|
|
|
|
|
before do
|
|
|
|
machine.stub(ssh_info: ssh_info)
|
2014-01-31 03:26:43 +00:00
|
|
|
guest.stub(:capability?).with(:rsync_installed)
|
2014-01-11 01:40:29 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it "rsyncs each folder" do
|
|
|
|
folders = [
|
|
|
|
[:one, {}],
|
|
|
|
[:two, {}],
|
|
|
|
]
|
|
|
|
|
|
|
|
folders.each do |_, opts|
|
2014-01-13 19:01:50 +00:00
|
|
|
helper_class.should_receive(:rsync_single).
|
2014-01-11 01:51:44 +00:00
|
|
|
with(machine, ssh_info, opts).
|
2014-01-11 01:40:29 +00:00
|
|
|
ordered
|
|
|
|
end
|
|
|
|
|
|
|
|
subject.enable(machine, folders, {})
|
|
|
|
end
|
2014-01-31 03:26:43 +00:00
|
|
|
|
|
|
|
it "installs rsync if capable" do
|
|
|
|
folders = [ [:foo, {}] ]
|
|
|
|
|
|
|
|
helper_class.stub(:rsync_single)
|
|
|
|
|
|
|
|
guest.stub(:capability?).with(:rsync_installed).and_return(true)
|
|
|
|
guest.stub(:capability?).with(:rsync_install).and_return(true)
|
|
|
|
|
|
|
|
expect(guest).to receive(:capability).with(:rsync_installed).and_return(false)
|
|
|
|
expect(guest).to receive(:capability).with(:rsync_install)
|
|
|
|
|
|
|
|
subject.enable(machine, folders, {})
|
|
|
|
end
|
|
|
|
|
|
|
|
it "errors if rsync not installable" do
|
|
|
|
folders = [ [:foo, {}] ]
|
|
|
|
|
|
|
|
helper_class.stub(:rsync_single)
|
|
|
|
|
|
|
|
guest.stub(:capability?).with(:rsync_installed).and_return(true)
|
|
|
|
guest.stub(:capability?).with(:rsync_install).and_return(false)
|
|
|
|
|
|
|
|
expect(guest).to receive(:capability).with(:rsync_installed).and_return(false)
|
|
|
|
|
|
|
|
expect { subject.enable(machine, folders, {}) }.
|
|
|
|
to raise_error(Vagrant::Errors::RSyncNotInstalledInGuest)
|
|
|
|
end
|
2014-01-11 01:40:29 +00:00
|
|
|
end
|
|
|
|
end
|