From 567ede7db619bd4a22f7d4ebc260339e3babd5c3 Mon Sep 17 00:00:00 2001 From: Fabio Rehm Date: Sun, 10 Mar 2013 19:22:58 -0300 Subject: [PATCH] Begin to make use of CLI from LXC::Container --- lib/vagrant-lxc/container.rb | 10 ++++++---- spec/unit/container_spec.rb | 10 +++------- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/lib/vagrant-lxc/container.rb b/lib/vagrant-lxc/container.rb index 3dfb3b6..6fbeb97 100644 --- a/lib/vagrant-lxc/container.rb +++ b/lib/vagrant-lxc/container.rb @@ -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 diff --git a/spec/unit/container_spec.rb b/spec/unit/container_spec.rb index fd6428a..9707cfb 100644 --- a/spec/unit/container_spec.rb +++ b/spec/unit/container_spec.rb @@ -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 {