Box destroying middleware
This commit is contained in:
parent
842ddd75b4
commit
5d2e3d9f6f
|
@ -0,0 +1,19 @@
|
|||
module Vagrant
|
||||
class Action
|
||||
module Box
|
||||
class Destroy
|
||||
def initialize(app, env)
|
||||
@app = app
|
||||
@env = env
|
||||
end
|
||||
|
||||
def call(env)
|
||||
env.logger.info "Deleting box directory..."
|
||||
FileUtils.rm_rf(env["box"].directory)
|
||||
|
||||
@app.call(env)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -92,6 +92,13 @@ module Vagrant
|
|||
end
|
||||
|
||||
register :box_add, box_add
|
||||
|
||||
# box_remove - Removes/deletes a box.
|
||||
box_remove = Builder.new do
|
||||
use Box::Destroy
|
||||
end
|
||||
|
||||
register :box_remove, box_remove
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -40,7 +40,7 @@ module Vagrant
|
|||
# box = Vagrant::Box.find("foo")
|
||||
# box.destroy
|
||||
#
|
||||
class Box < Actions::Runner
|
||||
class Box
|
||||
# The name of the box.
|
||||
attr_accessor :name
|
||||
|
||||
|
@ -138,7 +138,7 @@ module Vagrant
|
|||
|
||||
# Beings the process of destroying this box.
|
||||
def destroy
|
||||
execute!(Actions::Box::Destroy)
|
||||
env.actions.run(:box_remove, { "box" => self })
|
||||
end
|
||||
|
||||
# Returns the directory to the location of this boxes content in the local
|
||||
|
|
|
@ -0,0 +1,30 @@
|
|||
require File.join(File.dirname(__FILE__), '..', '..', '..', 'test_helper')
|
||||
|
||||
class DestroyBoxActionTest < Test::Unit::TestCase
|
||||
setup do
|
||||
@klass = Vagrant::Action::Box::Destroy
|
||||
@app, @env = mock_action_data
|
||||
|
||||
@vm = mock("vm")
|
||||
@env["vm"] = @vm
|
||||
@env["box"] = Vagrant::Box.new(mock_environment, "foo")
|
||||
|
||||
@internal_vm = mock("internal")
|
||||
@vm.stubs(:vm).returns(@internal_vm)
|
||||
|
||||
@instance = @klass.new(@app, @env)
|
||||
end
|
||||
|
||||
context "calling" do
|
||||
setup do
|
||||
@env.logger.stubs(:info)
|
||||
end
|
||||
|
||||
should "delete the box directory" do
|
||||
seq = sequence("seq")
|
||||
FileUtils.expects(:rm_rf).with(@env["box"].directory).in_sequence(seq)
|
||||
@app.expects(:call).with(@env).once.in_sequence(seq)
|
||||
@instance.call(@env)
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,6 +1,6 @@
|
|||
require File.join(File.dirname(__FILE__), '..', '..', '..', 'test_helper')
|
||||
|
||||
class DestroyBoxActionTest < Test::Unit::TestCase
|
||||
class DestroyBoxActionsTest < Test::Unit::TestCase
|
||||
setup do
|
||||
@name = "foo"
|
||||
@dir = "foo"
|
||||
|
|
|
@ -134,7 +134,7 @@ class BoxTest < Test::Unit::TestCase
|
|||
|
||||
context "destroying" do
|
||||
should "execute the destroy action" do
|
||||
@box.expects(:execute!).with(Vagrant::Actions::Box::Destroy).once
|
||||
@box.env.actions.expects(:run).with(:box_remove, { "box" => @box })
|
||||
@box.destroy
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue