From 8512c5ace776d0e9b429eaec1ba26562b866e640 Mon Sep 17 00:00:00 2001 From: Fabio Rehm Date: Sat, 8 Jun 2013 02:07:56 -0300 Subject: [PATCH] Prevent `vagrant package` from blowing up --- lib/vagrant-lxc/action/setup_package_files.rb | 4 +- spec/unit/action/setup_package_files_spec.rb | 39 ++++++++++++------- 2 files changed, 29 insertions(+), 14 deletions(-) diff --git a/lib/vagrant-lxc/action/setup_package_files.rb b/lib/vagrant-lxc/action/setup_package_files.rb index 652f507..8743861 100644 --- a/lib/vagrant-lxc/action/setup_package_files.rb +++ b/lib/vagrant-lxc/action/setup_package_files.rb @@ -45,7 +45,9 @@ module Vagrant box_dir = @env[:machine].box.directory FileUtils.cp box_dir.join('lxc-template').to_s, @env['package.directory'].to_s FileUtils.cp box_dir.join('metadata.json').to_s, @env['package.directory'].to_s - FileUtils.cp box_dir.join('lxc.conf').to_s, @env['package.directory'].to_s + if (conf = box_dir.join('lxc.conf')).exist? + FileUtils.cp conf.to_s, @env['package.directory'].to_s + end end end end diff --git a/spec/unit/action/setup_package_files_spec.rb b/spec/unit/action/setup_package_files_spec.rb index 68d3133..c5a4c7b 100644 --- a/spec/unit/action/setup_package_files_spec.rb +++ b/spec/unit/action/setup_package_files_spec.rb @@ -20,27 +20,40 @@ describe Vagrant::LXC::Action::SetupPackageFiles do end subject.stub(recover: true) # Prevents files from being removed on specs - subject.call(env) end after do FileUtils.rm_rf(tmp_path.to_s) end - it 'copies box lxc-template to package directory' do - env['package.directory'].join('lxc-template').should be_file + context 'when all files exist' do + before { subject.call(env) } + + it 'copies box lxc-template to package directory' do + env['package.directory'].join('lxc-template').should be_file + end + + it 'copies metadata.json to package directory' do + env['package.directory'].join('metadata.json').should be_file + end + + it 'copies box lxc.conf to package directory' do + env['package.directory'].join('lxc-template').should be_file + end + + it 'moves the compressed rootfs to package directory' do + env['package.directory'].join(rootfs_path.basename).should be_file + env['package.rootfs'].should_not be_file + end end - it 'copies metadata.json to package directory' do - env['package.directory'].join('metadata.json').should be_file - end + context 'when lxc.conf file is not present' do + before do + box.directory.join('lxc.conf').delete + end - it 'copies box lxc.conf to package directory' do - env['package.directory'].join('lxc-template').should be_file - end - - it 'moves the compressed rootfs to package directory' do - env['package.directory'].join(rootfs_path.basename).should be_file - env['package.rootfs'].should_not be_file + it 'does not blow up' do + expect { subject.call(env) }.to_not raise_error + end end end