Improve Windows drive letter removal hack

This commit is contained in:
Julian Zinn 2018-02-19 20:33:37 -08:00 committed by Julian Zinn
parent 1cc4a48371
commit 269645f63d
2 changed files with 77 additions and 2 deletions

View File

@ -5,6 +5,7 @@ require "set"
require "log4r"
require "vagrant/util/counter"
require "vagrant/action/builtin/mixin_synced_folders"
require_relative "base"
@ -95,13 +96,12 @@ module VagrantPlugins
else
# Path already exists on the virtual machine. Expand it
# relative to where we're provisioning.
remote_path = File.expand_path(path, guest_provisioning_path)
# Remove drive letter if running on a windows host. This is a bit
# of a hack but is the most portable way I can think of at the moment
# to achieve this. Otherwise, Vagrant attempts to share at some crazy
# path like /home/vagrant/c:/foo/bar
remote_path = remote_path.gsub(/^[a-zA-Z]:/, "")
remote_path = File.expand_path(path.gsub(/^[a-zA-Z]:\//, "/"), guest_provisioning_path.gsub(/^[a-zA-Z]:\//, "/"))
end
# If we have specified a folder name to append then append it

View File

@ -0,0 +1,75 @@
require_relative "../../../../base"
require Vagrant.source_root.join("plugins/provisioners/chef/provisioner/chef_solo")
describe VagrantPlugins::Chef::Provisioner::ChefSolo do
include_context "unit"
let(:iso_env) do
# We have to create a Vagrantfile so there is a root path
env = isolated_environment
env.vagrantfile("")
env.create_vagrant_env
end
let(:machine) { iso_env.machine(iso_env.machine_names[0], :dummy) }
let(:config) { double("config") }
subject { described_class.new(machine, config) }
before do
allow(config).to receive(:node_name)
allow(config).to receive(:node_name=)
end
describe "#expanded_folders" do
it "handles the default Windows provisioning path" do
allow(config).to receive(:provisioning_path).and_return(nil)
allow(subject).to receive(:windows?).and_return(true)
remote_path = subject.expanded_folders([[:vm, "cookbooks-1"]])[0][2]
expect(remote_path).to eq("/vagrant-chef/cookbooks-1")
end
end
describe "#expanded_folders" do
it "expands Windows absolute provisioning path with relative path" do
provisioning_path = "C:/vagrant-chef-1"
unexpanded_path = "cookbooks-1"
allow(config).to receive(:provisioning_path).and_return(provisioning_path)
remote_path = subject.expanded_folders([[:vm, unexpanded_path]])[0][2]
expect(remote_path).to eq("/vagrant-chef-1/cookbooks-1")
end
it "expands Windows absolute provisioning path with absolute path" do
provisioning_path = "C:/vagrant-chef-1"
unexpanded_path = "/cookbooks-1"
allow(config).to receive(:provisioning_path).and_return(provisioning_path)
remote_path = subject.expanded_folders([[:vm, unexpanded_path]])[0][2]
expect(remote_path).to eq("/cookbooks-1")
end
it "expands Windows absolute provisioning path with Windows absolute path" do
provisioning_path = "C:/vagrant-chef-1"
unexpanded_path = "D:/cookbooks-1"
allow(config).to receive(:provisioning_path).and_return(provisioning_path)
remote_path = subject.expanded_folders([[:vm, unexpanded_path]])[0][2]
expect(remote_path).to eq("/cookbooks-1")
end
it "expands absolute provisioning path with Windows absolute path" do
provisioning_path = "/vagrant-chef-1"
unexpanded_path = "D:/cookbooks-1"
allow(config).to receive(:provisioning_path).and_return(provisioning_path)
remote_path = subject.expanded_folders([[:vm, unexpanded_path]])[0][2]
expect(remote_path).to eq("/cookbooks-1")
end
end
end