Prepends box directory to after-create-script defined on box metadata

This commit is contained in:
Fabio Rehm 2013-03-02 16:39:49 -03:00
parent 10655d4c30
commit a9acde7da1
2 changed files with 13 additions and 3 deletions

View file

@ -17,9 +17,14 @@ module Vagrant
metadata = box.metadata metadata = box.metadata
template_name = metadata['template-name'] template_name = metadata['template-name']
after_create = metadata['after-create-script'] ?
box.directory.join(metadata['after-create-script']).to_s :
nil
metadata.merge!( metadata.merge!(
'template-name' => "vagrant-#{box.name}-#{template_name}", 'template-name' => "vagrant-#{box.name}-#{template_name}",
'tar-cache' => box.directory.join(metadata['tar-cache']).to_s 'tar-cache' => box.directory.join(metadata['tar-cache']).to_s,
'after-create-script' => after_create
) )
# Prepends "lxc-" to the template file so that `lxc-create` is able to find it # Prepends "lxc-" to the template file so that `lxc-create` is able to find it

View file

@ -5,7 +5,8 @@ require 'vagrant-lxc/action/handle_box_metadata'
describe Vagrant::LXC::Action::HandleBoxMetadata do describe Vagrant::LXC::Action::HandleBoxMetadata do
let(:tar_cache) { 'template.zip' } let(:tar_cache) { 'template.zip' }
let(:template_name) { 'ubuntu-lts' } let(:template_name) { 'ubuntu-lts' }
let(:metadata) { {'template-name' => template_name, 'tar-cache' => tar_cache} } let(:after_create) { 'setup-vagrant-user.sh' }
let(:metadata) { {'template-name' => template_name, 'tar-cache' => tar_cache, 'after-create-script' => after_create} }
let(:box) { mock(:box, name: 'box-name', metadata: metadata, directory: Pathname.new('/path/to/box')) } let(:box) { mock(:box, name: 'box-name', metadata: metadata, directory: Pathname.new('/path/to/box')) }
let(:machine) { mock(:machine, box: box) } let(:machine) { mock(:machine, box: box) }
let(:app) { mock(:app, call: true) } let(:app) { mock(:app, call: true) }
@ -22,6 +23,10 @@ describe Vagrant::LXC::Action::HandleBoxMetadata do
metadata['tar-cache'].should == "#{box.directory.to_s}/#{tar_cache}" metadata['tar-cache'].should == "#{box.directory.to_s}/#{tar_cache}"
end end
it 'prepends box directory to after-create-script' do
metadata['after-create-script'].should == "#{box.directory.to_s}/#{after_create}"
end
it 'prepends vagrant and box name to template-name' do it 'prepends vagrant and box name to template-name' do
metadata['template-name'].should == "vagrant-#{box.name}-#{template_name}" metadata['template-name'].should == "vagrant-#{box.name}-#{template_name}"
end end