Check for nil return from forwarded ports cap
Nil may be returned if the forwarded ports cap is called while the machine is not in a running state.
This commit is contained in:
parent
2063111ab5
commit
649f69747f
@ -58,7 +58,7 @@ module VagrantPlugins
|
||||
# ports.
|
||||
port = nil
|
||||
if machine.provider.capability?(:forwarded_ports)
|
||||
machine.provider.capability(:forwarded_ports).each do |host, guest|
|
||||
Array(machine.provider.capability(:forwarded_ports)).each do |host, guest|
|
||||
if guest == machine.config.winrm.guest_port
|
||||
port = host
|
||||
break
|
||||
|
||||
@ -147,6 +147,15 @@ describe VagrantPlugins::CommunicatorWinRM::Helper do
|
||||
|
||||
expect(subject.winrm_port(machine)).to eq(2456)
|
||||
end
|
||||
|
||||
it "does not error when the provider capability returns nil result" do
|
||||
machine.config.winrm.port = 22
|
||||
machine.config.winrm.guest_port = 2222
|
||||
machine.config.vm.network "forwarded_port", host: 1234, guest: 2222
|
||||
allow(machine.provider).to receive(:capability).with(:forwarded_ports).and_return(nil)
|
||||
|
||||
expect(subject.winrm_port(machine)).to eq(1234)
|
||||
end
|
||||
end
|
||||
|
||||
describe ".winrm_info_invalid?" do
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user