Only verify NFS settings if NFS shared folders exist

This commit is contained in:
Mitchell Hashimoto 2010-07-13 20:25:20 -07:00
parent 604b978cab
commit 1bfb99d606
3 changed files with 39 additions and 9 deletions

View File

@ -20,7 +20,7 @@ module Vagrant
@app = app
@env = env
verify_settings
verify_settings if nfs_enabled?
end
def call(env)
@ -105,6 +105,15 @@ module Vagrant
@env["config"].vm.network_options[1][:ip]
end
# Checks if there are any NFS enabled shared folders.
def nfs_enabled?
@env["config"].vm.shared_folders.each do |key, opts|
return true if opts[:nfs]
end
false
end
# Verifies that the host is set and supports NFS.
def verify_settings
return @env.error!(:nfs_host_required) if @env["host"].nil?

View File

@ -15,11 +15,21 @@ class NFSVMActionTest < Test::Unit::TestCase
@vm.stubs(:vm).returns(@internal_vm)
end
context "initializing" do
should "not call verify settings if NFS is not enabled" do
@klass.any_instance.expects(:verify_settings).never
@klass.new(@app, @env)
end
should "call verify settings if NFS is enabled" do
@env.env.config.vm.share_folder("v-root", "/vagrant", ".", :nfs => true)
@klass.any_instance.expects(:verify_settings).once
@klass.new(@app, @env)
end
end
context "with an instance" do
setup do
# Kind of dirty but not sure of a way around this
@klass.send(:alias_method, :verify_settings_real, :verify_settings)
@klass.any_instance.stubs(:verify_settings)
@instance = @klass.new(@app, @env)
end
@ -161,6 +171,17 @@ class NFSVMActionTest < Test::Unit::TestCase
end
end
context "nfs enabled" do
should "return false if no folders are marked for NFS" do
assert !@instance.nfs_enabled?
end
should "return true if a shared folder is marked for NFS" do
@env.env.config.vm.share_folder("v-foo", "/foo", "/bar", :nfs => true)
assert @instance.nfs_enabled?
end
end
context "verifying settings" do
setup do
@env.env.host.stubs(:nfs?).returns(true)
@ -168,28 +189,28 @@ class NFSVMActionTest < Test::Unit::TestCase
should "error environment if host is nil" do
@env.env.stubs(:host).returns(nil)
@instance.verify_settings_real
@instance.verify_settings
assert @env.error?
assert_equal :nfs_host_required, @env.error.first
end
should "error environment if host does not support NFS" do
@env.env.host.stubs(:nfs?).returns(false)
@instance.verify_settings_real
@instance.verify_settings
assert @env.error?
assert_equal :nfs_not_supported, @env.error.first
end
should "error environment if host only networking is not enabled" do
@env.env.config.vm.network_options.clear
@instance.verify_settings_real
@instance.verify_settings
assert @env.error?
assert_equal :nfs_no_host_network, @env.error.first
end
should "be fine if everything passes" do
@env.env.host.stubs(:nfs?).returns(true)
@instance.verify_settings_real
@instance.verify_settings
assert !@env.error?
end
end

View File

@ -9,7 +9,7 @@ Gem::Specification.new do |s|
s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version=
s.authors = ["Mitchell Hashimoto", "John Bender"]
s.date = %q{2010-07-12}
s.date = %q{2010-07-13}
s.default_executable = %q{vagrant}
s.description = %q{Vagrant is a tool for building and distributing virtualized development environments.}
s.email = ["mitchell.hashimoto@gmail.com", "john.m.bender@gmail.com"]