- added shell_expand_guest_path capability for solaris11 - added tests for solaris11 shell_expand_guest_path capability
This commit is contained in:
parent
6ee180a023
commit
c4b16b509a
32
plugins/guests/solaris11/cap/shell_expand_guest_path.rb
Normal file
32
plugins/guests/solaris11/cap/shell_expand_guest_path.rb
Normal file
@ -0,0 +1,32 @@
|
||||
module VagrantPlugins
|
||||
module GuestSolaris11
|
||||
module Cap
|
||||
class ShellExpandGuestPath
|
||||
def self.shell_expand_guest_path(machine, path)
|
||||
real_path = nil
|
||||
path = path.gsub(/ /, '\ ')
|
||||
machine.communicate.execute("echo; printf #{path}") do |type, data|
|
||||
if type == :stdout
|
||||
real_path ||= ""
|
||||
real_path += data
|
||||
end
|
||||
end
|
||||
|
||||
if real_path
|
||||
# The last line is the path we care about
|
||||
real_path = real_path.split("\n").last.chomp
|
||||
end
|
||||
|
||||
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 Vagrant::Errors::ShellExpandFailed
|
||||
end
|
||||
|
||||
# Chomp the string so that any trailing newlines are killed
|
||||
return real_path.chomp
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -29,6 +29,11 @@ module VagrantPlugins
|
||||
require_relative "cap/configure_networks"
|
||||
Cap::ConfigureNetworks
|
||||
end
|
||||
|
||||
guest_capability(:solaris11, :shell_expand_guest_path) do
|
||||
require_relative "cap/shell_expand_guest_path"
|
||||
Cap::ShellExpandGuestPath
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@ -0,0 +1,52 @@
|
||||
require_relative "../../../../base"
|
||||
|
||||
describe "VagrantPlugins::GuestSolaris11::Cap::ShellExpandGuestPath" do
|
||||
let(:caps) do
|
||||
VagrantPlugins::GuestSolaris11::Plugin
|
||||
.components
|
||||
.guest_capabilities[:solaris11]
|
||||
end
|
||||
|
||||
let(:machine) { double("machine", config: double("config", solaris11: double("solaris11", suexec_cmd: 'sudo', device: 'net'))) }
|
||||
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 = "/export/home/vagrant/folder"
|
||||
allow(machine.communicate).to receive(:execute).
|
||||
with(any_args).and_yield(:stdout, "/export/home/vagrant/folder")
|
||||
|
||||
cap.shell_expand_guest_path(machine, path)
|
||||
end
|
||||
|
||||
it "expands a path with tilde" do
|
||||
path = "~/folder"
|
||||
allow(machine.communicate).to receive(:execute).
|
||||
with(any_args).and_yield(:stdout, "/export/home/vagrant/folder")
|
||||
|
||||
cap.shell_expand_guest_path(machine, path)
|
||||
end
|
||||
|
||||
it "raises an exception if no path was detected" do
|
||||
path = "/export/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 = "/export/home/vagrant folder/folder"
|
||||
path_with_spaces = "/export/home/vagrant\\ folder/folder"
|
||||
allow(machine.communicate).to receive(:execute).
|
||||
with(any_args).and_yield(:stdout, path_with_spaces)
|
||||
|
||||
expect(machine.communicate).to receive(:execute).with("printf #{path_with_spaces}")
|
||||
cap.shell_expand_guest_path(machine, path)
|
||||
end
|
||||
end
|
||||
end
|
||||
Loading…
x
Reference in New Issue
Block a user