diff --git a/plugins/guests/darwin/cap/shell_expand_guest_path.rb b/plugins/guests/darwin/cap/shell_expand_guest_path.rb index 3bf439ef9..22c7bd11a 100644 --- a/plugins/guests/darwin/cap/shell_expand_guest_path.rb +++ b/plugins/guests/darwin/cap/shell_expand_guest_path.rb @@ -14,7 +14,7 @@ module VagrantPlugins if !real_path # If no real guest path was detected, this is really strange # and we raise an exception because this is a bug. - raise ShellExpandFailed + raise Vagrant::Errors::ShellExpandFailed end # Chomp the string so that any trailing newlines are killed diff --git a/plugins/guests/freebsd/cap/shell_expand_guest_path.rb b/plugins/guests/freebsd/cap/shell_expand_guest_path.rb index 854a2eef8..14ae7184d 100644 --- a/plugins/guests/freebsd/cap/shell_expand_guest_path.rb +++ b/plugins/guests/freebsd/cap/shell_expand_guest_path.rb @@ -15,7 +15,7 @@ module VagrantPlugins if !real_path # If no real guest path was detected, this is really strange # and we raise an exception because this is a bug. - raise ShellExpandFailed + raise Vagrant::Errors::ShellExpandFailed end # Chomp the string so that any trailing newlines are killed diff --git a/plugins/guests/linux/cap/shell_expand_guest_path.rb b/plugins/guests/linux/cap/shell_expand_guest_path.rb index 9065873b2..653068a78 100644 --- a/plugins/guests/linux/cap/shell_expand_guest_path.rb +++ b/plugins/guests/linux/cap/shell_expand_guest_path.rb @@ -19,7 +19,7 @@ module VagrantPlugins if !real_path # If no real guest path was detected, this is really strange # and we raise an exception because this is a bug. - raise ShellExpandFailed + raise Vagrant::Errors::ShellExpandFailed end # Chomp the string so that any trailing newlines are killed diff --git a/plugins/guests/netbsd/cap/shell_expand_guest_path.rb b/plugins/guests/netbsd/cap/shell_expand_guest_path.rb index 4dce5e2d6..007c5f944 100644 --- a/plugins/guests/netbsd/cap/shell_expand_guest_path.rb +++ b/plugins/guests/netbsd/cap/shell_expand_guest_path.rb @@ -14,7 +14,7 @@ module VagrantPlugins if !real_path # If no real guest path was detected, this is really strange # and we raise an exception because this is a bug. - raise ShellExpandFailed + raise Vagrant::Errors::ShellExpandFailed end # Chomp the string so that any trailing newlines are killed diff --git a/plugins/guests/openbsd/cap/shell_expand_guest_path.rb b/plugins/guests/openbsd/cap/shell_expand_guest_path.rb index b1a82813f..2a4f8b5ed 100644 --- a/plugins/guests/openbsd/cap/shell_expand_guest_path.rb +++ b/plugins/guests/openbsd/cap/shell_expand_guest_path.rb @@ -14,7 +14,7 @@ module VagrantPlugins if !real_path # If no real guest path was detected, this is really strange # and we raise an exception because this is a bug. - raise ShellExpandFailed + raise Vagrant::Errors::ShellExpandFailed end # Chomp the string so that any trailing newlines are killed diff --git a/test/unit/plugins/guests/darwin/cap/shell_expand_guest_path_test.rb b/test/unit/plugins/guests/darwin/cap/shell_expand_guest_path_test.rb new file mode 100644 index 000000000..fbbc45588 --- /dev/null +++ b/test/unit/plugins/guests/darwin/cap/shell_expand_guest_path_test.rb @@ -0,0 +1,43 @@ +require_relative "../../../../base" + +describe "VagrantPlugins::GuestDarwin::Cap::ShellExpandGuestPath" do + let(:caps) do + VagrantPlugins::GuestDarwin::Plugin + .components + .guest_capabilities[:darwin] + end + + let(:machine) { double("machine") } + let(:comm) { VagrantTests::DummyCommunicator::Communicator.new(machine) } + + before do + allow(machine).to receive(:communicate).and_return(comm) + end + + describe "#shell_expand_guest_path" do + let(:cap) { caps.get(:shell_expand_guest_path) } + + it "expands the path" do + path = "/home/vagrant/folder" + allow(machine.communicate).to receive(:execute). + with(any_args).and_yield(:stdout, "/home/vagrant/folder") + + cap.shell_expand_guest_path(machine, path) + end + + it "raises an exception if no path was detected" do + path = "/home/vagrant/folder" + expect { cap.shell_expand_guest_path(machine, path) }. + to raise_error(Vagrant::Errors::ShellExpandFailed) + end + + it "returns a path with a space in it" do + path = "/home/vagrant folder/folder" + allow(machine.communicate).to receive(:execute). + with(any_args).and_yield(:stdout, "/home/vagrant folder/folder") + + expect(machine.communicate).to receive(:execute).with("printf \"#{path}\"") + cap.shell_expand_guest_path(machine, path) + end + end +end diff --git a/test/unit/plugins/guests/freebsd/cap/shell_expand_guest_path_test.rb b/test/unit/plugins/guests/freebsd/cap/shell_expand_guest_path_test.rb new file mode 100644 index 000000000..2f10f8663 --- /dev/null +++ b/test/unit/plugins/guests/freebsd/cap/shell_expand_guest_path_test.rb @@ -0,0 +1,44 @@ +require_relative "../../../../base" + +describe "VagrantPlugins::GuestFreeBSD::Cap::ShellExpandGuestPath" do + let(:caps) do + VagrantPlugins::GuestFreeBSD::Plugin + .components + .guest_capabilities[:freebsd] + end + + let(:machine) { double("machine") } + let(:comm) { VagrantTests::DummyCommunicator::Communicator.new(machine) } + + before do + allow(machine).to receive(:communicate).and_return(comm) + end + + describe "#shell_expand_guest_path" do + let(:cap) { caps.get(:shell_expand_guest_path) } + + it "expands the path" do + path = "/home/vagrant/folder" + allow(machine.communicate).to receive(:execute). + with(any_args).and_yield(:stdout, "/home/vagrant/folder") + + cap.shell_expand_guest_path(machine, path) + end + + it "raises an exception if no path was detected" do + path = "/home/vagrant/folder" + expect { cap.shell_expand_guest_path(machine, path) }. + to raise_error(Vagrant::Errors::ShellExpandFailed) + end + + it "returns a path with a space in it" do + path = "/home/vagrant folder/folder" + allow(machine.communicate).to receive(:execute). + with(any_args).and_yield(:stdout, "/home/vagrant folder/folder") + + expect(machine.communicate).to receive(:execute) + .with("printf \"#{path}\"", {:shell=>"sh"}) + cap.shell_expand_guest_path(machine, path) + end + end +end diff --git a/test/unit/plugins/guests/linux/cap/shell_expand_guest_path_test.rb b/test/unit/plugins/guests/linux/cap/shell_expand_guest_path_test.rb new file mode 100644 index 000000000..0caf4ae1d --- /dev/null +++ b/test/unit/plugins/guests/linux/cap/shell_expand_guest_path_test.rb @@ -0,0 +1,43 @@ +require_relative "../../../../base" + +describe "VagrantPlugins::GuestLinux::Cap::ShellExpandGuestPath" do + let(:caps) do + VagrantPlugins::GuestLinux::Plugin + .components + .guest_capabilities[:linux] + end + + let(:machine) { double("machine") } + let(:comm) { VagrantTests::DummyCommunicator::Communicator.new(machine) } + + before do + allow(machine).to receive(:communicate).and_return(comm) + end + + describe "#shell_expand_guest_path" do + let(:cap) { caps.get(:shell_expand_guest_path) } + + it "expands the path" do + path = "/home/vagrant/folder" + allow(machine.communicate).to receive(:execute). + with(any_args).and_yield(:stdout, "/home/vagrant/folder") + + cap.shell_expand_guest_path(machine, path) + end + + it "raises an exception if no path was detected" do + path = "/home/vagrant/folder" + expect { cap.shell_expand_guest_path(machine, path) }. + to raise_error(Vagrant::Errors::ShellExpandFailed) + end + + it "returns a path with a space in it" do + path = "/home/vagrant folder/folder" + allow(machine.communicate).to receive(:execute). + with(any_args).and_yield(:stdout, "/home/vagrant folder/folder") + + expect(machine.communicate).to receive(:execute).with("echo; printf \"#{path}\"") + cap.shell_expand_guest_path(machine, path) + end + end +end diff --git a/test/unit/plugins/guests/netbsd/cap/shell_expand_guest_path_test.rb b/test/unit/plugins/guests/netbsd/cap/shell_expand_guest_path_test.rb new file mode 100644 index 000000000..49e4e6305 --- /dev/null +++ b/test/unit/plugins/guests/netbsd/cap/shell_expand_guest_path_test.rb @@ -0,0 +1,43 @@ +require_relative "../../../../base" + +describe "VagrantPlugins::GuestNetBSD::Cap::ShellExpandGuestPath" do + let(:caps) do + VagrantPlugins::GuestNetBSD::Plugin + .components + .guest_capabilities[:netbsd] + end + + let(:machine) { double("machine") } + let(:comm) { VagrantTests::DummyCommunicator::Communicator.new(machine) } + + before do + allow(machine).to receive(:communicate).and_return(comm) + end + + describe "#shell_expand_guest_path" do + let(:cap) { caps.get(:shell_expand_guest_path) } + + it "expands the path" do + path = "/home/vagrant/folder" + allow(machine.communicate).to receive(:execute). + with(any_args).and_yield(:stdout, "/home/vagrant/folder") + + cap.shell_expand_guest_path(machine, path) + end + + it "raises an exception if no path was detected" do + path = "/home/vagrant/folder" + expect { cap.shell_expand_guest_path(machine, path) }. + to raise_error(Vagrant::Errors::ShellExpandFailed) + end + + it "returns a path with a space in it" do + path = "/home/vagrant folder/folder" + allow(machine.communicate).to receive(:execute). + with(any_args).and_yield(:stdout, "/home/vagrant folder/folder") + + expect(machine.communicate).to receive(:execute).with("printf \"#{path}\"") + cap.shell_expand_guest_path(machine, path) + end + end +end diff --git a/test/unit/plugins/guests/openbsd/cap/shell_expand_guest_path_test.rb b/test/unit/plugins/guests/openbsd/cap/shell_expand_guest_path_test.rb new file mode 100644 index 000000000..1cd787911 --- /dev/null +++ b/test/unit/plugins/guests/openbsd/cap/shell_expand_guest_path_test.rb @@ -0,0 +1,43 @@ +require_relative "../../../../base" + +describe "VagrantPlugins::GuestOpenBSD::Cap::ShellExpandGuestPath" do + let(:caps) do + VagrantPlugins::GuestOpenBSD::Plugin + .components + .guest_capabilities[:openbsd] + end + + let(:machine) { double("machine") } + let(:comm) { VagrantTests::DummyCommunicator::Communicator.new(machine) } + + before do + allow(machine).to receive(:communicate).and_return(comm) + end + + describe "#shell_expand_guest_path" do + let(:cap) { caps.get(:shell_expand_guest_path) } + + it "expands the path" do + path = "/home/vagrant/folder" + allow(machine.communicate).to receive(:execute). + with(any_args).and_yield(:stdout, "/home/vagrant/folder") + + cap.shell_expand_guest_path(machine, path) + end + + it "raises an exception if no path was detected" do + path = "/home/vagrant/folder" + expect { cap.shell_expand_guest_path(machine, path) }. + to raise_error(Vagrant::Errors::ShellExpandFailed) + end + + it "returns a path with a space in it" do + path = "/home/vagrant folder/folder" + allow(machine.communicate).to receive(:execute). + with(any_args).and_yield(:stdout, "/home/vagrant folder/folder") + + expect(machine.communicate).to receive(:execute).with("printf \"#{path}\"") + cap.shell_expand_guest_path(machine, path) + end + end +end