💣 spike specs

This commit is contained in:
Fabio Rehm 2013-03-02 23:47:54 -03:00
parent e7cfc52391
commit 9150ca56f9
3 changed files with 0 additions and 227 deletions

View file

@ -1,59 +0,0 @@
require 'rubygems'
require 'bundler/setup'
Bundler.require
require 'yaml'
require 'shellwords'
`mkdir -p tmp`
module TestHelpers
def provider_up
`cd tmp && ../lib/provider up -o /vagrant/tmp/logger.log`
end
def destroy_container!
`cd tmp && ../lib/provider destroy -o /vagrant/tmp/logger.log`
`rm -f tmp/config.yml`
end
def restore_rinetd_conf!
`sudo cp /vagrant/cache/rinetd.conf /etc/rinetd.conf`
`sudo service rinetd restart`
end
def configure_box_with(opts)
opts = opts.dup
opts.keys.each do |key|
opts[key.to_s] = opts.delete(key)
end
File.open('./tmp/config.yml', 'w') { |f| f.puts YAML::dump(opts) }
end
def provider_ssh(options)
options = options.map { |opt, val| "-#{opt} #{Shellwords.escape val}" }
options = options.join(' ')
`cd tmp && ../lib/provider ssh #{options}`
end
end
RSpec.configure do |config|
config.treat_symbols_as_metadata_keys_with_true_values = true
config.run_all_when_everything_filtered = true
config.filter_run :focus
config.include TestHelpers
# Run specs in random order to surface order dependencies. If you find an
# order dependency and want to debug it, you can fix the order by providing
# the seed, which is printed after each run.
# --seed 1234
config.order = 'random'
config.after :all do
destroy_container!
restore_rinetd_conf!
end
end

View file

@ -1,20 +0,0 @@
require 'spec_helper'
describe 'vagrant ssh' do
let(:ip) { '10.0.3.100' }
before :all do
destroy_container!
configure_box_with :forwards => [[2222, 22]], :ip => ip
provider_up
end
after :all do
restore_rinetd_conf!
destroy_container!
end
it 'accepts a user argument' do
provider_ssh('c' => 'echo $USER', 'u' => 'ubuntu').should include 'ubuntu'
end
end

View file

@ -1,148 +0,0 @@
require 'spec_helper'
describe 'vagrant up' do
context 'given the machine has not been created yet' do
let(:output) { @output }
let(:containers) { @containers }
let(:users) { File.read '/var/lib/lxc/vagrant-container/rootfs/etc/passwd' }
let(:sudoers) { `sudo cat /var/lib/lxc/vagrant-container/rootfs/etc/sudoers` }
let(:rinetd_conf) { File.read('/etc/rinetd.conf') }
before :all do
destroy_container!
configure_box_with :ip => '10.0.3.121'
@output = provider_up
@containers = `sudo lxc-ls`.split
end
it 'outputs some debugging info' do
output.should =~ /INFO lxc: Creating container.../
output.should =~ /INFO lxc: Container started/
end
it 'creates an lxc container' do
containers.should include 'vagrant-container'
end
it 'sets up the vagrant user with passwordless sudo' do
users.should =~ /vagrant/
sudoers.should =~ /Defaults\s+exempt_group=admin/
sudoers.should =~ /%admin ALL=NOPASSWD:ALL/
end
it 'automagically shares the root folder' do
output.should =~ /Sharing \/vagrant\/tmp as \/vagrant/
end
it 'automagically redirects 2222 port to 22 on guest machine'
end
context 'given the machine was created and is down' do
let(:output) { @output }
let(:info) { @info }
before :all do
destroy_container!
provider_up
`sudo lxc-stop -n vagrant-container`
@output = provider_up
@info = `sudo lxc-info -n vagrant-container`
end
it 'outputs some debugging info' do
output.should =~ /INFO lxc: Container already created, moving on/
output.should =~ /INFO lxc: Container started/
end
it 'starts the container' do
info.should =~ /RUNNING/
end
end
context 'given the machine is up already' do
let(:output) { @output }
let(:containers) { @containers }
before :all do
destroy_container!
provider_up
@output = provider_up
end
it 'outputs some debugging info' do
output.should =~ /INFO lxc: Container already created, moving on/
output.should =~ /INFO lxc: Container already started/
end
end
context 'given an ip was specified' do
let(:ip) { '10.0.3.100' }
let(:output) { @output }
before :all do
destroy_container!
configure_box_with :ip => ip
@output = provider_up
end
it 'sets up container ip' do
`ping -c1 #{ip} > /dev/null && echo -n 'yes'`.should == 'yes'
end
end
context 'given a port was configured to be forwarded' do
let(:ip) { '10.0.3.101' }
let(:output) { @output }
let(:rinetd_conf) { File.read('/etc/rinetd.conf') }
before :all do
destroy_container!
configure_box_with :forwards => [[3333, 33]], :ip => ip
@output = provider_up
end
after :all do
restore_rinetd_conf!
end
it 'ouputs some debugging info' do
output.should =~ /Forwarding ports\.\.\./
output.should =~ /33 => 3333/
output.should =~ /Restarting rinetd/
end
it 'sets configs for rinetd' do
rinetd_conf.should =~ /0\.0\.0\.0\s+3333\s+#{Regexp.escape ip}\s+33/
end
end
context 'given a folder was configured to be shared' do
let(:ip) { '10.0.3.100' }
let(:output) { @output }
before :all do
destroy_container!
configure_box_with({
:ip => ip,
:shared_folders => [
{'source' => '/vagrant', 'destination' => '/tmp/vagrant-all'}
]
})
@output = provider_up
`rm -f /vagrant/tmp/file-from-spec`
end
after :all do
`rm -f /vagrant/tmp/file-from-spec`
end
it 'ouputs some debugging info' do
output.should =~ /Sharing \/vagrant as \/tmp\/vagrant\-all/
end
it 'mounts the folder on the right path' do
`echo 'IT WORKS' > /vagrant/tmp/file-from-spec`
provider_ssh('c' => 'cat /tmp/vagrant-all/tmp/file-from-spec').should include 'IT WORKS'
end
end
end