Merge pull request #7623 from carlosefr/relative-dotfile-path
Support Vagrantfile-relative VAGRANT_DOTFILE_PATHs
This commit is contained in:
commit
3abfbec5a6
|
@ -157,13 +157,19 @@ module Vagrant
|
||||||
end
|
end
|
||||||
|
|
||||||
# Setup the local data directory. If a configuration path is given,
|
# Setup the local data directory. If a configuration path is given,
|
||||||
# then it is expanded relative to the working directory. Otherwise,
|
# it is expanded relative to the root path. Otherwise, we use the
|
||||||
# we use the default which is expanded relative to the root path.
|
# default (which is also expanded relative to the root path).
|
||||||
opts[:local_data_path] ||= ENV["VAGRANT_DOTFILE_PATH"] if !opts[:child]
|
if !root_path.nil?
|
||||||
opts[:local_data_path] ||= root_path.join(DEFAULT_LOCAL_DATA) if !root_path.nil?
|
if !(ENV["VAGRANT_DOTFILE_PATH"] or "").empty? && !opts[:child]
|
||||||
|
opts[:local_data_path] ||= root_path.join(ENV["VAGRANT_DOTFILE_PATH"])
|
||||||
|
else
|
||||||
|
opts[:local_data_path] ||= root_path.join(DEFAULT_LOCAL_DATA)
|
||||||
|
end
|
||||||
|
end
|
||||||
if opts[:local_data_path]
|
if opts[:local_data_path]
|
||||||
@local_data_path = Pathname.new(File.expand_path(opts[:local_data_path], @cwd))
|
@local_data_path = Pathname.new(File.expand_path(opts[:local_data_path], @cwd))
|
||||||
end
|
end
|
||||||
|
@logger.debug("Effective local data path: #{@local_data_path}")
|
||||||
|
|
||||||
# If we have a root path, load the ".vagrantplugins" file.
|
# If we have a root path, load the ".vagrantplugins" file.
|
||||||
if root_path
|
if root_path
|
||||||
|
|
|
@ -921,6 +921,84 @@ VF
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context "with environmental variable VAGRANT_DOTFILE_PATH set to the empty string" do
|
||||||
|
it "is set to the default, from the work directory" do
|
||||||
|
with_temp_env("VAGRANT_DOTFILE_PATH" => "") do
|
||||||
|
instance = env.create_vagrant_env
|
||||||
|
expect(instance.cwd).to eq(env.workdir)
|
||||||
|
expect(instance.local_data_path.to_s).to eq(File.join(env.workdir, ".vagrant"))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
it "is set to the default, from a sub-directory of the work directory" do
|
||||||
|
Dir.mktmpdir("sub-directory", env.workdir) do |temp_dir|
|
||||||
|
with_temp_env("VAGRANT_DOTFILE_PATH" => "") do
|
||||||
|
instance = env.create_vagrant_env(cwd: temp_dir)
|
||||||
|
expect(instance.cwd.to_s).to eq(temp_dir)
|
||||||
|
expect(instance.local_data_path.to_s).to eq(File.join(env.workdir, ".vagrant"))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "with environmental variable VAGRANT_DOTFILE_PATH set to an absolute path" do
|
||||||
|
it "is set to VAGRANT_DOTFILE_PATH from the work directory" do
|
||||||
|
Dir.mktmpdir("sub-directory", env.workdir) do |temp_dir|
|
||||||
|
dotfile_path = File.join(temp_dir, ".vagrant-custom")
|
||||||
|
|
||||||
|
with_temp_env("VAGRANT_DOTFILE_PATH" => dotfile_path) do
|
||||||
|
instance = env.create_vagrant_env
|
||||||
|
expect(instance.cwd).to eq(env.workdir)
|
||||||
|
expect(instance.local_data_path.to_s).to eq(dotfile_path)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
it "is set to VAGRANT_DOTFILE_PATH from a sub-directory of the work directory" do
|
||||||
|
Dir.mktmpdir("sub-directory", env.workdir) do |temp_dir|
|
||||||
|
dotfile_path = File.join(temp_dir, ".vagrant-custom")
|
||||||
|
|
||||||
|
with_temp_env("VAGRANT_DOTFILE_PATH" => dotfile_path) do
|
||||||
|
instance = env.create_vagrant_env(cwd: temp_dir)
|
||||||
|
expect(instance.cwd.to_s).to eq(temp_dir)
|
||||||
|
expect(instance.local_data_path.to_s).to eq(dotfile_path)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "with environmental variable VAGRANT_DOTFILE_PATH set to a relative path" do
|
||||||
|
it "is set relative to the the work directory, from the work directory" do
|
||||||
|
Dir.mktmpdir("sub-directory", env.workdir) do |temp_dir|
|
||||||
|
with_temp_env("VAGRANT_DOTFILE_PATH" => ".vagrant-custom") do
|
||||||
|
instance = env.create_vagrant_env
|
||||||
|
expect(instance.cwd).to eq(env.workdir)
|
||||||
|
expect(instance.local_data_path.to_s).to eq(File.join(env.workdir, ".vagrant-custom"))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
it "is set relative to the the work directory, from a sub-directory of the work directory" do
|
||||||
|
Dir.mktmpdir("sub-directory", env.workdir) do |temp_dir|
|
||||||
|
with_temp_env("VAGRANT_DOTFILE_PATH" => ".vagrant-custom") do
|
||||||
|
instance = env.create_vagrant_env(cwd: temp_dir)
|
||||||
|
expect(instance.cwd.to_s).to eq(temp_dir)
|
||||||
|
expect(instance.local_data_path.to_s).to eq(File.join(env.workdir, ".vagrant-custom"))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
it "is set to the empty string when there is no valid work directory" do
|
||||||
|
Dir.mktmpdir("out-of-tree-directory") do |temp_dir|
|
||||||
|
with_temp_env("VAGRANT_DOTFILE_PATH" => ".vagrant-custom") do
|
||||||
|
instance = env.create_vagrant_env(cwd: temp_dir)
|
||||||
|
expect(instance.cwd.to_s).to eq(temp_dir)
|
||||||
|
expect(instance.local_data_path.to_s).to eq("")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
describe "upgrading V1 dotfiles" do
|
describe "upgrading V1 dotfiles" do
|
||||||
let(:v1_dotfile_tempfile) do
|
let(:v1_dotfile_tempfile) do
|
||||||
Tempfile.new("vagrant-upgrade-dotfile").tap do |f|
|
Tempfile.new("vagrant-upgrade-dotfile").tap do |f|
|
||||||
|
|
Loading…
Reference in New Issue