diff --git a/README.md b/README.md index 2d11968..494627d 100644 --- a/README.md +++ b/README.md @@ -121,7 +121,7 @@ list if you have a problem and feel free to use the [issue tracker](https://gith propose new functionality and / or report bugs. -## Donating +## Support Support this project and [others by fgrehm](https://github.com/fgrehm) via [gittip](https://www.gittip.com/fgrehm/). diff --git a/spec/Vagrantfile b/spec/Vagrantfile index 8edea4a..9b35550 100644 --- a/spec/Vagrantfile +++ b/spec/Vagrantfile @@ -5,22 +5,26 @@ Vagrant.require_plugin 'vagrant-lxc' Vagrant.require_plugin 'vagrant-cachier' ENV['BOX_NAME'] ||= 'quantal64' -puts "Running specs using #{ENV['BOX_NAME']} box" +puts "Running vagrant commands using #{ENV['BOX_NAME']} box" Vagrant.configure("2") do |config| config.vm.box = ENV['BOX_NAME'] config.vm.hostname = 'lxc-test-box' + config.vm.box_url = ENV['BOX_URL'] config.vm.network :forwarded_port, guest: 80, host: 8080 config.cache.auto_detect = true config.vm.provider :lxc do |lxc| - lxc.sudo_wrapper = '/usr/bin/lxc-vagrant-wrapper' + # lxc.sudo_wrapper = '/usr/bin/lxc-vagrant-wrapper' end config.vm.provision :shell, inline: 'mkdir -p /vagrant/tmp && echo -n "Provisioned" > /vagrant/tmp/provisioning' config.vm.provision :shell, - inline: 'sudo apt-get install apache2 -y' + inline: 'apt-get install apache2 -y' + + config.vm.provision :shell, privileged: false, + inline: "if ! [ -f $HOME/original-box ]; then echo '#{ENV['BOX_NAME']}' > $HOME/original-box; fi" end diff --git a/spec/acceptance/sanity_check_spec.rb b/spec/acceptance/sanity_check_spec.rb index 77b07b0..c3c4d97 100644 --- a/spec/acceptance/sanity_check_spec.rb +++ b/spec/acceptance/sanity_check_spec.rb @@ -48,7 +48,7 @@ describe 'Sanity check' do vagrant_halt end - it 'shuts down container' do + it 'shuts down the container' do status = `sudo lxc-info -n #{vagrant_container_name}` expect(status).to include 'STOPPED' end @@ -63,9 +63,10 @@ describe 'Sanity check' do expect($?.exitstatus).to_not eq 0 end - it 'removes files under `/tmp`' do - container_tmp = Pathname("/var/lib/lxc/#{vagrant_container_name}/rootfs/tmp") - expect(container_tmp.entries).to have(2).items # basically '.' and '..' + xit 'removes files under `/tmp`' do + container_tmp_files = `sudo ls -l "/var/lib/lxc/#{vagrant_container_name}/rootfs/tmp"`.split("\n") + puts container_tmp_files.join("\n") + expect(container_tmp_files).to be_empty end end @@ -82,4 +83,29 @@ describe 'Sanity check' do expect(containers).to_not include @container_name end end + + pending 'box packaging' do + before(:all) do + destroy_container + vagrant_box_remove('new-box') + vagrant_up + vagrant_package + @box_name = ENV['BOX_NAME'] + # This will make + ENV["BOX_NAME"] = 'new-box' + ENV['BOX_URL'] = '/vagrant/spec/tmp/package.box' + end + + after(:all) do + vagrant_box_remove('new-box') + ENV["BOX_NAME"] = @box_name + ENV['BOX_URL'] = nil + end + + it 'creates a package that can be successfully brought up on a later `vagrant up`' do + vagrant_up + # Just to make sure we packaged it properly + expect(vagrant_ssh('cat /home/vagrant/original-box')).to eq @box_name + end + end end diff --git a/spec/acceptance/support/acceptance_example_group.rb b/spec/acceptance/support/acceptance_example_group.rb index e363839..7042117 100644 --- a/spec/acceptance/support/acceptance_example_group.rb +++ b/spec/acceptance/support/acceptance_example_group.rb @@ -13,12 +13,13 @@ module AcceptanceExampleGroup `sudo lxc-shutdown -n #{name} 2>/dev/null` `sudo lxc-wait -n #{name} --state STOPPED 2>/dev/null` `sudo lxc-destroy -n #{name} 2>/dev/null` + `rm -rf /vagrant/spec/.vagrant/` end `sudo killall -9 redir 2>/dev/null` end def with_vagrant_environment - opts = { cwd: 'spec', ui_class: TestUI } + opts = { cwd: '/vagrant/spec', ui_class: TestUI } env = Vagrant::Environment.new(opts) yield env env.unload @@ -53,4 +54,23 @@ module AcceptanceExampleGroup end output end + + def vagrant_package + with_vagrant_environment do |env| + pkg = '/vagrant/spec/tmp/package.box' + `rm -f #{pkg}` + env.cli('package', '--output', pkg) + end + end + + def vagrant_box_remove(name) + with_vagrant_environment do |env| + env.cli('box', 'list') + output = env.ui.messages[:info].join("\n").chomp + + if output.include?(name) + env.cli('box', 'remove', name) + end + end + end end diff --git a/spec/acceptance/support/machine_ext.rb b/spec/acceptance/support/machine_ext.rb index d09fcff..9b28a61 100644 --- a/spec/acceptance/support/machine_ext.rb +++ b/spec/acceptance/support/machine_ext.rb @@ -1,13 +1,12 @@ # Monkey patch vagrant in order to reuse the UI test object that is set on # our Vagrant::Environments # -# TODO: Find out if this makes sense to be on vagrant core itself require 'vagrant/machine' Vagrant::Machine.class_eval do alias :old_action :action - define_method :action do |name, extra_env = nil| + define_method :action do |action_name, extra_env = nil| extra_env = { ui: @env.ui }.merge(extra_env || {}) - old_action name, extra_env + old_action action_name, extra_env end end diff --git a/spec/acceptance/support/test_ui.rb b/spec/acceptance/support/test_ui.rb index bd70d0c..9fc1ff6 100644 --- a/spec/acceptance/support/test_ui.rb +++ b/spec/acceptance/support/test_ui.rb @@ -15,8 +15,8 @@ class TestUI < Vagrant::UI::Interface end METHODS.each do |method| - define_method(method) do |message, *opts| - @messages[method].push message + define_method(method) do |*args|#message, *opts| + @messages[method].push args[0] end end end