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 for execution' do
|
|
|
|
args[0].should == 'sudo'
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'uses the first argument as lxc command suffix' do
|
|
|
|
args[1].should == 'lxc-command'
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'sends remaining arguments for execution' do
|
|
|
|
args[2].should == '--state'
|
|
|
|
args[3].should == 'RUNNING'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-03-01 23:45:13 +00:00
|
|
|
describe 'create' do
|
|
|
|
let(:last_command) { @last_command }
|
|
|
|
let(:new_machine_id) { 'random-machine-id' }
|
|
|
|
|
|
|
|
before do
|
2013-03-02 01:47:02 +00:00
|
|
|
subject.stub(:lxc) do |*cmds|
|
2013-03-01 23:45:13 +00:00
|
|
|
@last_command = cmds.join(' ')
|
|
|
|
mock(exit_code: 0, stdout: '')
|
|
|
|
end
|
|
|
|
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
|
|
|
|
last_command.should =~ /^create/
|
|
|
|
last_command.should include "--name #{new_machine_id}"
|
|
|
|
last_command.should include "--template ubuntu-cloud"
|
|
|
|
last_command.should =~ /\-\- \-S (\w|\/|\.)+\/id_rsa\.pub$/
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'start' do
|
|
|
|
let(:last_command) { @last_command }
|
|
|
|
let(:machine_id) { 'random-machine-id' }
|
|
|
|
let(:machine) { fire_double('Vagrant::Machine', id: machine_id) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
subject.stub(:lxc) do |*cmds|
|
|
|
|
@last_command = cmds.join(' ')
|
|
|
|
mock(exit_code: 0, stdout: '')
|
|
|
|
end
|
|
|
|
subject.start
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'calls lxc-start with the right arguments' do
|
|
|
|
last_command.should =~ /^start/
|
|
|
|
last_command.should include "--name #{machine_id}"
|
|
|
|
last_command.should include '-d'
|
2013-03-01 23:45:13 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|