2013-03-02 15:17:04 +00:00
|
|
|
require 'unit_helper'
|
|
|
|
|
2013-03-03 05:24:05 +00:00
|
|
|
require 'vagrant-lxc/action/base_action'
|
2013-03-02 15:17:04 +00:00
|
|
|
require 'vagrant-lxc/action/handle_box_metadata'
|
|
|
|
|
|
|
|
describe Vagrant::LXC::Action::HandleBoxMetadata do
|
|
|
|
let(:tar_cache) { 'template.zip' }
|
|
|
|
let(:template_name) { 'ubuntu-lts' }
|
2013-03-02 19:39:49 +00:00
|
|
|
let(:after_create) { 'setup-vagrant-user.sh' }
|
|
|
|
let(:metadata) { {'template-name' => template_name, 'tar-cache' => tar_cache, 'after-create-script' => after_create} }
|
2013-03-02 15:17:04 +00:00
|
|
|
let(:box) { mock(:box, name: 'box-name', metadata: metadata, directory: Pathname.new('/path/to/box')) }
|
|
|
|
let(:machine) { mock(:machine, box: box) }
|
|
|
|
let(:app) { mock(:app, call: true) }
|
|
|
|
let(:env) { {machine: machine} }
|
|
|
|
|
|
|
|
subject { described_class.new(app, env) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
subject.stub(:system)
|
|
|
|
subject.call(env)
|
|
|
|
end
|
|
|
|
|
2013-03-03 02:12:26 +00:00
|
|
|
it 'sets box directory as lxc-cache-path' do
|
|
|
|
metadata['lxc-cache-path'].should == box.directory.to_s
|
2013-03-02 15:17:04 +00:00
|
|
|
end
|
|
|
|
|
2013-03-02 19:39:49 +00:00
|
|
|
it 'prepends box directory to after-create-script' do
|
|
|
|
metadata['after-create-script'].should == "#{box.directory.to_s}/#{after_create}"
|
|
|
|
end
|
|
|
|
|
2013-03-02 15:17:04 +00:00
|
|
|
it 'prepends vagrant and box name to template-name' do
|
|
|
|
metadata['template-name'].should == "vagrant-#{box.name}-#{template_name}"
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'copies box template file to the right folder' do
|
|
|
|
src = box.directory.join(template_name).to_s
|
|
|
|
dest = "/usr/share/lxc/templates/lxc-#{metadata['template-name']}"
|
|
|
|
subject.should have_received(:system).with("sudo su root -c \"cp #{src} #{dest}\"")
|
|
|
|
end
|
|
|
|
end
|