`vagrant box remove` functionality is in
This commit is contained in:
parent
f502587931
commit
546db294ca
|
@ -21,7 +21,7 @@ msg
|
||||||
end
|
end
|
||||||
|
|
||||||
def box_dir
|
def box_dir
|
||||||
File.join(Env.boxes_path, @runner.name)
|
@runner.directory
|
||||||
end
|
end
|
||||||
|
|
||||||
def decompress
|
def decompress
|
||||||
|
|
|
@ -5,16 +5,38 @@ module Vagrant
|
||||||
attr_accessor :temp_path
|
attr_accessor :temp_path
|
||||||
|
|
||||||
class <<self
|
class <<self
|
||||||
|
# Finds a box by the given name
|
||||||
|
def find(name)
|
||||||
|
return nil unless File.directory?(directory(name))
|
||||||
|
new(name)
|
||||||
|
end
|
||||||
|
|
||||||
def add(name, uri)
|
def add(name, uri)
|
||||||
box = new
|
box = new
|
||||||
box.name = name
|
box.name = name
|
||||||
box.uri = uri
|
box.uri = uri
|
||||||
box.add
|
box.add
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def directory(name)
|
||||||
|
File.join(Env.boxes_path, name)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def initialize(name=nil)
|
||||||
|
@name = name
|
||||||
end
|
end
|
||||||
|
|
||||||
def add
|
def add
|
||||||
execute!(Actions::Box::Add)
|
execute!(Actions::Box::Add)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def destroy
|
||||||
|
FileUtils.rm_rf(directory)
|
||||||
|
end
|
||||||
|
|
||||||
|
def directory
|
||||||
|
self.class.directory(self.name)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
|
@ -161,6 +161,19 @@ error
|
||||||
Box.add(name, path)
|
Box.add(name, path)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Removes a box.
|
||||||
|
def box_remove(name)
|
||||||
|
box = Box.find(name)
|
||||||
|
if box.nil?
|
||||||
|
error_and_exit(<<-error)
|
||||||
|
The box you're attempting to remove does not exist!
|
||||||
|
error
|
||||||
|
return # for tests
|
||||||
|
end
|
||||||
|
|
||||||
|
box.destroy
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def act_on_vm(&block)
|
def act_on_vm(&block)
|
||||||
|
|
|
@ -20,12 +20,10 @@ class UnpackageBoxActionTest < Test::Unit::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
context "box directory" do
|
context "box directory" do
|
||||||
setup do
|
should "return the runner directory" do
|
||||||
@box_dir = File.join(Vagrant::Env.boxes_path, @runner.name)
|
result = mock("object")
|
||||||
end
|
@runner.expects(:directory).once.returns(result)
|
||||||
|
assert result.equal?(@action.box_dir)
|
||||||
should "return the boxes_path joined with the name" do
|
|
||||||
assert_equal @box_dir, @action.box_dir
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,26 @@ require File.join(File.dirname(__FILE__), '..', 'test_helper')
|
||||||
|
|
||||||
class BoxTest < Test::Unit::TestCase
|
class BoxTest < Test::Unit::TestCase
|
||||||
context "class methods" do
|
context "class methods" do
|
||||||
|
context "finding" do
|
||||||
|
setup do
|
||||||
|
@dir = "foo"
|
||||||
|
@name = "bar"
|
||||||
|
Vagrant::Box.stubs(:directory).with(@name).returns(@dir)
|
||||||
|
end
|
||||||
|
|
||||||
|
should "return nil if the box doesn't exist" do
|
||||||
|
File.expects(:directory?).with(@dir).once.returns(false)
|
||||||
|
assert_nil Vagrant::Box.find(@name)
|
||||||
|
end
|
||||||
|
|
||||||
|
should "return a box object with the proper name set" do
|
||||||
|
File.expects(:directory?).with(@dir).once.returns(true)
|
||||||
|
result = Vagrant::Box.find(@name)
|
||||||
|
assert result
|
||||||
|
assert_equal @name, result.name
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
context "adding" do
|
context "adding" do
|
||||||
setup do
|
setup do
|
||||||
@name = "foo"
|
@name = "foo"
|
||||||
|
@ -17,6 +37,17 @@ class BoxTest < Test::Unit::TestCase
|
||||||
Vagrant::Box.add(@name, @uri)
|
Vagrant::Box.add(@name, @uri)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context "box directory" do
|
||||||
|
setup do
|
||||||
|
@name = "foo"
|
||||||
|
@box_dir = File.join(Vagrant::Env.boxes_path, @name)
|
||||||
|
end
|
||||||
|
|
||||||
|
should "return the boxes_path joined with the name" do
|
||||||
|
assert_equal @box_dir, Vagrant::Box.directory(@name)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context "instance methods" do
|
context "instance methods" do
|
||||||
|
@ -28,5 +59,29 @@ class BoxTest < Test::Unit::TestCase
|
||||||
@box.expects(:execute!).with(Vagrant::Actions::Box::Add).once
|
@box.expects(:execute!).with(Vagrant::Actions::Box::Add).once
|
||||||
@box.add
|
@box.add
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context "box directory" do
|
||||||
|
setup do
|
||||||
|
@box.name = "foo"
|
||||||
|
end
|
||||||
|
|
||||||
|
should "return the boxes_path joined with the name" do
|
||||||
|
result = mock("object")
|
||||||
|
Vagrant::Box.expects(:directory).with(@box.name).returns(result)
|
||||||
|
assert result.equal?(@box.directory)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "destroying" do
|
||||||
|
setup do
|
||||||
|
@dir = mock("directory")
|
||||||
|
@box.stubs(:directory).returns(@dir)
|
||||||
|
end
|
||||||
|
|
||||||
|
should "rm_rf the directory" do
|
||||||
|
FileUtils.expects(:rm_rf).with(@dir).once
|
||||||
|
@box.destroy
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -210,4 +210,23 @@ class CommandsTest < Test::Unit::TestCase
|
||||||
Vagrant::Commands.box_add(@name, @path)
|
Vagrant::Commands.box_add(@name, @path)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context "box remove" do
|
||||||
|
setup do
|
||||||
|
@name = "foo"
|
||||||
|
end
|
||||||
|
|
||||||
|
should "error and exit if the box doesn't exist" do
|
||||||
|
Vagrant::Box.expects(:find).returns(nil)
|
||||||
|
Vagrant::Commands.expects(:error_and_exit).once
|
||||||
|
Vagrant::Commands.box_remove(@name)
|
||||||
|
end
|
||||||
|
|
||||||
|
should "call destroy on the box if it exists" do
|
||||||
|
@box = mock("box")
|
||||||
|
Vagrant::Box.expects(:find).with(@name).returns(@box)
|
||||||
|
@box.expects(:destroy).once
|
||||||
|
Vagrant::Commands.box_remove(@name)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue