system testing
This commit is contained in:
parent
ce6d95c131
commit
007ecc5f1c
|
@ -57,16 +57,16 @@ module Vagrant
|
||||||
:scriptname => config.vm.rsync_script))
|
:scriptname => config.vm.rsync_script))
|
||||||
|
|
||||||
ssh.exec!("sudo mkdir -p #{opts[:rsyncpath]}")
|
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!("sudo echo \"#{crontab_entry}\" >> #{config.vm.rsync_crontab_entry_file}")
|
||||||
ssh.exec!("crontab #{config.vm.rsync_crontab_entry_file}")
|
ssh.exec!("crontab #{config.vm.rsync_crontab_entry_file}")
|
||||||
chown(ssh, opts[:rsyncpath])
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def prepare_rsync(ssh)
|
def prepare_rsync(ssh)
|
||||||
logger.info "Preparing system for rsync..."
|
logger.info "Preparing system for rsync..."
|
||||||
vm.env.ssh.upload!(StringIO.new(render_rsync), config.vm.rsync_script)
|
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
|
end
|
||||||
|
|
||||||
#-------------------------------------------------------------------
|
#-------------------------------------------------------------------
|
||||||
|
|
|
@ -43,6 +43,8 @@ class Test::Unit::TestCase
|
||||||
config.vm.shared_folder_uid = nil
|
config.vm.shared_folder_uid = nil
|
||||||
config.vm.shared_folder_gid = nil
|
config.vm.shared_folder_gid = nil
|
||||||
config.vm.system = :linux
|
config.vm.system = :linux
|
||||||
|
config.vm.rsync_script = "/foo"
|
||||||
|
config.vm.rsync_crontab_entry_file = "/tmp/foo"
|
||||||
|
|
||||||
config.package.name = 'vagrant'
|
config.package.name = 'vagrant'
|
||||||
config.package.extension = '.box'
|
config.package.extension = '.box'
|
||||||
|
|
|
@ -129,7 +129,7 @@ class SharedFoldersActionTest < Test::Unit::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
context "with rsyncd folders" do
|
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
|
should "prepare the system for rsync if necessary" do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -3,15 +3,16 @@ require File.join(File.dirname(__FILE__), '..', '..', 'test_helper')
|
||||||
class LinuxSystemTest < Test::Unit::TestCase
|
class LinuxSystemTest < Test::Unit::TestCase
|
||||||
setup do
|
setup do
|
||||||
@klass = Vagrant::Systems::Linux
|
@klass = Vagrant::Systems::Linux
|
||||||
|
@ssh = mock("ssh")
|
||||||
@vm = mock_vm
|
@mock_env = mock_environment
|
||||||
|
@vm = mock("vm")
|
||||||
|
@vm.stubs(:env).returns(@mock_env)
|
||||||
@instance = @klass.new(@vm)
|
@instance = @klass.new(@vm)
|
||||||
end
|
end
|
||||||
|
|
||||||
context "halting" do
|
context "halting" do
|
||||||
setup do
|
setup do
|
||||||
@ssh_session = mock("ssh_session")
|
@ssh_session = mock("ssh_session")
|
||||||
@ssh = mock("ssh")
|
|
||||||
@ssh.stubs(:execute).yields(@ssh_session)
|
@ssh.stubs(:execute).yields(@ssh_session)
|
||||||
@vm.stubs(:ssh).returns(@ssh)
|
@vm.stubs(:ssh).returns(@ssh)
|
||||||
|
|
||||||
|
@ -28,7 +29,6 @@ class LinuxSystemTest < Test::Unit::TestCase
|
||||||
|
|
||||||
context "mounting shared folders" do
|
context "mounting shared folders" do
|
||||||
setup do
|
setup do
|
||||||
@ssh = mock("ssh")
|
|
||||||
@name = "foo"
|
@name = "foo"
|
||||||
@guestpath = "/bar"
|
@guestpath = "/bar"
|
||||||
end
|
end
|
||||||
|
@ -43,12 +43,67 @@ class LinuxSystemTest < Test::Unit::TestCase
|
||||||
end
|
end
|
||||||
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
|
# "Private" methods tests
|
||||||
#-------------------------------------------------------------------
|
#-------------------------------------------------------------------
|
||||||
context "mounting the main folder" do
|
context "mounting the main folder" do
|
||||||
setup do
|
setup do
|
||||||
@ssh = mock("ssh")
|
|
||||||
@name = "foo"
|
@name = "foo"
|
||||||
@guestpath = "bar"
|
@guestpath = "bar"
|
||||||
@sleeptime = 0
|
@sleeptime = 0
|
||||||
|
|
Loading…
Reference in New Issue