Add unique names to all tmpdir and tempfile calls in tests + cleanup
This commit attempts to uniquely identify the temporary files and directories that are created during test runs. Where it was a quick fix, this commit also removes the temporary files and directories. There are still a ton of temporary files due to calls to .isolated_environment in the tests without an easy API an easy way to provide a closer to that function.
This commit is contained in:
parent
3a27c29577
commit
fb60d34236
|
@ -28,7 +28,7 @@ class IsolatedEnvironment
|
|||
@logger = Log4r::Logger.new("test::isolated_environment")
|
||||
|
||||
# Create a temporary directory for our work
|
||||
@tempdir = Vagrant::Util::Platform.fs_real_path(Dir.mktmpdir("vagrant"))
|
||||
@tempdir = Vagrant::Util::Platform.fs_real_path(Dir.mktmpdir("vagrant-iso-env"))
|
||||
@logger.info("Initialize isolated environment: #{@tempdir}")
|
||||
|
||||
# Setup the home and working directories
|
||||
|
|
|
@ -27,6 +27,10 @@ require "unit/support/shared/virtualbox_context"
|
|||
$stdout.sync = true
|
||||
$stderr.sync = true
|
||||
|
||||
# Create a temporary directory where test vagrant will run. The reason we save
|
||||
# this to a constant is so we can clean it up later.
|
||||
VAGRANT_TEST_CWD = Dir.mktmpdir("vagrant-test-cwd")
|
||||
|
||||
# Configure RSpec
|
||||
RSpec.configure do |c|
|
||||
c.treat_symbols_as_metadata_keys_with_true_values = true
|
||||
|
@ -36,11 +40,15 @@ RSpec.configure do |c|
|
|||
else
|
||||
c.filter_run_excluding :windows
|
||||
end
|
||||
|
||||
c.after(:suite) do
|
||||
FileUtils.rm_rf(VAGRANT_TEST_CWD)
|
||||
end
|
||||
end
|
||||
|
||||
# Configure VAGRANT_CWD so that the tests never find an actual
|
||||
# Vagrantfile anywhere, or at least this minimizes those chances.
|
||||
ENV["VAGRANT_CWD"] = Dir.mktmpdir("vagrant")
|
||||
ENV["VAGRANT_CWD"] = VAGRANT_TEST_CWD
|
||||
|
||||
# Set the dummy provider to the default for tests
|
||||
ENV["VAGRANT_DEFAULT_PROVIDER"] = "dummy"
|
||||
|
|
|
@ -35,7 +35,9 @@ describe VagrantPlugins::CommandBox::Command::Update do
|
|||
context "updating specific box" do
|
||||
let(:argv) { ["--box", "foo"] }
|
||||
|
||||
let(:metadata_url) { Pathname.new(Dir.mktmpdir).join("metadata.json") }
|
||||
let(:scratch) { Dir.mktmpdir("vagrant-test-command-box-update-execute") }
|
||||
|
||||
let(:metadata_url) { Pathname.new(scratch).join("metadata.json") }
|
||||
|
||||
before do
|
||||
metadata_url.open("w") do |f|
|
||||
|
@ -46,6 +48,10 @@ describe VagrantPlugins::CommandBox::Command::Update do
|
|||
"foo", "1.0", :virtualbox, metadata_url: metadata_url.to_s)
|
||||
end
|
||||
|
||||
after do
|
||||
FileUtils.rm_rf(scratch)
|
||||
end
|
||||
|
||||
it "doesn't update if they're up to date" do
|
||||
called = false
|
||||
allow(action_runner).to receive(:run) do |callable, opts|
|
||||
|
|
|
@ -64,7 +64,7 @@ describe VagrantPlugins::FTPPush::FTPAdapter do
|
|||
|
||||
describe "#upload" do
|
||||
before do
|
||||
@dir = Dir.mktmpdir
|
||||
@dir = Dir.mktmpdir("vagrant-ftp-push-adapter-upload")
|
||||
FileUtils.touch("#{@dir}/file")
|
||||
end
|
||||
|
||||
|
|
|
@ -109,7 +109,7 @@ describe VagrantPlugins::FTPPush::Push do
|
|||
|
||||
describe "#all_files" do
|
||||
before(:all) do
|
||||
@dir = Dir.mktmpdir
|
||||
@dir = Dir.mktmpdir("vagrant-ftp-push-push-all-files")
|
||||
|
||||
FileUtils.touch("#{@dir}/.hidden.rb")
|
||||
FileUtils.touch("#{@dir}/application.rb")
|
||||
|
@ -151,9 +151,9 @@ describe VagrantPlugins::FTPPush::Push do
|
|||
end
|
||||
end
|
||||
|
||||
describe "includes_files" do
|
||||
describe "#includes_files" do
|
||||
before(:all) do
|
||||
@dir = Dir.mktmpdir
|
||||
@dir = Dir.mktmpdir("vagrant-ftp-push-includes-files")
|
||||
|
||||
FileUtils.touch("#{@dir}/.hidden.rb")
|
||||
FileUtils.touch("#{@dir}/application.rb")
|
||||
|
|
|
@ -132,8 +132,8 @@ module Unit
|
|||
# @return [Pathname] Path to the newly created box.
|
||||
def box1_file
|
||||
# Create a temporary directory to store our data we will tar up
|
||||
td_source = Dir.mktmpdir
|
||||
td_dest = Dir.mktmpdir
|
||||
td_source = Dir.mktmpdir("vagrant-box1-source")
|
||||
td_dest = Dir.mktmpdir("vagrant-box-1-dest")
|
||||
|
||||
# Store the temporary directory so it is not deleted until
|
||||
# this instance is garbage collected.
|
||||
|
@ -177,8 +177,8 @@ module Unit
|
|||
}.merge(options[:metadata] || {})
|
||||
|
||||
# Create a temporary directory to store our data we will tar up
|
||||
td_source = Dir.mktmpdir
|
||||
td_dest = Dir.mktmpdir
|
||||
td_source = Dir.mktmpdir("vagrant-box-2-source")
|
||||
td_dest = Dir.mktmpdir("vagrant-box-2-dest")
|
||||
|
||||
# Store the temporary directory so it is not deleted until
|
||||
# this instance is garbage collected.
|
||||
|
|
|
@ -73,19 +73,27 @@ shared_context "unit" do
|
|||
end
|
||||
|
||||
# This creates a temporary directory and returns a {Pathname}
|
||||
# pointing to it.
|
||||
# pointing to it. If a block is given, the pathname is yielded and the
|
||||
# temporary directory is removed at the end of the block.
|
||||
#
|
||||
# @return [Pathname]
|
||||
def temporary_dir
|
||||
# Create a temporary directory and append it to the instance
|
||||
# variabe so that it isn't garbage collected and deleted
|
||||
d = Dir.mktmpdir("vagrant")
|
||||
d = Dir.mktmpdir("vagrant-temporary-dir")
|
||||
@_temp_files ||= []
|
||||
@_temp_files << d
|
||||
|
||||
# Return the pathname
|
||||
result = Pathname.new(Vagrant::Util::Platform.fs_real_path(d))
|
||||
yield result if block_given?
|
||||
if block_given?
|
||||
begin
|
||||
yield result
|
||||
ensure
|
||||
FileUtils.rm_rf(result)
|
||||
end
|
||||
end
|
||||
|
||||
return result
|
||||
end
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@ describe Vagrant::Action::Builtin::BoxAdd, :skip_windows do
|
|||
let(:env) { {
|
||||
box_collection: box_collection,
|
||||
hook: Proc.new { |name, env| env },
|
||||
tmp_path: Pathname.new(Dir.mktmpdir),
|
||||
tmp_path: Pathname.new(Dir.mktmpdir("vagrant-test-builtin-box-add")),
|
||||
ui: Vagrant::UI::Silent.new,
|
||||
} }
|
||||
|
||||
|
@ -31,6 +31,10 @@ describe Vagrant::Action::Builtin::BoxAdd, :skip_windows do
|
|||
Vagrant::Box.new("foo", :virtualbox, "1.0", box_dir)
|
||||
end
|
||||
|
||||
after do
|
||||
FileUtils.rm_rf(env[:tmp_path])
|
||||
end
|
||||
|
||||
# Helper to quickly SHA1 checksum a path
|
||||
def checksum(path)
|
||||
FileChecksum.new(path, Digest::SHA1).checksum
|
||||
|
@ -39,9 +43,6 @@ describe Vagrant::Action::Builtin::BoxAdd, :skip_windows do
|
|||
def with_ftp_server(path, **opts)
|
||||
path = Pathname.new(path)
|
||||
|
||||
tf = Tempfile.new("vagrant")
|
||||
tf.close
|
||||
|
||||
port = nil
|
||||
server = nil
|
||||
with_random_port do |port1, port2|
|
||||
|
@ -56,7 +57,7 @@ describe Vagrant::Action::Builtin::BoxAdd, :skip_windows do
|
|||
end
|
||||
|
||||
def with_web_server(path, **opts)
|
||||
tf = Tempfile.new("vagrant")
|
||||
tf = Tempfile.new("vagrant-web-server")
|
||||
tf.close
|
||||
|
||||
opts[:json_type] ||= "application/json"
|
||||
|
@ -74,6 +75,7 @@ describe Vagrant::Action::Builtin::BoxAdd, :skip_windows do
|
|||
thr = Thread.new { server.start }
|
||||
yield port
|
||||
ensure
|
||||
tf.unlink
|
||||
server.shutdown rescue nil
|
||||
thr.join rescue nil
|
||||
end
|
||||
|
@ -282,7 +284,7 @@ describe Vagrant::Action::Builtin::BoxAdd, :skip_windows do
|
|||
context "with box metadata" do
|
||||
it "adds from HTTP URL" do
|
||||
box_path = iso_env.box2_file(:virtualbox)
|
||||
tf = Tempfile.new(["vagrant", ".json"]).tap do |f|
|
||||
tf = Tempfile.new(["vagrant-test-box-http-url", ".json"]).tap do |f|
|
||||
f.write(<<-RAW)
|
||||
{
|
||||
"name": "foo/bar",
|
||||
|
@ -325,7 +327,7 @@ describe Vagrant::Action::Builtin::BoxAdd, :skip_windows do
|
|||
|
||||
it "adds from HTTP URL with complex JSON mime type" do
|
||||
box_path = iso_env.box2_file(:virtualbox)
|
||||
tf = Tempfile.new(["vagrant", ".json"]).tap do |f|
|
||||
tf = Tempfile.new(["vagrant-test-http-json", ".json"]).tap do |f|
|
||||
f.write(<<-RAW)
|
||||
{
|
||||
"name": "foo/bar",
|
||||
|
@ -370,7 +372,7 @@ describe Vagrant::Action::Builtin::BoxAdd, :skip_windows do
|
|||
|
||||
it "adds from shorthand path" do
|
||||
box_path = iso_env.box2_file(:virtualbox)
|
||||
td = Pathname.new(Dir.mktmpdir)
|
||||
td = Pathname.new(Dir.mktmpdir("vagrant-test-box-add-shorthand-path"))
|
||||
tf = td.join("mitchellh", "precise64.json")
|
||||
tf.dirname.mkpath
|
||||
tf.open("w") do |f|
|
||||
|
@ -414,11 +416,13 @@ describe Vagrant::Action::Builtin::BoxAdd, :skip_windows do
|
|||
subject.call(env)
|
||||
end
|
||||
end
|
||||
|
||||
FileUtils.rm_rf(td)
|
||||
end
|
||||
|
||||
it "add from shorthand path with configured server url" do
|
||||
box_path = iso_env.box2_file(:virtualbox)
|
||||
td = Pathname.new(Dir.mktmpdir)
|
||||
td = Pathname.new(Dir.mktmpdir("vagrant-test-box-add-server-url"))
|
||||
tf = td.join("mitchellh", "precise64.json")
|
||||
tf.dirname.mkpath
|
||||
tf.open("w") do |f|
|
||||
|
@ -461,11 +465,13 @@ describe Vagrant::Action::Builtin::BoxAdd, :skip_windows do
|
|||
|
||||
subject.call(env)
|
||||
end
|
||||
|
||||
FileUtils.rm_rf(td)
|
||||
end
|
||||
|
||||
it "authenticates HTTP URLs and adds them" do
|
||||
box_path = iso_env.box2_file(:virtualbox)
|
||||
tf = Tempfile.new(["vagrant", ".json"]).tap do |f|
|
||||
tf = Tempfile.new(["vagrant-test-http", ".json"]).tap do |f|
|
||||
f.write(<<-RAW)
|
||||
{
|
||||
"name": "foo/bar",
|
||||
|
@ -523,7 +529,7 @@ describe Vagrant::Action::Builtin::BoxAdd, :skip_windows do
|
|||
|
||||
it "adds from HTTP URL with a checksum" do
|
||||
box_path = iso_env.box2_file(:virtualbox)
|
||||
tf = Tempfile.new(["vagrant", ".json"]).tap do |f|
|
||||
tf = Tempfile.new(["vagrant-test-http-checksum", ".json"]).tap do |f|
|
||||
f.write(<<-RAW)
|
||||
{
|
||||
"name": "foo/bar",
|
||||
|
@ -568,7 +574,7 @@ describe Vagrant::Action::Builtin::BoxAdd, :skip_windows do
|
|||
|
||||
it "raises an exception if checksum given but not correct" do
|
||||
box_path = iso_env.box2_file(:virtualbox)
|
||||
tf = Tempfile.new(["vagrant", ".json"]).tap do |f|
|
||||
tf = Tempfile.new(["vagrant-test-bad-checksum", ".json"]).tap do |f|
|
||||
f.write(<<-RAW)
|
||||
{
|
||||
"name": "foo/bar",
|
||||
|
@ -606,9 +612,6 @@ describe Vagrant::Action::Builtin::BoxAdd, :skip_windows do
|
|||
end
|
||||
|
||||
it "raises an error if no Vagrant server is set" do
|
||||
tf = Tempfile.new("foo")
|
||||
tf.close
|
||||
|
||||
env[:box_url] = "mitchellh/precise64.json"
|
||||
|
||||
expect(box_collection).to receive(:add).never
|
||||
|
@ -621,10 +624,9 @@ describe Vagrant::Action::Builtin::BoxAdd, :skip_windows do
|
|||
end
|
||||
|
||||
it "raises an error if shorthand is invalid" do
|
||||
tf = Tempfile.new("foo")
|
||||
tf.close
|
||||
path = Dir::Tmpname.create("vagrant-shorthand-invalid") {}
|
||||
|
||||
with_web_server(Pathname.new(tf.path)) do |port|
|
||||
with_web_server(Pathname.new(path)) do |port|
|
||||
env[:box_url] = "mitchellh/precise64.json"
|
||||
|
||||
expect(box_collection).to receive(:add).never
|
||||
|
@ -640,7 +642,7 @@ describe Vagrant::Action::Builtin::BoxAdd, :skip_windows do
|
|||
|
||||
it "raises an error if multiple metadata URLs are given" do
|
||||
box_path = iso_env.box2_file(:virtualbox)
|
||||
tf = Tempfile.new("vagrant").tap do |f|
|
||||
tf = Tempfile.new(["vagrant-box-multi-metadata", ".json"]).tap do |f|
|
||||
f.write(<<-RAW)
|
||||
{
|
||||
"name": "foo/bar",
|
||||
|
@ -676,7 +678,7 @@ describe Vagrant::Action::Builtin::BoxAdd, :skip_windows do
|
|||
|
||||
it "adds the latest version of a box with only one provider" do
|
||||
box_path = iso_env.box2_file(:virtualbox)
|
||||
tf = Tempfile.new("vagrant").tap do |f|
|
||||
tf = Tempfile.new(["vagrant-box-latest-version", ".json"]).tap do |f|
|
||||
f.write(<<-RAW)
|
||||
{
|
||||
"name": "foo/bar",
|
||||
|
@ -715,7 +717,7 @@ describe Vagrant::Action::Builtin::BoxAdd, :skip_windows do
|
|||
|
||||
it "adds the latest version of a box with the specified provider" do
|
||||
box_path = iso_env.box2_file(:vmware)
|
||||
tf = Tempfile.new("vagrant").tap do |f|
|
||||
tf = Tempfile.new(["vagrant-box-specific-provider", ".json"]).tap do |f|
|
||||
f.write(<<-RAW)
|
||||
{
|
||||
"name": "foo/bar",
|
||||
|
@ -761,7 +763,7 @@ describe Vagrant::Action::Builtin::BoxAdd, :skip_windows do
|
|||
|
||||
it "adds the latest version of a box with the specified provider, even if not latest" do
|
||||
box_path = iso_env.box2_file(:vmware)
|
||||
tf = Tempfile.new("vagrant").tap do |f|
|
||||
tf = Tempfile.new(["vagrant-box-specified-provider", ".json"]).tap do |f|
|
||||
f.write(<<-RAW)
|
||||
{
|
||||
"name": "foo/bar",
|
||||
|
@ -810,7 +812,7 @@ describe Vagrant::Action::Builtin::BoxAdd, :skip_windows do
|
|||
|
||||
it "adds the constrained version of a box with the only provider" do
|
||||
box_path = iso_env.box2_file(:vmware)
|
||||
tf = Tempfile.new("vagrant").tap do |f|
|
||||
tf = Tempfile.new(["vagrant-box-constrained", ".json"]).tap do |f|
|
||||
f.write(<<-RAW)
|
||||
{
|
||||
"name": "foo/bar",
|
||||
|
@ -850,7 +852,7 @@ describe Vagrant::Action::Builtin::BoxAdd, :skip_windows do
|
|||
|
||||
it "adds the constrained version of a box with the specified provider" do
|
||||
box_path = iso_env.box2_file(:vmware)
|
||||
tf = Tempfile.new("vagrant").tap do |f|
|
||||
tf = Tempfile.new(["vagrant-box-constrained-provider", ".json"]).tap do |f|
|
||||
f.write(<<-RAW)
|
||||
{
|
||||
"name": "foo/bar",
|
||||
|
@ -895,7 +897,7 @@ describe Vagrant::Action::Builtin::BoxAdd, :skip_windows do
|
|||
|
||||
it "adds the latest version of a box with any specified provider" do
|
||||
box_path = iso_env.box2_file(:vmware)
|
||||
tf = Tempfile.new("vagrant").tap do |f|
|
||||
tf = Tempfile.new(["vagrant-box-latest-version", ".json"]).tap do |f|
|
||||
f.write(<<-RAW)
|
||||
{
|
||||
"name": "foo/bar",
|
||||
|
@ -943,7 +945,7 @@ describe Vagrant::Action::Builtin::BoxAdd, :skip_windows do
|
|||
|
||||
it "asks the user what provider if multiple options" do
|
||||
box_path = iso_env.box2_file(:virtualbox)
|
||||
tf = Tempfile.new("vagrant").tap do |f|
|
||||
tf = Tempfile.new(["vagrant-box-provider-asks", ".json"]).tap do |f|
|
||||
f.write(<<-RAW)
|
||||
{
|
||||
"name": "foo/bar",
|
||||
|
@ -989,7 +991,7 @@ describe Vagrant::Action::Builtin::BoxAdd, :skip_windows do
|
|||
|
||||
it "raises an exception if the name doesn't match a requested name" do
|
||||
box_path = iso_env.box2_file(:virtualbox)
|
||||
tf = Tempfile.new("vagrant").tap do |f|
|
||||
tf = Tempfile.new(["vagrant-box-name-mismatch", ".json"]).tap do |f|
|
||||
f.write(<<-RAW)
|
||||
{
|
||||
"name": "foo/bar",
|
||||
|
@ -1024,7 +1026,7 @@ describe Vagrant::Action::Builtin::BoxAdd, :skip_windows do
|
|||
|
||||
it "raises an exception if no matching version" do
|
||||
box_path = iso_env.box2_file(:vmware)
|
||||
tf = Tempfile.new("vagrant").tap do |f|
|
||||
tf = Tempfile.new(["vagrant-box-no-matching-version", ".json"]).tap do |f|
|
||||
f.write(<<-RAW)
|
||||
{
|
||||
"name": "foo/bar",
|
||||
|
@ -1055,7 +1057,7 @@ describe Vagrant::Action::Builtin::BoxAdd, :skip_windows do
|
|||
end
|
||||
|
||||
it "raises an error if there is no matching provider" do
|
||||
tf = Tempfile.new("vagrant").tap do |f|
|
||||
tf = Tempfile.new(["vagrant-box-no-matching-provider", ".json"]).tap do |f|
|
||||
f.write(<<-RAW)
|
||||
{
|
||||
"name": "foo/bar",
|
||||
|
@ -1089,7 +1091,7 @@ describe Vagrant::Action::Builtin::BoxAdd, :skip_windows do
|
|||
|
||||
it "raises an error if a box already exists" do
|
||||
box_path = iso_env.box2_file(:virtualbox)
|
||||
tf = Tempfile.new("vagrant").tap do |f|
|
||||
tf = Tempfile.new(["vagrant-box-already-exists", ".json"]).tap do |f|
|
||||
f.write(<<-RAW)
|
||||
{
|
||||
"name": "foo/bar",
|
||||
|
@ -1124,7 +1126,7 @@ describe Vagrant::Action::Builtin::BoxAdd, :skip_windows do
|
|||
|
||||
it "force adds a box if specified" do
|
||||
box_path = iso_env.box2_file(:virtualbox)
|
||||
tf = Tempfile.new("vagrant").tap do |f|
|
||||
tf = Tempfile.new(["vagrant-box-force-add", ".json"]).tap do |f|
|
||||
f.write(<<-RAW)
|
||||
{
|
||||
"name": "foo/bar",
|
||||
|
|
|
@ -4,8 +4,7 @@ describe Vagrant::Action::Builtin::Lock do
|
|||
let(:app) { lambda { |env| } }
|
||||
let(:env) { {} }
|
||||
let(:lock_path) do
|
||||
@__lock_path = Tempfile.new("vagrant-test-lock")
|
||||
@__lock_path.path.to_s
|
||||
Dir::Tmpname.create("vagrant-test-lock") {}
|
||||
end
|
||||
|
||||
let(:options) do
|
||||
|
@ -15,6 +14,10 @@ describe Vagrant::Action::Builtin::Lock do
|
|||
}
|
||||
end
|
||||
|
||||
after do
|
||||
File.unlink(lock_path) if File.file?(lock_path)
|
||||
end
|
||||
|
||||
it "should require a path" do
|
||||
expect { described_class.new(app, env) }.
|
||||
to raise_error(ArgumentError)
|
||||
|
|
|
@ -13,9 +13,9 @@ describe Vagrant::Action::Builtin::MixinSyncedFolders do
|
|||
end
|
||||
end
|
||||
|
||||
let(:machine) do
|
||||
data_dir = Pathname.new(Dir.mktmpdir)
|
||||
let(:data_dir) { Pathname.new(Dir.mktmpdir("vagrant-test-mixin-synced-folders")) }
|
||||
|
||||
let(:machine) do
|
||||
double("machine").tap do |machine|
|
||||
allow(machine).to receive(:config).and_return(machine_config)
|
||||
allow(machine).to receive(:data_dir).and_return(data_dir)
|
||||
|
@ -30,6 +30,10 @@ describe Vagrant::Action::Builtin::MixinSyncedFolders do
|
|||
|
||||
let(:vm_config) { double("machine_vm_config", :allowed_synced_folder_types => nil) }
|
||||
|
||||
after do
|
||||
FileUtils.rm_rf(data_dir)
|
||||
end
|
||||
|
||||
describe "default_synced_folder_type" do
|
||||
it "returns the usable implementation" do
|
||||
plugins = {
|
||||
|
|
|
@ -53,12 +53,16 @@ describe Vagrant::Action::Builtin::SyncedFolderCleanup do
|
|||
plugins[:nfs] = [impl(true, "nfs"), 5]
|
||||
|
||||
env[:machine] = Object.new
|
||||
env[:root_path] = Pathname.new(Dir.mktmpdir)
|
||||
env[:root_path] = Pathname.new(Dir.mktmpdir("vagrant-test-synced-folder-cleanup-call"))
|
||||
|
||||
subject.stub(plugins: plugins)
|
||||
subject.stub(synced_folders: synced_folders)
|
||||
end
|
||||
|
||||
after do
|
||||
FileUtils.rm_rf(env[:root_path])
|
||||
end
|
||||
|
||||
it "should invoke cleanup" do
|
||||
tracker = create_cleanup_tracker
|
||||
plugins[:tracker] = [tracker, 15]
|
||||
|
|
|
@ -41,12 +41,16 @@ describe Vagrant::Action::Builtin::SyncedFolders do
|
|||
plugins[:default] = [impl(true, "default"), 10]
|
||||
plugins[:nfs] = [impl(true, "nfs"), 5]
|
||||
|
||||
env[:root_path] = Pathname.new(Dir.mktmpdir)
|
||||
env[:root_path] = Pathname.new(Dir.mktmpdir("vagrant-test-synced-folders-call"))
|
||||
subject.stub(plugins: plugins)
|
||||
subject.stub(synced_folders: synced_folders)
|
||||
allow(subject).to receive(:save_synced_folders)
|
||||
end
|
||||
|
||||
after do
|
||||
FileUtils.rm_rf(env[:root_path])
|
||||
end
|
||||
|
||||
it "should create on the host if specified" do
|
||||
synced_folders["default"] = {
|
||||
"root" => {
|
||||
|
|
|
@ -39,8 +39,13 @@ describe Vagrant::BoxCollection, :skip_windows do
|
|||
end
|
||||
|
||||
it 'does not raise an exception when a file appears in the boxes dir' do
|
||||
Tempfile.new('a_file', environment.boxes_dir)
|
||||
expect { subject.all }.to_not raise_error
|
||||
t = Tempfile.new('a_file', environment.boxes_dir)
|
||||
t.close
|
||||
begin
|
||||
expect { subject.all }.to_not raise_error
|
||||
ensure
|
||||
t.unlink
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -227,7 +227,7 @@ describe Vagrant::Box, :skip_windows do
|
|||
|
||||
context "#load_metadata" do
|
||||
let(:metadata_url) do
|
||||
Tempfile.new("vagrant").tap do |f|
|
||||
Tempfile.new("vagrant-test-box-test").tap do |f|
|
||||
f.write(<<-RAW)
|
||||
{
|
||||
"name": "foo",
|
||||
|
@ -244,6 +244,10 @@ describe Vagrant::Box, :skip_windows do
|
|||
metadata_url: metadata_url.path)
|
||||
end
|
||||
|
||||
after do
|
||||
metadata_url.unlink if metadata_url.file?
|
||||
end
|
||||
|
||||
it "loads the url and returns the data" do
|
||||
result = subject.load_metadata
|
||||
expect(result.name).to eq("foo")
|
||||
|
|
|
@ -69,14 +69,14 @@ describe Vagrant::Environment do
|
|||
|
||||
describe "#home_path" do
|
||||
it "is set to the home path given" do
|
||||
temporary_dir do |dir|
|
||||
Dir.mktmpdir("vagrant-test-env-home-path-given") do |dir|
|
||||
instance = described_class.new(home_path: dir)
|
||||
expect(instance.home_path).to eq(Pathname.new(dir))
|
||||
end
|
||||
end
|
||||
|
||||
it "is set to the environmental variable VAGRANT_HOME" do
|
||||
temporary_dir do |dir|
|
||||
Dir.mktmpdir("vagrant-test-env-home-env-var") do |dir|
|
||||
instance = with_temp_env("VAGRANT_HOME" => dir.to_s) do
|
||||
described_class.new
|
||||
end
|
||||
|
@ -99,7 +99,7 @@ describe Vagrant::Environment do
|
|||
end
|
||||
|
||||
it "is okay if it has the current version" do
|
||||
Dir.mktmpdir do |dir|
|
||||
Dir.mktmpdir("vagrant-test-env-current-version") do |dir|
|
||||
Pathname.new(dir).join("setup_version").open("w") do |f|
|
||||
f.write(Vagrant::Environment::CURRENT_SETUP_VERSION)
|
||||
end
|
||||
|
@ -112,7 +112,7 @@ describe Vagrant::Environment do
|
|||
end
|
||||
|
||||
it "raises an exception if the version is newer than ours" do
|
||||
Dir.mktmpdir do |dir|
|
||||
Dir.mktmpdir("vagrant-test-env-newer-version") do |dir|
|
||||
Pathname.new(dir).join("setup_version").open("w") do |f|
|
||||
f.write("100.5")
|
||||
end
|
||||
|
@ -123,7 +123,7 @@ describe Vagrant::Environment do
|
|||
end
|
||||
|
||||
it "raises an exception if there is an unknown home directory version" do
|
||||
Dir.mktmpdir do |dir|
|
||||
Dir.mktmpdir("vagrant-test-env-unknown-home") do |dir|
|
||||
Pathname.new(dir).join("setup_version").open("w") do |f|
|
||||
f.write("0.7")
|
||||
end
|
||||
|
@ -645,7 +645,7 @@ VF
|
|||
|
||||
describe "active machines" do
|
||||
it "should be empty if there is no root path" do
|
||||
Dir.mktmpdir do |temp_dir|
|
||||
Dir.mktmpdir("vagrant-test-env-no-root-path") do |temp_dir|
|
||||
instance = described_class.new(cwd: temp_dir)
|
||||
expect(instance.active_machines).to be_empty
|
||||
end
|
||||
|
@ -715,7 +715,7 @@ VF
|
|||
|
||||
describe "current working directory" do
|
||||
it "is the cwd by default" do
|
||||
Dir.mktmpdir do |temp_dir|
|
||||
Dir.mktmpdir("vagrant-test-env-cwd-default") do |temp_dir|
|
||||
Dir.chdir(temp_dir) do
|
||||
with_temp_env("VAGRANT_CWD" => nil) do
|
||||
expect(described_class.new.cwd).to eq(Pathname.new(Dir.pwd))
|
||||
|
@ -725,14 +725,14 @@ VF
|
|||
end
|
||||
|
||||
it "is set to the cwd given" do
|
||||
Dir.mktmpdir do |directory|
|
||||
Dir.mktmpdir("vagrant-test-env-set-cwd") do |directory|
|
||||
instance = described_class.new(cwd: directory)
|
||||
expect(instance.cwd).to eq(Pathname.new(directory))
|
||||
end
|
||||
end
|
||||
|
||||
it "is set to the environmental variable VAGRANT_CWD" do
|
||||
Dir.mktmpdir do |directory|
|
||||
Dir.mktmpdir("vagrant-test-env-set-vagrant-cwd") do |directory|
|
||||
instance = with_temp_env("VAGRANT_CWD" => directory) do
|
||||
described_class.new
|
||||
end
|
||||
|
@ -905,7 +905,7 @@ VF
|
|||
end
|
||||
|
||||
it "is expanded relative to the cwd" do
|
||||
Dir.mktmpdir do |temp_dir|
|
||||
Dir.mktmpdir("vagrant-test-env-relative-cwd") do |temp_dir|
|
||||
Dir.chdir(temp_dir) do
|
||||
instance = described_class.new(local_data_path: "foo")
|
||||
expect(instance.local_data_path).to eq(instance.cwd.join("foo"))
|
||||
|
@ -915,7 +915,7 @@ VF
|
|||
end
|
||||
|
||||
it "is set to the given value" do
|
||||
Dir.mktmpdir do |dir|
|
||||
Dir.mktmpdir("vagrant-test-env-set-given") do |dir|
|
||||
instance = described_class.new(local_data_path: dir)
|
||||
expect(instance.local_data_path.to_s).to eq(dir)
|
||||
end
|
||||
|
@ -923,7 +923,7 @@ VF
|
|||
|
||||
describe "upgrading V1 dotfiles" do
|
||||
let(:v1_dotfile_tempfile) do
|
||||
Tempfile.new("vagrant").tap do |f|
|
||||
Tempfile.new("vagrant-upgrade-dotfile").tap do |f|
|
||||
f.close
|
||||
end
|
||||
end
|
||||
|
@ -932,6 +932,10 @@ VF
|
|||
let(:local_data_path) { v1_dotfile_tempfile.path }
|
||||
let(:instance) { described_class.new(local_data_path: local_data_path) }
|
||||
|
||||
after do
|
||||
File.unlink(v1_dotfile_tempfile) if File.file?(v1_dotfile_template)
|
||||
end
|
||||
|
||||
it "should be fine if dotfile is empty" do
|
||||
v1_dotfile.open("w+") do |f|
|
||||
f.write("")
|
||||
|
|
|
@ -9,7 +9,7 @@ require "vagrant/machine_index"
|
|||
describe Vagrant::MachineIndex do
|
||||
include_context "unit"
|
||||
|
||||
let(:data_dir) { temporary_dir }
|
||||
let(:data_dir) { Dir.mktmpdir }
|
||||
let(:entry_klass) { Vagrant::MachineIndex::Entry }
|
||||
|
||||
let(:new_entry) do
|
||||
|
@ -21,6 +21,10 @@ describe Vagrant::MachineIndex do
|
|||
|
||||
subject { described_class.new(data_dir) }
|
||||
|
||||
after do
|
||||
FileUtils.rm_rf(data_dir)
|
||||
end
|
||||
|
||||
it "raises an exception if the data file is corrupt" do
|
||||
data_dir.join("index").open("w") do |f|
|
||||
f.write(JSON.dump({}))
|
||||
|
|
|
@ -28,7 +28,7 @@ describe Vagrant::Machine do
|
|||
end
|
||||
|
||||
let(:config) { env.vagrantfile.config }
|
||||
let(:data_dir) { Pathname.new(Dir.mktmpdir("vagrant")) }
|
||||
let(:data_dir) { Pathname.new(Dir.mktmpdir("vagrant-machine-data-dir")) }
|
||||
let(:env) do
|
||||
# We need to create a Vagrantfile so that this test environment
|
||||
# has a proper root path
|
||||
|
@ -42,6 +42,10 @@ describe Vagrant::Machine do
|
|||
|
||||
let(:instance) { new_instance }
|
||||
|
||||
after do
|
||||
FileUtils.rm_rf(data_dir)
|
||||
end
|
||||
|
||||
subject { instance }
|
||||
|
||||
def new_provider_mock
|
||||
|
|
|
@ -11,11 +11,7 @@ describe Vagrant::Plugin::Manager do
|
|||
include_context "unit"
|
||||
|
||||
let(:path) do
|
||||
f = Tempfile.new("vagrant")
|
||||
p = f.path
|
||||
f.close
|
||||
f.unlink
|
||||
Pathname.new(p)
|
||||
Pathname.new(Dir::Tmpname.create("vagrant-test-plugin-manager") {})
|
||||
end
|
||||
|
||||
let(:bundler) { double("bundler") }
|
||||
|
|
|
@ -5,11 +5,7 @@ require File.expand_path("../../../base", __FILE__)
|
|||
|
||||
describe Vagrant::Plugin::StateFile do
|
||||
let(:path) do
|
||||
f = Tempfile.new("vagrant")
|
||||
p = f.path
|
||||
f.close
|
||||
f.unlink
|
||||
Pathname.new(p)
|
||||
Pathname.new(Dir::Tmpname.create("vagrant-test-statefile") {})
|
||||
end
|
||||
|
||||
after do
|
||||
|
|
|
@ -5,10 +5,17 @@ require File.expand_path("../../../base", __FILE__)
|
|||
require 'vagrant/util/safe_chdir'
|
||||
|
||||
describe Vagrant::Util::SafeChdir do
|
||||
let(:temp_dir) { Dir.mktmpdir("vagrant-test-util-safe-chdir") }
|
||||
let(:temp_dir2) { Dir.mktmpdir("vagrant-test-util-safe-chdir-2") }
|
||||
|
||||
after do
|
||||
FileUtils.rm_rf(temp_dir)
|
||||
FileUtils.rm_rf(temp_dir2)
|
||||
end
|
||||
|
||||
it "should change directories" do
|
||||
expected = nil
|
||||
result = nil
|
||||
temp_dir = Dir.mktmpdir
|
||||
|
||||
Dir.chdir(temp_dir) do
|
||||
expected = Dir.pwd
|
||||
|
@ -24,15 +31,14 @@ describe Vagrant::Util::SafeChdir do
|
|||
it "should allow recursive chdir" do
|
||||
expected = nil
|
||||
result = nil
|
||||
temp_path = Dir.mktmpdir
|
||||
|
||||
Dir.chdir(temp_path) do
|
||||
Dir.chdir(temp_dir) do
|
||||
expected = Dir.pwd
|
||||
end
|
||||
|
||||
expect do
|
||||
described_class.safe_chdir(Dir.mktmpdir) do
|
||||
described_class.safe_chdir(temp_path) do
|
||||
described_class.safe_chdir(temp_dir2) do
|
||||
described_class.safe_chdir(temp_dir) do
|
||||
result = Dir.pwd
|
||||
end
|
||||
end
|
||||
|
|
|
@ -58,7 +58,7 @@ describe Vagrant::Vagrantfile do
|
|||
|
||||
describe "#machine" do
|
||||
let(:boxes) { Vagrant::BoxCollection.new(iso_env.boxes_dir) }
|
||||
let(:data_path) { Pathname.new(Dir.mktmpdir) }
|
||||
let(:data_path) { Pathname.new(Dir.mktmpdir("vagrant-machine-data-path")) }
|
||||
let(:env) { iso_env.create_vagrant_env }
|
||||
let(:iso_env) { isolated_environment }
|
||||
let(:vagrantfile) { described_class.new(loader, keys) }
|
||||
|
@ -86,6 +86,10 @@ describe Vagrant::Vagrantfile do
|
|||
VF
|
||||
end
|
||||
|
||||
after do
|
||||
FileUtils.rm_rf(data_path.to_s)
|
||||
end
|
||||
|
||||
describe '#data_dir' do
|
||||
subject { super().data_dir }
|
||||
it { should eq(data_path) }
|
||||
|
|
Loading…
Reference in New Issue