Require root path on environment load
This commit is contained in:
parent
baccbd047d
commit
5f6e3acf40
|
@ -91,7 +91,7 @@ module Vagrant
|
|||
|
||||
# The options on the hash get priority, then the default
|
||||
# values
|
||||
value = opts[key] || @env["config"].nfs.send(key)
|
||||
value = opts.has_key?(key) ? opts[key] : @env["config"].nfs.send(key)
|
||||
return value if value != :auto
|
||||
|
||||
# Get UID/GID from folder if we've made it this far
|
||||
|
|
|
@ -9,15 +9,9 @@ module Vagrant
|
|||
@env.ui = UI::Shell.new(@env, shell) if !@env.ui.is_a?(UI::Shell)
|
||||
end
|
||||
|
||||
def require_environment
|
||||
raise Errors::NoEnvironmentError.new if !env.root_path
|
||||
end
|
||||
|
||||
# This returns an array of {VM} objects depending on the arguments
|
||||
# given to the command.
|
||||
def target_vms
|
||||
require_environment
|
||||
|
||||
@target_vms ||= begin
|
||||
if env.multivm?
|
||||
return env.vms.values if !self.name
|
||||
|
|
|
@ -209,6 +209,7 @@ module Vagrant
|
|||
def load!
|
||||
if !loaded?
|
||||
@loaded = true
|
||||
raise Errors::NoEnvironmentError.new if !root_path
|
||||
self.class.check_virtualbox!
|
||||
load_config!
|
||||
load_vm!
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
module VagrantTestHelpers
|
||||
module Objects
|
||||
# Returns a blank app (callable) and action environment with the
|
||||
# given vagrant environment.
|
||||
def action_env(v_env = nil)
|
||||
v_env ||= vagrant_env
|
||||
app = lambda { |env| }
|
||||
env = Vagrant::Action::Environment.new(v_env)
|
||||
env["vagrant.test"] = true
|
||||
[app, env]
|
||||
end
|
||||
end
|
||||
end
|
|
@ -7,6 +7,7 @@ require 'contest'
|
|||
require 'mocha'
|
||||
require 'support/path'
|
||||
require 'support/environment'
|
||||
require 'support/objects'
|
||||
|
||||
# Try to load ruby debug since its useful if it is available.
|
||||
# But not a big deal if its not available (probably on a non-MRI
|
||||
|
@ -25,6 +26,7 @@ I18n.load_path << File.expand_path("../locales/en.yml", __FILE__)
|
|||
class Test::Unit::TestCase
|
||||
include VagrantTestHelpers::Path
|
||||
include VagrantTestHelpers::Environment
|
||||
include VagrantTestHelpers::Objects
|
||||
|
||||
# Mocks an environment, setting it up with the given config.
|
||||
def mock_environment
|
||||
|
@ -102,9 +104,10 @@ class Test::Unit::TestCase
|
|||
vm
|
||||
end
|
||||
|
||||
def mock_action_data
|
||||
def mock_action_data(v_env=nil)
|
||||
v_env ||= vagrant_env
|
||||
app = lambda { |env| }
|
||||
env = Vagrant::Action::Environment.new(mock_environment)
|
||||
env = Vagrant::Action::Environment.new(v_env)
|
||||
env["vagrant.test"] = true
|
||||
[app, env]
|
||||
end
|
||||
|
|
|
@ -3,8 +3,6 @@ require 'test_helper'
|
|||
class CheckBoxVMActionTest < Test::Unit::TestCase
|
||||
setup do
|
||||
@klass = Vagrant::Action::VM::CheckBox
|
||||
@app, @env = mock_action_data
|
||||
@instance = @klass.new(@app, @env)
|
||||
end
|
||||
|
||||
context "calling" do
|
||||
|
@ -13,34 +11,48 @@ class CheckBoxVMActionTest < Test::Unit::TestCase
|
|||
end
|
||||
|
||||
should "raise error if box not specified" do
|
||||
@env.env.config.vm.box = nil
|
||||
@app.expects(:call).never
|
||||
app, env = action_env(vagrant_env(vagrantfile(<<-vf)))
|
||||
config.vm.box = nil
|
||||
vf
|
||||
|
||||
instance = @klass.new(app, env)
|
||||
app.expects(:call).never
|
||||
|
||||
assert_raises(Vagrant::Errors::BoxNotSpecified) {
|
||||
@instance.call(@env)
|
||||
instance.call(env)
|
||||
}
|
||||
end
|
||||
|
||||
should "error if box does not exist and URL not specified" do
|
||||
@env.env.config.vm.box_url = nil
|
||||
Vagrant::Box.expects(:find).with(@env.env, @env["config"].vm.box).returns(nil)
|
||||
app, env = action_env(vagrant_env(vagrantfile(<<-vf)))
|
||||
config.vm.box = "yo"
|
||||
config.vm.box_url = nil
|
||||
vf
|
||||
|
||||
instance = @klass.new(app, env)
|
||||
app.expects(:call).never
|
||||
Vagrant::Box.expects(:find).with(env.env, env["config"].vm.box).returns(nil)
|
||||
|
||||
@app.expects(:call).never
|
||||
assert_raises(Vagrant::Errors::BoxSpecifiedDoesntExist) {
|
||||
@instance.call(@env)
|
||||
instance.call(env)
|
||||
}
|
||||
end
|
||||
|
||||
should "attempt to download box and continue if URL specified" do
|
||||
app, env = action_env(vagrant_env(vagrantfile(<<-vf)))
|
||||
config.vm.box = "yo"
|
||||
config.vm.box_url = "http://google.com"
|
||||
vf
|
||||
|
||||
instance = @klass.new(app, env)
|
||||
seq = sequence("seq")
|
||||
@env.env.config.vm.box_url = "bar"
|
||||
Vagrant::Box.expects(:find).returns(nil)
|
||||
Vagrant::Box.expects(:add).with(@env.env, @env["config"].vm.box, @env["config"].vm.box_url).in_sequence(seq)
|
||||
@env.env.expects(:load_box!).in_sequence(seq)
|
||||
@app.expects(:call).with(@env).once.in_sequence(seq)
|
||||
Vagrant::Box.expects(:add).with(env.env, env["config"].vm.box, env["config"].vm.box_url).in_sequence(seq)
|
||||
env.env.expects(:load_box!).in_sequence(seq)
|
||||
app.expects(:call).with(env).once.in_sequence(seq)
|
||||
|
||||
assert_nothing_raised {
|
||||
@instance.call(@env)
|
||||
instance.call(env)
|
||||
}
|
||||
end
|
||||
end
|
||||
|
|
|
@ -3,7 +3,7 @@ require "test_helper"
|
|||
class NFSVMActionTest < Test::Unit::TestCase
|
||||
setup do
|
||||
@klass = Vagrant::Action::VM::NFS
|
||||
@app, @env = mock_action_data
|
||||
@app, @env = action_env
|
||||
|
||||
@vm = mock("vm")
|
||||
@vm.stubs(:system).returns(mock("system"))
|
||||
|
@ -109,11 +109,12 @@ class NFSVMActionTest < Test::Unit::TestCase
|
|||
end
|
||||
|
||||
should "return nil if the perm is not set" do
|
||||
@env.env.config.nfs.map_uid = nil
|
||||
assert_nil @instance.prepare_permission(:uid, {:gid => 7})
|
||||
end
|
||||
|
||||
should "return nil if the perm explicitly says nil" do
|
||||
assert_nil @instance.prepare_permission(:uid, {:uid => nil})
|
||||
assert_nil @instance.prepare_permission(:uid, {:map_uid => nil})
|
||||
end
|
||||
|
||||
should "return the set value if it is set" do
|
||||
|
|
|
@ -24,22 +24,6 @@ class CommandHelpersTest < Test::Unit::TestCase
|
|||
end
|
||||
end
|
||||
|
||||
context "requiring environment" do
|
||||
setup do
|
||||
@env = mock_environment
|
||||
end
|
||||
|
||||
should "raise an exception if no environment" do
|
||||
@env.stubs(:root_path).returns(nil)
|
||||
assert_raises(Vagrant::Errors::NoEnvironmentError) { command([], @env).require_environment }
|
||||
end
|
||||
|
||||
should "not raise an exception if there is an environment" do
|
||||
@env.stubs(:root_path).returns(7)
|
||||
assert_nothing_raised { command([], @env).require_environment }
|
||||
end
|
||||
end
|
||||
|
||||
context "vms from args" do
|
||||
setup do
|
||||
@env = mock_environment
|
||||
|
|
|
@ -433,12 +433,6 @@ class EnvironmentTest < Test::Unit::TestCase
|
|||
end
|
||||
|
||||
context "loading box" do
|
||||
should "do nothing if the root path is nil" do
|
||||
env = @klass.new(:cwd => "/")
|
||||
Vagrant::Box.expects(:find).never
|
||||
env.load_box!
|
||||
end
|
||||
|
||||
should "not load the box if its not set" do
|
||||
env = vagrant_env
|
||||
assert env.config.vm.box.nil?
|
||||
|
@ -459,11 +453,7 @@ class EnvironmentTest < Test::Unit::TestCase
|
|||
|
||||
context "loading the UUID out from the persisted dotfile" do
|
||||
setup do
|
||||
@local_data = {}
|
||||
|
||||
@env = mock_environment
|
||||
@env.stubs(:root_path).returns("foo")
|
||||
@env.stubs(:local_data).returns(@local_data)
|
||||
@env = vagrant_env
|
||||
end
|
||||
|
||||
should "blank the VMs" do
|
||||
|
@ -474,13 +464,13 @@ class EnvironmentTest < Test::Unit::TestCase
|
|||
end
|
||||
|
||||
should "load all the VMs from the dotfile" do
|
||||
@local_data[:active] = { :foo => "bar", :bar => "baz" }
|
||||
@env.local_data[:active] = { "foo" => "bar", "bar" => "baz" }
|
||||
|
||||
results = {}
|
||||
@local_data[:active].each do |key, value|
|
||||
@env.local_data[:active].each do |key, value|
|
||||
vm = mock("vm#{key}")
|
||||
Vagrant::VM.expects(:find).with(value, @env, key.to_sym).returns(vm)
|
||||
results[key] = vm
|
||||
results[key.to_sym] = vm
|
||||
end
|
||||
|
||||
@env.load_vm!
|
||||
|
@ -502,7 +492,7 @@ class EnvironmentTest < Test::Unit::TestCase
|
|||
end
|
||||
|
||||
should "uuid should be nil if local data contains nothing" do
|
||||
assert @local_data.empty? # sanity
|
||||
assert @env.local_data.empty? # sanity
|
||||
@env.load_vm!
|
||||
assert_nil @env.vm
|
||||
end
|
||||
|
|
|
@ -3,10 +3,8 @@ require "test_helper"
|
|||
class BSDHostTest < Test::Unit::TestCase
|
||||
setup do
|
||||
@klass = Vagrant::Hosts::BSD
|
||||
@env = mock_environment
|
||||
@env.stubs(:vm).returns(Vagrant::VM.new(:env => @env))
|
||||
|
||||
@instance = @klass.new(@env)
|
||||
@env = vagrant_env
|
||||
@instance = @klass.new(@env.vms.values.first.env)
|
||||
end
|
||||
|
||||
context "supporting nfs check" do
|
||||
|
@ -39,7 +37,7 @@ class BSDHostTest < Test::Unit::TestCase
|
|||
should "output the lines of the rendered template" do
|
||||
output = %W[foo bar baz].join("\n")
|
||||
Vagrant::Util::TemplateRenderer.expects(:render).with("nfs/exports",
|
||||
:uuid => @env.vm.uuid,
|
||||
:uuid => @instance.env.vm.uuid,
|
||||
:ip => @ip,
|
||||
:folders => @folders).returns(output)
|
||||
|
||||
|
|
|
@ -3,10 +3,9 @@ require "test_helper"
|
|||
class LinuxHostTest < Test::Unit::TestCase
|
||||
setup do
|
||||
@klass = Vagrant::Hosts::Linux
|
||||
@env = mock_environment
|
||||
@env.stubs(:vm).returns(Vagrant::VM.new(:env => @env))
|
||||
@env = vagrant_env
|
||||
|
||||
@instance = @klass.new(@env)
|
||||
@instance = @klass.new(@env.vms.values.first.env)
|
||||
end
|
||||
|
||||
context "supporting nfs check" do
|
||||
|
@ -39,7 +38,7 @@ class LinuxHostTest < Test::Unit::TestCase
|
|||
should "output the lines of the rendered template" do
|
||||
output = %W[foo bar baz].join("\n")
|
||||
Vagrant::Util::TemplateRenderer.expects(:render).with("nfs/exports_linux",
|
||||
:uuid => @env.vm.uuid,
|
||||
:uuid => @instance.env.vm.uuid,
|
||||
:ip => @ip,
|
||||
:folders => @folders).returns(output)
|
||||
|
||||
|
|
Loading…
Reference in New Issue