System `prepare_unison` method + tests
This commit is contained in:
parent
5f0695f776
commit
67ab68df89
|
@ -20,6 +20,16 @@ module Vagrant
|
|||
end
|
||||
end
|
||||
|
||||
# This method returns the list of shared folders which are to
|
||||
# be synced via unison.
|
||||
def unison_folders
|
||||
shared_folders.inject({}) do |acc, data|
|
||||
key, value = data
|
||||
acc[key] = value if !!value[:sync]
|
||||
acc
|
||||
end
|
||||
end
|
||||
|
||||
def before_boot
|
||||
clear_shared_folders
|
||||
create_metadata
|
||||
|
@ -42,6 +52,8 @@ module Vagrant
|
|||
end
|
||||
|
||||
def setup_unison
|
||||
return if unison_folders.empty?
|
||||
|
||||
# TODO
|
||||
end
|
||||
|
||||
|
|
|
@ -55,6 +55,13 @@ module Vagrant
|
|||
# wants the folder mounted.
|
||||
def mount_shared_folder(ssh, name, guestpath); end
|
||||
|
||||
# Prepares the system for unison folder syncing. This is called
|
||||
# once once prior to any `create_unison` calls.
|
||||
def prepare_unison(ssh); end
|
||||
|
||||
# Creates an entry for folder syncing via unison.
|
||||
def create_unison(ssh, options); end
|
||||
|
||||
# Prepares the system for host only networks. This is called
|
||||
# once prior to any `enable_host_only_network` calls.
|
||||
def prepare_host_only_network; end
|
||||
|
|
|
@ -52,21 +52,21 @@ module Vagrant
|
|||
chown(ssh, guestpath)
|
||||
end
|
||||
|
||||
def create_sync(ssh, opts)
|
||||
crontab_entry = render_crontab_entry(opts.merge(:syncopts => config.vm.sync_opts,
|
||||
:scriptname => config.vm.sync_script))
|
||||
# def create_sync(ssh, opts)
|
||||
# crontab_entry = render_crontab_entry(opts.merge(:syncopts => config.vm.sync_opts,
|
||||
# :scriptname => config.vm.sync_script))
|
||||
|
||||
ssh.exec!("sudo mkdir -p #{opts[:syncpath]}")
|
||||
chown(ssh, opts[:syncpath])
|
||||
ssh.exec!("sudo echo \"#{crontab_entry}\" >> #{config.vm.sync_crontab_entry_file}")
|
||||
ssh.exec!("crontab #{config.vm.sync_crontab_entry_file}")
|
||||
end
|
||||
# ssh.exec!("sudo mkdir -p #{opts[:syncpath]}")
|
||||
# chown(ssh, opts[:syncpath])
|
||||
# ssh.exec!("sudo echo \"#{crontab_entry}\" >> #{config.vm.sync_crontab_entry_file}")
|
||||
# ssh.exec!("crontab #{config.vm.sync_crontab_entry_file}")
|
||||
# end
|
||||
|
||||
def prepare_sync(ssh)
|
||||
logger.info "Preparing system for sync..."
|
||||
vm.ssh.upload!(StringIO.new(render_sync), config.vm.sync_script)
|
||||
ssh.exec!("sudo chmod +x #{config.vm.sync_script}")
|
||||
ssh.exec!("sudo rm #{config.vm.sync_crontab_entry_file}", :error_check => false)
|
||||
def prepare_unison(ssh)
|
||||
logger.info "Preparing system for unison sync..."
|
||||
vm.ssh.upload!(StringIO.new(TemplateRenderer.render('/unison/script')), config.unison.script)
|
||||
ssh.exec!("sudo chmod +x #{config.unison.script}")
|
||||
ssh.exec!("sudo rm #{config.unison.crontab_entry_file}", :error_check => false)
|
||||
end
|
||||
|
||||
def prepare_host_only_network
|
||||
|
@ -125,10 +125,6 @@ module Vagrant
|
|||
vm.env.config
|
||||
end
|
||||
|
||||
def render_sync
|
||||
TemplateRenderer.render('sync')
|
||||
end
|
||||
|
||||
def render_crontab_entry(opts)
|
||||
TemplateRenderer.render('crontab_entry', opts)
|
||||
end
|
||||
|
|
|
@ -76,7 +76,7 @@ module Vagrant
|
|||
#
|
||||
# @return [String]
|
||||
def full_template_path
|
||||
File.join(PROJECT_ROOT, 'templates', "#{template}.erb")
|
||||
File.join(PROJECT_ROOT, 'templates', "#{template}.erb").squeeze("/")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -83,6 +83,22 @@ class SharedFoldersActionTest < Test::Unit::TestCase
|
|||
end
|
||||
end
|
||||
|
||||
context "unison shared folders" do
|
||||
setup do
|
||||
@folders = stub_shared_folders do |config|
|
||||
config.vm.share_folder("foo", "bar", "baz", :sync => true)
|
||||
config.vm.share_folder("bar", "foo", "baz")
|
||||
end
|
||||
end
|
||||
|
||||
should "only return the folders marked for syncing" do
|
||||
result = @action.unison_folders
|
||||
assert_equal 1, result.length
|
||||
assert result.has_key?("foo")
|
||||
assert !result.has_key?("bar")
|
||||
end
|
||||
end
|
||||
|
||||
context "clearing shared folders" do
|
||||
setup do
|
||||
@shared_folder = mock("shared_folder")
|
||||
|
@ -146,4 +162,8 @@ class SharedFoldersActionTest < Test::Unit::TestCase
|
|||
@action.mount_shared_folders
|
||||
end
|
||||
end
|
||||
|
||||
context "setting up unison" do
|
||||
|
||||
end
|
||||
end
|
||||
|
|
|
@ -43,65 +43,66 @@ class LinuxSystemTest < Test::Unit::TestCase
|
|||
end
|
||||
end
|
||||
|
||||
context "preparing sync" do
|
||||
context "preparing unison" do
|
||||
setup do
|
||||
@ssh.stubs(:exec!)
|
||||
@ssh.stubs(:upload!)
|
||||
@vm.stubs(:ssh).returns(@ssh)
|
||||
@vm.ssh.stubs(:upload!)
|
||||
end
|
||||
|
||||
should "upload the sync template" do
|
||||
@vm.ssh.expects(:upload!).with do |string_io, guest_path|
|
||||
string_io.string =~ /#!\/bin\/sh/ && guest_path == @mock_env.config.vm.sync_script
|
||||
should "upload the script" do
|
||||
@vm.ssh.expects(:upload!).with do |script, path|
|
||||
assert_equal @mock_env.config.unison.script, path
|
||||
true
|
||||
end
|
||||
|
||||
@instance.prepare_sync(@ssh)
|
||||
@instance.prepare_unison(@ssh)
|
||||
end
|
||||
|
||||
should "remove old crontab entries file" do
|
||||
@ssh.expects(:exec!).with("sudo rm #{@mock_env.config.vm.sync_crontab_entry_file}", :error_check => false)
|
||||
@instance.prepare_sync(@ssh)
|
||||
should "make the script executable" do
|
||||
@ssh.expects(:exec!).with("sudo chmod +x #{@mock_env.config.unison.script}").once
|
||||
@instance.prepare_unison(@ssh)
|
||||
end
|
||||
|
||||
should "prepare the sync template for execution" do
|
||||
@ssh.expects(:exec!).with("sudo chmod +x #{@mock_env.config.vm.sync_script}")
|
||||
@instance.prepare_sync(@ssh)
|
||||
should "remove old crontab entry file" do
|
||||
@ssh.expects(:exec!).with("sudo rm #{@mock_env.config.unison.crontab_entry_file}", :error_check => false).once
|
||||
@instance.prepare_unison(@ssh)
|
||||
end
|
||||
end
|
||||
|
||||
context "setting up an sync folder" do
|
||||
setup do
|
||||
@ssh.stubs(:exec!)
|
||||
end
|
||||
# context "setting up an sync folder" do
|
||||
# setup do
|
||||
# @ssh.stubs(:exec!)
|
||||
# end
|
||||
|
||||
should "create the new rysnc destination directory" do
|
||||
sync_path = 'foo'
|
||||
@ssh.expects(:exec!).with("sudo mkdir -p #{sync_path}")
|
||||
@instance.create_sync(@ssh, :syncpath => "foo")
|
||||
end
|
||||
# should "create the new rysnc destination directory" do
|
||||
# sync_path = 'foo'
|
||||
# @ssh.expects(:exec!).with("sudo mkdir -p #{sync_path}")
|
||||
# @instance.create_sync(@ssh, :syncpath => "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.sync_crontab_entry_file}/
|
||||
end
|
||||
@instance.create_sync(@ssh, {})
|
||||
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.sync_crontab_entry_file}/
|
||||
# end
|
||||
# @instance.create_sync(@ssh, {})
|
||||
# end
|
||||
|
||||
should "use the crontab entry file to define vagrant users cron entries" do
|
||||
@ssh.expects(:exec!).with("crontab #{@mock_env.config.vm.sync_crontab_entry_file}")
|
||||
@instance.create_sync(@ssh, {})
|
||||
end
|
||||
# should "use the crontab entry file to define vagrant users cron entries" do
|
||||
# @ssh.expects(:exec!).with("crontab #{@mock_env.config.vm.sync_crontab_entry_file}")
|
||||
# @instance.create_sync(@ssh, {})
|
||||
# end
|
||||
|
||||
should "chown the sync directory" do
|
||||
@instance.expects(:chown).with(@ssh, "foo")
|
||||
@instance.create_sync(@ssh, :syncpath => "foo")
|
||||
end
|
||||
# should "chown the sync directory" do
|
||||
# @instance.expects(:chown).with(@ssh, "foo")
|
||||
# @instance.create_sync(@ssh, :syncpath => "foo")
|
||||
# end
|
||||
|
||||
should "return provide a formatted crontab entry that runs every minute" do
|
||||
assert @instance.render_crontab_entry({}).include?("* * * * *")
|
||||
end
|
||||
end
|
||||
# should "return provide a formatted crontab entry that runs every minute" do
|
||||
# assert @instance.render_crontab_entry({}).include?("* * * * *")
|
||||
# end
|
||||
# end
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
# "Private" methods tests
|
||||
|
|
|
@ -75,6 +75,12 @@ class TemplateRendererUtilTest < Test::Unit::TestCase
|
|||
result = File.join(PROJECT_ROOT, "templates", "#{@template}.erb")
|
||||
assert_equal result, @r.full_template_path
|
||||
end
|
||||
|
||||
should "remove duplicate path separators" do
|
||||
@r.template = "foo///bar"
|
||||
result = File.join(PROJECT_ROOT, "templates", "foo", "bar.erb")
|
||||
assert_equal result, @r.full_template_path
|
||||
end
|
||||
end
|
||||
|
||||
context "class methods" do
|
||||
|
|
Loading…
Reference in New Issue