Begin to make use of CLI from LXC::Container

This commit is contained in:
Fabio Rehm 2013-03-10 19:22:58 -03:00
parent 811d9a4b29
commit 567ede7db6
2 changed files with 9 additions and 11 deletions

View file

@ -1,11 +1,12 @@
# FIXME: Ruby 1.8 users dont have SecureRandom
require 'securerandom'
require "vagrant-lxc/errors"
require "vagrant-lxc/container/cli"
require "vagrant/util/retryable"
require "vagrant/util/subprocess"
require "vagrant-lxc/errors"
module Vagrant
module LXC
class Container
@ -21,13 +22,14 @@ module Vagrant
attr_reader :name
def initialize(name)
def initialize(name, cli = CLI.new(name))
@name = name
@cli = cli
@logger = Log4r::Logger.new("vagrant::provider::lxc::container")
end
def validate!
raise NotFound if @name && ! lxc(:ls).split("\n").include?(@name)
raise NotFound if @name && ! @cli.list.include?(@name)
end
def base_path

View file

@ -8,14 +8,10 @@ describe Vagrant::LXC::Container do
subject { described_class.new(name) }
describe 'container name validation' do
let(:unknown_container) { described_class.new('unknown') }
let(:valid_container) { described_class.new('valid') }
let(:unknown_container) { described_class.new('unknown', cli) }
let(:valid_container) { described_class.new('valid', cli) }
let(:new_container) { described_class.new(nil) }
before do
unknown_container.stub(lxc: 'valid')
valid_container.stub(lxc: 'valid')
end
let(:cli) { fire_double('Vagrant::LXC::CLI', list: ['valid']) }
it 'raises a NotFound error if an unknown container name gets provided' do
expect {