vagrant-lxc-ng/spec/unit/container_spec.rb

93 lines
2.2 KiB
Ruby
Raw Normal View History

2013-03-01 23:45:13 +00:00
require 'unit_helper'
require 'vagrant-lxc/container'
describe Vagrant::LXC::Container do
2013-03-02 01:47:02 +00:00
# Default subject and machine for specs
2013-03-01 23:45:13 +00:00
let(:machine) { fire_double('Vagrant::Machine') }
subject { described_class.new(machine) }
2013-03-02 01:47:02 +00:00
describe 'lxc commands execution' do
let(:args) { @args }
before do
subject.stub(:execute) { |*args| @args = args }
subject.lxc :command, '--state', 'RUNNING'
end
it 'prepends sudo' do
2013-03-02 01:47:02 +00:00
args[0].should == 'sudo'
end
it 'uses the first argument as lxc command suffix' do
args[1].should == 'lxc-command'
end
2013-03-02 02:07:15 +00:00
it 'pass through remaining arguments' do
2013-03-02 01:47:02 +00:00
args[2].should == '--state'
args[3].should == 'RUNNING'
end
end
2013-03-02 02:07:15 +00:00
describe 'guard for container state' do
let(:machine_id) { 'random-machine-id' }
let(:machine) { fire_double('Vagrant::Machine', id: machine_id) }
before do
2013-03-02 02:27:08 +00:00
subject.stub :lxc
2013-03-02 02:07:15 +00:00
subject.wait_until :running
end
2013-03-02 02:27:08 +00:00
it 'runs lxc-wait with the machine id and upcased state' do
subject.should have_received(:lxc).with(
:wait,
'--name', machine_id,
'--state', 'RUNNING'
)
2013-03-02 02:07:15 +00:00
end
end
describe 'creation' do
2013-03-02 02:27:08 +00:00
let(:new_machine_id) { 'random-machine-id' }
2013-03-02 03:03:48 +00:00
let(:public_key_path) { Vagrant.source_root.join('keys', 'vagrant.pub').expand_path.to_s }
2013-03-01 23:45:13 +00:00
before do
2013-03-02 02:27:08 +00:00
subject.stub(:lxc)
2013-03-01 23:45:13 +00:00
SecureRandom.stub(hex: new_machine_id)
subject.create
end
2013-03-02 01:47:02 +00:00
it 'calls lxc-create with the right arguments' do
2013-03-02 02:27:08 +00:00
subject.should have_received(:lxc).with(
:create,
'--template', 'ubuntu-cloud',
'--name', new_machine_id,
'--',
'-S', public_key_path
)
2013-03-02 01:47:02 +00:00
end
end
describe 'start' do
let(:machine_id) { 'random-machine-id' }
let(:machine) { fire_double('Vagrant::Machine', id: machine_id) }
2013-03-02 01:47:02 +00:00
before do
subject.stub(lxc: true, wait_until: true)
2013-03-02 01:47:02 +00:00
subject.start
end
it 'calls lxc-start with the right arguments' do
2013-03-02 02:27:08 +00:00
subject.should have_received(:lxc).with(
:start,
'-d',
'--name', machine.id
)
end
it 'waits for container state to be RUNNING' do
subject.should have_received(:wait_until).with(:running)
2013-03-01 23:45:13 +00:00
end
end
end