Fix bug where dotfile_path is a directory in the project path. Thanks brett_h
This commit is contained in:
parent
ce7f7dd168
commit
db24291b3d
|
@ -3,6 +3,17 @@ module Vagrant
|
|||
module VM
|
||||
class Up < Base
|
||||
def prepare
|
||||
# If the dotfile is not a file, raise error
|
||||
if File.exist?(Env.dotfile_path) && !File.file?(Env.dotfile_path)
|
||||
raise ActionException.new(<<-msg)
|
||||
The dotfile which Vagrant uses to store the UUID of the project's
|
||||
virtual machine already exists and is not a file! The dotfile is
|
||||
currently configured to be `#{Env.dotfile_path}`
|
||||
|
||||
To change this value, please see `config.vagrant.dotfile_name`
|
||||
msg
|
||||
end
|
||||
|
||||
# Up is a "meta-action" so it really just queues up a bunch
|
||||
# of other actions in its place:
|
||||
steps = [Import, ForwardPorts, SharedFolders, Start]
|
||||
|
|
|
@ -71,7 +71,7 @@ module Vagrant
|
|||
end
|
||||
|
||||
def load_vm!
|
||||
return unless root_path
|
||||
return if !root_path || !File.file?(dotfile_path)
|
||||
|
||||
File.open(dotfile_path) do |f|
|
||||
@@persisted_vm = Vagrant::VM.find(f.read)
|
||||
|
|
|
@ -8,6 +8,8 @@ class UpActionTest < Test::Unit::TestCase
|
|||
|
||||
context "sub-actions" do
|
||||
setup do
|
||||
File.stubs(:file?).returns(true)
|
||||
File.stubs(:exist?).returns(true)
|
||||
@default_order = [Vagrant::Actions::VM::Import, Vagrant::Actions::VM::ForwardPorts, Vagrant::Actions::VM::SharedFolders, Vagrant::Actions::VM::Start]
|
||||
end
|
||||
|
||||
|
@ -18,6 +20,26 @@ class UpActionTest < Test::Unit::TestCase
|
|||
end
|
||||
end
|
||||
|
||||
should "raise an ActionException if a dotfile exists but is not a file" do
|
||||
File.expects(:file?).with(Vagrant::Env.dotfile_path).returns(false)
|
||||
assert_raises(Vagrant::Actions::ActionException) {
|
||||
@action.prepare
|
||||
}
|
||||
end
|
||||
|
||||
should "not raise an ActionException if dotfile doesn't exist" do
|
||||
setup_action_expectations
|
||||
File.stubs(:exist?).returns(false)
|
||||
assert_nothing_raised { @action.prepare }
|
||||
end
|
||||
|
||||
should "not raise an ActionException if dotfile exists but is a file" do
|
||||
File.stubs(:file?).returns(true)
|
||||
File.stubs(:exist?).returns(true)
|
||||
setup_action_expectations
|
||||
assert_nothing_raised { @action.prepare }
|
||||
end
|
||||
|
||||
should "do the proper actions by default" do
|
||||
setup_action_expectations
|
||||
@action.prepare
|
||||
|
|
|
@ -6,6 +6,7 @@ class EnvTest < Test::Unit::TestCase
|
|||
filemock.expects(:read).returns("foo")
|
||||
Vagrant::VM.expects(:find).with("foo").returns(returnvalue)
|
||||
File.expects(:open).with(Vagrant::Env.dotfile_path).once.yields(filemock)
|
||||
File.expects(:file?).with(Vagrant::Env.dotfile_path).once.returns(true)
|
||||
Vagrant::Env.load_vm!
|
||||
end
|
||||
|
||||
|
@ -155,7 +156,11 @@ class EnvTest < Test::Unit::TestCase
|
|||
end
|
||||
|
||||
context "loading the UUID out from the persisted file" do
|
||||
test "loading of the uuid from the dotfile" do
|
||||
setup do
|
||||
File.stubs(:file?).returns(true)
|
||||
end
|
||||
|
||||
should "loading of the uuid from the dotfile" do
|
||||
mock_persisted_vm
|
||||
assert_equal 'foovm', Vagrant::Env.persisted_vm
|
||||
end
|
||||
|
@ -166,13 +171,19 @@ class EnvTest < Test::Unit::TestCase
|
|||
Vagrant::Env.load_vm!
|
||||
end
|
||||
|
||||
test "uuid should be nil if dotfile didn't exist" do
|
||||
should "do nothing if dotfile is not a file" do
|
||||
File.expects(:file?).returns(false)
|
||||
File.expects(:open).never
|
||||
Vagrant::Env.load_vm!
|
||||
end
|
||||
|
||||
should "uuid should be nil if dotfile didn't exist" do
|
||||
File.expects(:open).raises(Errno::ENOENT)
|
||||
Vagrant::Env.load_vm!
|
||||
assert_nil Vagrant::Env.persisted_vm
|
||||
end
|
||||
|
||||
test "should build up the dotfile out of the root path and the dotfile name" do
|
||||
should "should build up the dotfile out of the root path and the dotfile name" do
|
||||
assert_equal File.join(Vagrant::Env.root_path, Vagrant.config.vagrant.dotfile_name), Vagrant::Env.dotfile_path
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue