Ensure tmp dir for validate is removed once command exits

This commit is contained in:
Brian Cain 2018-12-03 14:45:26 -08:00
parent 69eacd2b73
commit 5fa3c5866c
No known key found for this signature in database
GPG Key ID: 9FC4639B2E4510A0
2 changed files with 8 additions and 2 deletions

View File

@ -30,7 +30,7 @@ module VagrantPlugins
action_env = {}
if options[:ignore_provider]
action_env[:ignore_provider] = true
mockup_providers!
tmp_data_dir = mockup_providers!
end
# Validate the configuration of all machines
@ -42,6 +42,8 @@ module VagrantPlugins
# Success, exit status 0
0
ensure
FileUtils.remove_entry tmp_data_dir if tmp_data_dir
end
protected
@ -51,6 +53,8 @@ module VagrantPlugins
# It essentially ignores that there are no installed or usable prodivers so
# that Vagrant can go along and validate the rest of the Vagrantfile and ignore
# any provider blocks.
#
# return [String] tmp_data_dir - Temporary dir used to store guest metadata during validation
def mockup_providers!
require 'log4r'
logger = Log4r::Logger.new("vagrant::validate")
@ -93,6 +97,7 @@ module VagrantPlugins
end
end
end
tmp_data_dir
end
end
end

View File

@ -138,7 +138,8 @@ describe VagrantPlugins::CommandValidate::Command do
VF
end
it "ignores provider specific configurations with the flag" do
allow(subject).to receive(:mockup_providers!).and_return(true)
allow(subject).to receive(:mockup_providers!).and_return("")
allow(FileUtils).to receive(:remove_entry).and_return(true)
expect(iso_env.ui).to receive(:info).with(any_args) { |message, _|
expect(message).to include("Vagrantfile validated successfully.")
}