💣 hand made sanity checks (vagrant-spec is coming in!)
This commit is contained in:
parent
320a698f49
commit
36f7daa528
5 changed files with 0 additions and 242 deletions
|
@ -1,111 +0,0 @@
|
|||
require 'acceptance_helper'
|
||||
|
||||
describe 'Sanity check' do
|
||||
after(:all) { destroy_container }
|
||||
|
||||
context 'running `vagrant up` from scratch' do
|
||||
before(:all) do
|
||||
destroy_container
|
||||
vagrant_up
|
||||
end
|
||||
|
||||
it 'creates a container' do
|
||||
containers = `sudo lxc-ls`.chomp.split(/\s+/).uniq
|
||||
expect(containers).to include vagrant_container_name
|
||||
end
|
||||
|
||||
it 'starts the newly created container' do
|
||||
status = `sudo lxc-info -n #{vagrant_container_name}`
|
||||
expect(status).to include 'RUNNING'
|
||||
end
|
||||
|
||||
it "is able to be SSH'ed" do
|
||||
expect(vagrant_ssh('hostname')).to eq 'lxc-test-box'
|
||||
end
|
||||
|
||||
it 'mounts shared folders with the right permissions' do
|
||||
vagrant_ssh 'mkdir -p /vagrant/tmp && echo -n "Shared" > /vagrant/tmp/shared'
|
||||
shared_file_contents = File.read('/vagrant/spec/tmp/shared')
|
||||
expect(shared_file_contents).to eq 'Shared'
|
||||
end
|
||||
|
||||
it 'provisions the container based on Vagrantfile configs' do
|
||||
provisioned_file_contents = File.read('/vagrant/spec/tmp/provisioning')
|
||||
expect(provisioned_file_contents).to eq 'Provisioned'
|
||||
end
|
||||
|
||||
it 'forwards configured ports' do
|
||||
output = `curl -s localhost:8080`.strip.chomp
|
||||
expect(output).to include 'It works!'
|
||||
end
|
||||
end
|
||||
|
||||
context '`vagrant halt` on a running container' do
|
||||
before(:all) do
|
||||
destroy_container
|
||||
vagrant_up
|
||||
vagrant_ssh 'touch /tmp/{some,files}'
|
||||
vagrant_halt
|
||||
end
|
||||
|
||||
it 'shuts down the container' do
|
||||
status = `sudo lxc-info -n #{vagrant_container_name}`
|
||||
expect(status).to include 'STOPPED'
|
||||
end
|
||||
|
||||
it 'clears forwarded ports' do
|
||||
`curl -s localhost:8080 --connect-timeout 2`
|
||||
expect($?.exitstatus).to_not eq 0
|
||||
end
|
||||
|
||||
it 'kills redir processes' do
|
||||
processes = `pgrep redir`
|
||||
expect($?.exitstatus).to_not eq 0
|
||||
end
|
||||
|
||||
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
|
||||
|
||||
context '`vagrant destroy`' do
|
||||
before(:all) do
|
||||
destroy_container
|
||||
vagrant_up
|
||||
@container_name = vagrant_container_name
|
||||
vagrant_destroy
|
||||
end
|
||||
|
||||
it 'destroys the underlying container' do
|
||||
containers = `sudo lxc-ls`.chomp.split(/\s+/).uniq
|
||||
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
|
|
@ -1,76 +0,0 @@
|
|||
module AcceptanceExampleGroup
|
||||
def self.included(base)
|
||||
base.metadata[:type] = :acceptance
|
||||
end
|
||||
|
||||
ID_FILE = "/vagrant/spec/.vagrant/machines/default/lxc/id"
|
||||
def vagrant_container_name
|
||||
File.read(ID_FILE).strip.chomp if File.exists?(ID_FILE)
|
||||
end
|
||||
|
||||
def destroy_container
|
||||
if name = vagrant_container_name
|
||||
`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: '/vagrant/spec', ui_class: TestUI }
|
||||
env = Vagrant::Environment.new(opts)
|
||||
yield env
|
||||
env.unload
|
||||
end
|
||||
|
||||
def vagrant_up
|
||||
with_vagrant_environment do |env|
|
||||
env.cli('up', '--provider', 'lxc')
|
||||
end
|
||||
end
|
||||
|
||||
def vagrant_halt
|
||||
with_vagrant_environment do |env|
|
||||
env.cli('halt')
|
||||
end
|
||||
end
|
||||
|
||||
def vagrant_destroy
|
||||
with_vagrant_environment do |env|
|
||||
env.cli('destroy', '-f')
|
||||
end
|
||||
end
|
||||
|
||||
def vagrant_ssh(cmd)
|
||||
output = nil
|
||||
with_vagrant_environment do |env|
|
||||
result = env.cli('ssh', '-c', cmd)
|
||||
if result.to_i != 0
|
||||
raise "SSH command failed: '#{cmd}'\n#{env.ui.messages.inspect}"
|
||||
end
|
||||
output = env.ui.messages[:info].join("\n").chomp
|
||||
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
|
|
@ -1,12 +0,0 @@
|
|||
# Monkey patch vagrant in order to reuse the UI test object that is set on
|
||||
# our Vagrant::Environments
|
||||
#
|
||||
require 'vagrant/machine'
|
||||
Vagrant::Machine.class_eval do
|
||||
alias :old_action :action
|
||||
|
||||
define_method :action do |action_name, extra_env = nil|
|
||||
extra_env = { ui: @env.ui }.merge(extra_env || {})
|
||||
old_action action_name, extra_env
|
||||
end
|
||||
end
|
|
@ -1,22 +0,0 @@
|
|||
class TestUI < Vagrant::UI::Interface
|
||||
attr_reader :messages
|
||||
|
||||
METHODS = [:clear_line, :report_progress, :warn, :error, :info, :success]
|
||||
|
||||
def initialize
|
||||
super
|
||||
@messages = METHODS.each_with_object({}) { |m, h| h[m] = [] }
|
||||
end
|
||||
|
||||
def ask(*args)
|
||||
super
|
||||
# Automated tests should not depend on user input, obviously.
|
||||
raise Errors::UIExpectsTTY
|
||||
end
|
||||
|
||||
METHODS.each do |method|
|
||||
define_method(method) do |*args|#message, *opts|
|
||||
@messages[method].push args[0]
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,21 +0,0 @@
|
|||
require 'spec_helper'
|
||||
|
||||
unless ENV['USER'] == 'vagrant'
|
||||
puts 'Acceptance specs are supposed to run from one of the vagrant-lxc dev machines'
|
||||
exit 1
|
||||
end
|
||||
|
||||
if defined? SimpleCov
|
||||
SimpleCov.command_name 'acceptance'
|
||||
end
|
||||
|
||||
require 'vagrant'
|
||||
require 'vagrant-lxc'
|
||||
|
||||
Dir[File.dirname(__FILE__) + "/acceptance/support/**/*.rb"].each { |f| require f }
|
||||
|
||||
RSpec.configure do |config|
|
||||
config.include AcceptanceExampleGroup, :type => :acceptance, :example_group => {
|
||||
:file_path => /\bspec\/acceptance\//
|
||||
}
|
||||
end
|
Loading…
Reference in a new issue