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
|
2013-03-07 05:09:09 +00:00
|
|
|
let(:metadata) { {'template-opts' => {'--foo' => 'bar'}} }
|
2013-03-08 03:54:15 +00:00
|
|
|
let(:box) { mock(:box, name: 'box-name', metadata: metadata, directory: box_directory) }
|
|
|
|
let(:box_directory) { Pathname.new('/path/to/box') }
|
2013-03-02 15:17:04 +00:00
|
|
|
let(:machine) { mock(:machine, box: box) }
|
|
|
|
let(:app) { mock(:app, call: true) }
|
2013-03-11 03:13:48 +00:00
|
|
|
let(:env) { {machine: machine, ui: stub(info: true)} }
|
2013-03-02 15:17:04 +00:00
|
|
|
|
|
|
|
subject { described_class.new(app, env) }
|
|
|
|
|
|
|
|
before do
|
2013-03-08 03:54:15 +00:00
|
|
|
File.stub(exists?: true)
|
2013-03-02 15:17:04 +00:00
|
|
|
subject.stub(:system)
|
|
|
|
subject.call(env)
|
|
|
|
end
|
|
|
|
|
2013-04-05 01:31:09 +00:00
|
|
|
it 'sets the rootfs-tarball path on metadata hash' do
|
|
|
|
metadata['rootfs-tarball'].should == box_directory.join('rootfs.tar.gz')
|
2013-03-02 15:17:04 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'prepends vagrant and box name to template-name' do
|
2013-03-07 05:09:09 +00:00
|
|
|
metadata['template-name'].should == "vagrant-#{box.name}"
|
2013-03-02 15:17:04 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'copies box template file to the right folder' do
|
2013-03-08 03:54:15 +00:00
|
|
|
src = box_directory.join('lxc-template').to_s
|
2013-03-02 15:17:04 +00:00
|
|
|
dest = "/usr/share/lxc/templates/lxc-#{metadata['template-name']}"
|
2013-03-08 03:54:15 +00:00
|
|
|
|
|
|
|
subject.should have_received(:system).
|
|
|
|
with("sudo su root -c \"cp #{src} #{dest}\"")
|
2013-03-02 15:17:04 +00:00
|
|
|
end
|
|
|
|
end
|