synced_folders/rsync: unit tests for the callback, fix bug

This commit is contained in:
Mitchell Hashimoto 2014-01-13 22:01:09 -08:00
parent fe2844ca59
commit 04f1854840
2 changed files with 103 additions and 0 deletions

View File

@ -72,6 +72,10 @@ module VagrantPlugins
throw :done, true if listenpath.start_with?(hostpath)
end
end
# Make sure to return false if all else fails so that we
# don't sync to this machine.
false
end
# If it should be synced, store it for later

View File

@ -0,0 +1,99 @@
require_relative "../../../../base"
require Vagrant.source_root.join("plugins/synced_folders/rsync/command/rsync_auto")
describe VagrantPlugins::SyncedFolderRSync::Command::RsyncAuto do
include_context "unit"
let(:argv) { [] }
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
let(:synced_folders) { {} }
let(:helper_class) { VagrantPlugins::SyncedFolderRSync::RsyncHelper }
subject do
described_class.new(argv, iso_env).tap do |s|
s.stub(synced_folders: synced_folders)
end
end
describe "#callback" do
let(:paths) { {} }
let(:ssh_info) {{}}
def machine_stub(name)
double(name).tap do |m|
m.stub(ssh_info: ssh_info)
end
end
it "syncs modified folders to the proper path" do
paths["/foo"] = [
{ machine: machine_stub("m1"), opts: double("opts_m1") },
{ machine: machine_stub("m2"), opts: double("opts_m2") },
]
paths["/bar"] = [
{ machine: machine_stub("m3"), opts: double("opts_m3") },
]
paths["/foo"].each do |data|
helper_class.should_receive(:rsync_single).
with(data[:machine], data[:machine].ssh_info, data[:opts]).
once
end
m = ["/foo/bar"]
a = []
r = []
subject.callback(paths, m, a, r)
end
it "syncs added folders to the proper path" do
paths["/foo"] = [
{ machine: machine_stub("m1"), opts: double("opts_m1") },
{ machine: machine_stub("m2"), opts: double("opts_m2") },
]
paths["/bar"] = [
{ machine: machine_stub("m3"), opts: double("opts_m3") },
]
paths["/foo"].each do |data|
helper_class.should_receive(:rsync_single).
with(data[:machine], data[:machine].ssh_info, data[:opts]).
once
end
m = []
a = ["/foo/bar"]
r = []
subject.callback(paths, m, a, r)
end
it "syncs removed folders to the proper path" do
paths["/foo"] = [
{ machine: machine_stub("m1"), opts: double("opts_m1") },
{ machine: machine_stub("m2"), opts: double("opts_m2") },
]
paths["/bar"] = [
{ machine: machine_stub("m3"), opts: double("opts_m3") },
]
paths["/foo"].each do |data|
helper_class.should_receive(:rsync_single).
with(data[:machine], data[:machine].ssh_info, data[:opts]).
once
end
m = []
a = []
r = ["/foo/bar"]
subject.callback(paths, m, a, r)
end
end
end