Add basic unit test for CWD change warning
This commit is contained in:
parent
48b0e00368
commit
79c7799fd9
|
@ -562,22 +562,23 @@ module Vagrant
|
||||||
@data_dir.join("creator_uid")
|
@data_dir.join("creator_uid")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Checks the current directory for a given machine
|
||||||
|
# and displays a warning if that machine has moved
|
||||||
|
# from its previous location on disk. If the machine
|
||||||
|
# has moved, it prints a warning to the user.
|
||||||
def check_cwd
|
def check_cwd
|
||||||
vagrant_cwd_filepath = @data_dir.join('vagrant_cwd')
|
vagrant_cwd_filepath = @data_dir.join('vagrant_cwd')
|
||||||
vagrant_cwd = if File.exist?(vagrant_cwd_filepath)
|
vagrant_cwd = if File.exist?(vagrant_cwd_filepath)
|
||||||
File.read(vagrant_cwd_filepath).chomp
|
File.read(vagrant_cwd_filepath).chomp
|
||||||
end
|
end
|
||||||
|
|
||||||
if vagrant_cwd
|
if vagrant_cwd.nil?
|
||||||
if vagrant_cwd != @env.cwd.to_s
|
File.write(vagrant_cwd_filepath, @env.cwd)
|
||||||
ui.warn(I18n.t(
|
elsif vagrant_cwd != @env.cwd.to_s
|
||||||
'vagrant.moved_cwd',
|
ui.warn(I18n.t(
|
||||||
old_wd: vagrant_cwd,
|
'vagrant.moved_cwd',
|
||||||
current_wd: @env.cwd.to_s))
|
old_wd: vagrant_cwd,
|
||||||
|
current_wd: @env.cwd.to_s))
|
||||||
File.write(vagrant_cwd_filepath, @env.cwd)
|
|
||||||
end
|
|
||||||
else
|
|
||||||
File.write(vagrant_cwd_filepath, @env.cwd)
|
File.write(vagrant_cwd_filepath, @env.cwd)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -308,6 +308,23 @@ describe Vagrant::Machine do
|
||||||
to raise_error(Vagrant::Errors::UnimplementedProviderAction)
|
to raise_error(Vagrant::Errors::UnimplementedProviderAction)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'should not warn if the machines cwd has not changed' do
|
||||||
|
initial_action_name = :up
|
||||||
|
second_action_name = :reload
|
||||||
|
callable = lambda { |_env| }
|
||||||
|
original_cwd = env.cwd.to_s
|
||||||
|
|
||||||
|
allow(provider).to receive(:action).with(initial_action_name).and_return(callable)
|
||||||
|
allow(provider).to receive(:action).with(second_action_name).and_return(callable)
|
||||||
|
allow(subject.ui).to receive(:warn)
|
||||||
|
|
||||||
|
instance.action(initial_action_name)
|
||||||
|
expect(subject.ui).to_not have_received(:warn)
|
||||||
|
|
||||||
|
instance.action(second_action_name)
|
||||||
|
expect(subject.ui).to_not have_received(:warn)
|
||||||
|
end
|
||||||
|
|
||||||
it 'should warn if the machine was last run under a different directory' do
|
it 'should warn if the machine was last run under a different directory' do
|
||||||
action_name = :up
|
action_name = :up
|
||||||
callable = lambda { |_env| }
|
callable = lambda { |_env| }
|
||||||
|
|
Loading…
Reference in New Issue