Checking if a box already exists at the checking middleware

This commit is contained in:
Vitor Pellegrino 2010-07-19 12:18:40 -03:00 committed by Mitchell Hashimoto
parent 0c5c938250
commit 23296093b1
2 changed files with 46 additions and 0 deletions

View File

@ -0,0 +1,21 @@
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 @@
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