Changed box actions and commands to use the Box class instead of passed in params.
This commit is contained in:
parent
1856d56431
commit
28b48929df
|
@ -2,14 +2,8 @@ module Vagrant
|
|||
module Actions
|
||||
module Box
|
||||
class Add < Base
|
||||
def initialize(runner, name, path, *args)
|
||||
super
|
||||
@name = name
|
||||
@uri = path
|
||||
end
|
||||
|
||||
def prepare
|
||||
@runner.add_action(Download, @uri)
|
||||
@runner.add_action(Download)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -7,11 +7,6 @@ module Vagrant
|
|||
BASENAME = "box"
|
||||
BUFFERSIZE = 1048576 # 1 MB
|
||||
|
||||
def initialize(runner, uri, *args)
|
||||
super
|
||||
@uri = uri
|
||||
end
|
||||
|
||||
def execute!
|
||||
with_tempfile do |tempfile|
|
||||
copy_uri_to(tempfile)
|
||||
|
@ -27,7 +22,7 @@ module Vagrant
|
|||
|
||||
def copy_uri_to(f)
|
||||
logger.info "Copying box to temporary location..."
|
||||
open(@uri) do |remote_file|
|
||||
open(@runner.uri) do |remote_file|
|
||||
loop do
|
||||
break if remote_file.eof?
|
||||
f.write(remote_file.read(BUFFERSIZE))
|
||||
|
|
|
@ -1,5 +1,20 @@
|
|||
module Vagrant
|
||||
class Box < Actions::Runner
|
||||
attr_accessor :name
|
||||
attr_accessor :uri
|
||||
attr_accessor :temp_path
|
||||
|
||||
class <<self
|
||||
def add(name, uri)
|
||||
box = new
|
||||
box.name = name
|
||||
box.uri = uri
|
||||
box.add
|
||||
end
|
||||
end
|
||||
|
||||
def add
|
||||
execute!(Actions::Box::Add)
|
||||
end
|
||||
end
|
||||
end
|
|
@ -158,7 +158,7 @@ error
|
|||
|
||||
# Adds a box to the local filesystem, given a URI.
|
||||
def box_add(name, path)
|
||||
Box.execute!(Actions::Box::Add, name, path)
|
||||
Box.add(name, path)
|
||||
end
|
||||
|
||||
private
|
||||
|
|
|
@ -3,7 +3,8 @@ require File.join(File.dirname(__FILE__), '..', '..', '..', 'test_helper')
|
|||
class DownloadBoxActionTest < Test::Unit::TestCase
|
||||
setup do
|
||||
@uri = "foo.com"
|
||||
@wrapper_vm, @vm, @action = mock_action(Vagrant::Actions::Box::Download, @uri)
|
||||
@runner, @vm, @action = mock_action(Vagrant::Actions::Box::Download)
|
||||
@runner.stubs(:uri).returns(@uri)
|
||||
mock_config
|
||||
|
||||
Vagrant::Env.stubs(:tmp_path).returns("foo")
|
||||
|
@ -48,6 +49,11 @@ class DownloadBoxActionTest < Test::Unit::TestCase
|
|||
@action.stubs(:open).yields(@file)
|
||||
end
|
||||
|
||||
should "open with the given uri" do
|
||||
@action.expects(:open).with(@uri).once
|
||||
@action.copy_uri_to(@tempfile)
|
||||
end
|
||||
|
||||
should "read from the file and write to the tempfile" do
|
||||
data = mock("data")
|
||||
write_seq = sequence("write_seq")
|
||||
|
|
|
@ -0,0 +1,32 @@
|
|||
require File.join(File.dirname(__FILE__), '..', 'test_helper')
|
||||
|
||||
class BoxTest < Test::Unit::TestCase
|
||||
context "class methods" do
|
||||
context "adding" do
|
||||
setup do
|
||||
@name = "foo"
|
||||
@uri = "bar"
|
||||
end
|
||||
|
||||
should "create a new instance, set the variables, and add it" do
|
||||
box = mock("box")
|
||||
box.expects(:name=).with(@name)
|
||||
box.expects(:uri=).with(@uri)
|
||||
box.expects(:add).once
|
||||
Vagrant::Box.expects(:new).returns(box)
|
||||
Vagrant::Box.add(@name, @uri)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "instance methods" do
|
||||
setup do
|
||||
@box = Vagrant::Box.new
|
||||
end
|
||||
|
||||
should "execute the Add action when add is called" do
|
||||
@box.expects(:execute!).with(Vagrant::Actions::Box::Add).once
|
||||
@box.add
|
||||
end
|
||||
end
|
||||
end
|
|
@ -206,7 +206,7 @@ class CommandsTest < Test::Unit::TestCase
|
|||
end
|
||||
|
||||
should "execute the add action with the name and path" do
|
||||
Vagrant::Box.expects(:execute!).with(Vagrant::Actions::Box::Add, @name, @path).once
|
||||
Vagrant::Box.expects(:add).with(@name, @path).once
|
||||
Vagrant::Commands.box_add(@name, @path)
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue