Couple of tweaks to acceptance specs
This will be eventually converted to Bats...
This commit is contained in:
parent
1c5c73b08a
commit
02f85e4e59
6 changed files with 63 additions and 14 deletions
|
@ -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.
|
propose new functionality and / or report bugs.
|
||||||
|
|
||||||
|
|
||||||
## Donating
|
## Support
|
||||||
|
|
||||||
Support this project and [others by fgrehm](https://github.com/fgrehm)
|
Support this project and [others by fgrehm](https://github.com/fgrehm)
|
||||||
via [gittip](https://www.gittip.com/fgrehm/).
|
via [gittip](https://www.gittip.com/fgrehm/).
|
||||||
|
|
10
spec/Vagrantfile
vendored
10
spec/Vagrantfile
vendored
|
@ -5,22 +5,26 @@ Vagrant.require_plugin 'vagrant-lxc'
|
||||||
Vagrant.require_plugin 'vagrant-cachier'
|
Vagrant.require_plugin 'vagrant-cachier'
|
||||||
|
|
||||||
ENV['BOX_NAME'] ||= 'quantal64'
|
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|
|
Vagrant.configure("2") do |config|
|
||||||
config.vm.box = ENV['BOX_NAME']
|
config.vm.box = ENV['BOX_NAME']
|
||||||
config.vm.hostname = 'lxc-test-box'
|
config.vm.hostname = 'lxc-test-box'
|
||||||
|
config.vm.box_url = ENV['BOX_URL']
|
||||||
config.vm.network :forwarded_port, guest: 80, host: 8080
|
config.vm.network :forwarded_port, guest: 80, host: 8080
|
||||||
|
|
||||||
config.cache.auto_detect = true
|
config.cache.auto_detect = true
|
||||||
|
|
||||||
config.vm.provider :lxc do |lxc|
|
config.vm.provider :lxc do |lxc|
|
||||||
lxc.sudo_wrapper = '/usr/bin/lxc-vagrant-wrapper'
|
# lxc.sudo_wrapper = '/usr/bin/lxc-vagrant-wrapper'
|
||||||
end
|
end
|
||||||
|
|
||||||
config.vm.provision :shell,
|
config.vm.provision :shell,
|
||||||
inline: 'mkdir -p /vagrant/tmp && echo -n "Provisioned" > /vagrant/tmp/provisioning'
|
inline: 'mkdir -p /vagrant/tmp && echo -n "Provisioned" > /vagrant/tmp/provisioning'
|
||||||
|
|
||||||
config.vm.provision :shell,
|
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
|
end
|
||||||
|
|
|
@ -48,7 +48,7 @@ describe 'Sanity check' do
|
||||||
vagrant_halt
|
vagrant_halt
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'shuts down container' do
|
it 'shuts down the container' do
|
||||||
status = `sudo lxc-info -n #{vagrant_container_name}`
|
status = `sudo lxc-info -n #{vagrant_container_name}`
|
||||||
expect(status).to include 'STOPPED'
|
expect(status).to include 'STOPPED'
|
||||||
end
|
end
|
||||||
|
@ -63,9 +63,10 @@ describe 'Sanity check' do
|
||||||
expect($?.exitstatus).to_not eq 0
|
expect($?.exitstatus).to_not eq 0
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'removes files under `/tmp`' do
|
xit 'removes files under `/tmp`' do
|
||||||
container_tmp = Pathname("/var/lib/lxc/#{vagrant_container_name}/rootfs/tmp")
|
container_tmp_files = `sudo ls -l "/var/lib/lxc/#{vagrant_container_name}/rootfs/tmp"`.split("\n")
|
||||||
expect(container_tmp.entries).to have(2).items # basically '.' and '..'
|
puts container_tmp_files.join("\n")
|
||||||
|
expect(container_tmp_files).to be_empty
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -82,4 +83,29 @@ describe 'Sanity check' do
|
||||||
expect(containers).to_not include @container_name
|
expect(containers).to_not include @container_name
|
||||||
end
|
end
|
||||||
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
|
end
|
||||||
|
|
|
@ -13,12 +13,13 @@ module AcceptanceExampleGroup
|
||||||
`sudo lxc-shutdown -n #{name} 2>/dev/null`
|
`sudo lxc-shutdown -n #{name} 2>/dev/null`
|
||||||
`sudo lxc-wait -n #{name} --state STOPPED 2>/dev/null`
|
`sudo lxc-wait -n #{name} --state STOPPED 2>/dev/null`
|
||||||
`sudo lxc-destroy -n #{name} 2>/dev/null`
|
`sudo lxc-destroy -n #{name} 2>/dev/null`
|
||||||
|
`rm -rf /vagrant/spec/.vagrant/`
|
||||||
end
|
end
|
||||||
`sudo killall -9 redir 2>/dev/null`
|
`sudo killall -9 redir 2>/dev/null`
|
||||||
end
|
end
|
||||||
|
|
||||||
def with_vagrant_environment
|
def with_vagrant_environment
|
||||||
opts = { cwd: 'spec', ui_class: TestUI }
|
opts = { cwd: '/vagrant/spec', ui_class: TestUI }
|
||||||
env = Vagrant::Environment.new(opts)
|
env = Vagrant::Environment.new(opts)
|
||||||
yield env
|
yield env
|
||||||
env.unload
|
env.unload
|
||||||
|
@ -53,4 +54,23 @@ module AcceptanceExampleGroup
|
||||||
end
|
end
|
||||||
output
|
output
|
||||||
end
|
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
|
end
|
||||||
|
|
|
@ -1,13 +1,12 @@
|
||||||
# Monkey patch vagrant in order to reuse the UI test object that is set on
|
# Monkey patch vagrant in order to reuse the UI test object that is set on
|
||||||
# our Vagrant::Environments
|
# our Vagrant::Environments
|
||||||
#
|
#
|
||||||
# TODO: Find out if this makes sense to be on vagrant core itself
|
|
||||||
require 'vagrant/machine'
|
require 'vagrant/machine'
|
||||||
Vagrant::Machine.class_eval do
|
Vagrant::Machine.class_eval do
|
||||||
alias :old_action :action
|
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 || {})
|
extra_env = { ui: @env.ui }.merge(extra_env || {})
|
||||||
old_action name, extra_env
|
old_action action_name, extra_env
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -15,8 +15,8 @@ class TestUI < Vagrant::UI::Interface
|
||||||
end
|
end
|
||||||
|
|
||||||
METHODS.each do |method|
|
METHODS.each do |method|
|
||||||
define_method(method) do |message, *opts|
|
define_method(method) do |*args|#message, *opts|
|
||||||
@messages[method].push message
|
@messages[method].push args[0]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue