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")
|
||||
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
|
||||
vagrant_cwd_filepath = @data_dir.join('vagrant_cwd')
|
||||
vagrant_cwd = if File.exist?(vagrant_cwd_filepath)
|
||||
File.read(vagrant_cwd_filepath).chomp
|
||||
end
|
||||
|
||||
if vagrant_cwd
|
||||
if vagrant_cwd != @env.cwd.to_s
|
||||
if vagrant_cwd.nil?
|
||||
File.write(vagrant_cwd_filepath, @env.cwd)
|
||||
elsif vagrant_cwd != @env.cwd.to_s
|
||||
ui.warn(I18n.t(
|
||||
'vagrant.moved_cwd',
|
||||
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)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -308,6 +308,23 @@ describe Vagrant::Machine do
|
|||
to raise_error(Vagrant::Errors::UnimplementedProviderAction)
|
||||
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
|
||||
action_name = :up
|
||||
callable = lambda { |_env| }
|
||||
|
|
Loading…
Reference in New Issue