diff --git a/lib/vagrant/systems/linux.rb b/lib/vagrant/systems/linux.rb index b553ca933..2da6fd11c 100644 --- a/lib/vagrant/systems/linux.rb +++ b/lib/vagrant/systems/linux.rb @@ -57,16 +57,16 @@ module Vagrant :scriptname => config.vm.rsync_script)) ssh.exec!("sudo mkdir -p #{opts[:rsyncpath]}") - ssh.exec!("sudo chmod +x #{config.vm.rsync_script}") + chown(ssh, opts[:rsyncpath]) ssh.exec!("sudo echo \"#{crontab_entry}\" >> #{config.vm.rsync_crontab_entry_file}") ssh.exec!("crontab #{config.vm.rsync_crontab_entry_file}") - chown(ssh, opts[:rsyncpath]) end def prepare_rsync(ssh) logger.info "Preparing system for rsync..." vm.env.ssh.upload!(StringIO.new(render_rsync), config.vm.rsync_script) - ssh.exec!('sudo rm #{config.vm.rsync_crontab_entry_file}') + ssh.exec!("sudo chmod +x #{config.vm.rsync_script}") + ssh.exec!("sudo rm #{config.vm.rsync_crontab_entry_file}") end #------------------------------------------------------------------- diff --git a/test/test_helper.rb b/test/test_helper.rb index d5491dfdc..7cc388ec2 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -43,6 +43,8 @@ class Test::Unit::TestCase config.vm.shared_folder_uid = nil config.vm.shared_folder_gid = nil config.vm.system = :linux + config.vm.rsync_script = "/foo" + config.vm.rsync_crontab_entry_file = "/tmp/foo" config.package.name = 'vagrant' config.package.extension = '.box' diff --git a/test/vagrant/actions/vm/shared_folders_test.rb b/test/vagrant/actions/vm/shared_folders_test.rb index ae478f6ca..581906050 100644 --- a/test/vagrant/actions/vm/shared_folders_test.rb +++ b/test/vagrant/actions/vm/shared_folders_test.rb @@ -129,7 +129,7 @@ class SharedFoldersActionTest < Test::Unit::TestCase end context "with rsyncd folders" do - # TODO + # TODO prevented by odd configuration swapping when stubbing ssh.execute should "prepare the system for rsync if necessary" do end end diff --git a/test/vagrant/systems/linux_test.rb b/test/vagrant/systems/linux_test.rb index f66b0499b..8c77c0eae 100644 --- a/test/vagrant/systems/linux_test.rb +++ b/test/vagrant/systems/linux_test.rb @@ -3,15 +3,16 @@ require File.join(File.dirname(__FILE__), '..', '..', 'test_helper') class LinuxSystemTest < Test::Unit::TestCase setup do @klass = Vagrant::Systems::Linux - - @vm = mock_vm + @ssh = mock("ssh") + @mock_env = mock_environment + @vm = mock("vm") + @vm.stubs(:env).returns(@mock_env) @instance = @klass.new(@vm) end context "halting" do setup do @ssh_session = mock("ssh_session") - @ssh = mock("ssh") @ssh.stubs(:execute).yields(@ssh_session) @vm.stubs(:ssh).returns(@ssh) @@ -28,7 +29,6 @@ class LinuxSystemTest < Test::Unit::TestCase context "mounting shared folders" do setup do - @ssh = mock("ssh") @name = "foo" @guestpath = "/bar" end @@ -43,12 +43,67 @@ class LinuxSystemTest < Test::Unit::TestCase end end + context "preparing rsync" do + setup do + @ssh.stubs(:exec!) + @vm.env.stubs(:ssh).returns(@ssh) + @vm.env.ssh.stubs(:upload!) + end + + should "upload the rsync template" do + @vm.env.ssh.expects(:upload!).with do |string_io, guest_path| + string_io.string =~ /#!\/bin\/sh/ && guest_path == @mock_env.config.vm.rsync_script + end + + @instance.prepare_rsync(@ssh) + end + + should "remove old crontab entries file" do + @ssh.expects(:exec!).with("sudo rm #{@mock_env.config.vm.rsync_crontab_entry_file}") + @instance.prepare_rsync(@ssh) + end + + should "prepare the rsync template for execution" do + @ssh.expects(:exec!).with("sudo chmod +x #{@mock_env.config.vm.rsync_script}") + @instance.prepare_rsync(@ssh) + end + end + + context "setting up an rsync folder" do + setup do + @ssh.stubs(:exec!) + end + + should "create the new rysnc destination directory" do + rsync_path = 'foo' + @ssh.expects(:exec!).with("sudo mkdir -p #{rsync_path}") + @instance.create_rsync(@ssh, :rsyncpath => "foo") + end + + should "add an entry to the crontab file" do + @instance.expects(:render_crontab_entry).returns('foo') + @ssh.expects(:exec!).with do |cmd| + cmd =~ /echo/ && cmd =~ /foo/ && cmd =~ /#{@mock_env.config.vm.rsync_crontab_entry_file}/ + end + @instance.create_rsync(@ssh, {}) + end + + should "use the crontab entry file to define vagrant users cron entries" do + @ssh.expects(:exec!).with("crontab #{@mock_env.config.vm.rsync_crontab_entry_file}") + @instance.create_rsync(@ssh, {}) + end + + should "chown the rsync directory" do + @instance.expects(:chown).with(@ssh, "foo") + @instance.create_rsync(@ssh, :rsyncpath => "foo") + end + end + #------------------------------------------------------------------- # "Private" methods tests #------------------------------------------------------------------- context "mounting the main folder" do setup do - @ssh = mock("ssh") @name = "foo" @guestpath = "bar" @sleeptime = 0