Add CheckBox to up command and make the typical require_box checks

This commit is contained in:
Mitchell Hashimoto 2010-07-23 22:06:17 -07:00
parent 23296093b1
commit 4ec6196b3b
7 changed files with 62 additions and 49 deletions

View File

@ -62,6 +62,7 @@ module Vagrant
# up - Imports, prepares, then starts a fresh VM.
up = Builder.new do
use VM::CheckBox
use VM::Import
use VM::Persist
use VM::MatchMACAddress

View File

@ -1,21 +0,0 @@
module Vagrant
class Action
module VM
class Check
def initialize(app, env)
@app = app
end
def call(env)
box_name = env["config"].vm.box
env.logger.info "Checking if the box '#{box_name}' was already downloaded"
box = Vagrant::Box.find(env.env , box_name)
env.logger.info "The box #{box} were found"
@app.call(env)
end
end
end
end
end

View File

@ -0,0 +1,25 @@
module Vagrant
class Action
module VM
class CheckBox
def initialize(app, env)
@app = app
end
def call(env)
box_name = env["config"].vm.box
return env.error!(:box_not_specified) if !box_name
if !Vagrant::Box.find(env.env , box_name)
box_url = env["config"].vm.box_url
return env.error!(:box_specified_doesnt_exist, :box_name => box_name) if !box_url
env.logger.info "Box #{box_name} not found. Fetching box since URL specified..."
end
@app.call(env)
end
end
end
end
end

View File

@ -23,8 +23,6 @@ module Vagrant
vm.env.logger.info "VM '#{name}' already created. Booting if its not already running..."
vm.start
else
vm.env.require_box
vm.env.logger.info "Creating VM '#{name}'"
vm.up
end

View File

@ -0,0 +1,36 @@
require File.join(File.dirname(__FILE__), '..', '..', '..', 'test_helper')
class CheckBoxVMActionTest < Test::Unit::TestCase
setup do
@klass = Vagrant::Action::VM::CheckBox
@app, @env = mock_action_data
@instance = @klass.new(@app, @env)
end
context "calling" do
setup do
Vagrant::Box.stubs(:find)
end
should "return error if box not specified" do
@env.env.config.vm.box = nil
@app.expects(:call).never
@instance.call(@env)
assert @env.error?
assert_equal :box_not_specified, @env.error.first
end
should "error if box does not exist and URL not specified" do
@env.env.config.vm.box_url = nil
Vagrant::Box.expects(:find).with(@env.env, @env["config"].vm.box).returns(nil)
@app.expects(:call).never
@instance.call(@env)
assert @env.error?
assert_equal :box_specified_doesnt_exist, @env.error.first
end
end
end

View File

@ -1,25 +0,0 @@
require File.join(File.dirname(__FILE__), '..', '..', '..', 'test_helper')
class CheckVMActionTest < Test::Unit::TestCase
setup do
@klass = Vagrant::Action::VM::Check
@app, @env = mock_action_data
@instance = @klass.new(@app, @env)
@env['config'].vm.box = "foo"
end
should "check if the box exist" do
Vagrant::Box.expects("find").with(@env.env, 'foo')
@instance.call(@env)
end
should 'continue the chain process' do
Vagrant::Box.stubs('find').with(@env.env, 'foo')
@app.expects(:call).with(@env).once
@instance.call(@env)
end
end

View File

@ -38,7 +38,6 @@ class CommandsUpTest < Test::Unit::TestCase
should "up non-created VMs" do
@vm.stubs(:created?).returns(false)
@vm.env.expects(:require_box).once
@vm.expects(:up).once
@vm.expects(:start).never
@instance.up_single(:foo)