Add unit tests for shell_expand_guest_path function

This commit is contained in:
Brian Cain 2017-08-15 09:33:29 -07:00
parent 61c501cc65
commit 2b8f7f67ea
10 changed files with 221 additions and 5 deletions

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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