diff --git a/plugins/synced_folders/rsync/command/rsync_auto.rb b/plugins/synced_folders/rsync/command/rsync_auto.rb index b0cbfb6ae..42d9e4e55 100644 --- a/plugins/synced_folders/rsync/command/rsync_auto.rb +++ b/plugins/synced_folders/rsync/command/rsync_auto.rb @@ -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 diff --git a/test/unit/plugins/synced_folders/rsync/command/rsync_auto_test.rb b/test/unit/plugins/synced_folders/rsync/command/rsync_auto_test.rb new file mode 100644 index 000000000..7da7cc9a8 --- /dev/null +++ b/test/unit/plugins/synced_folders/rsync/command/rsync_auto_test.rb @@ -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