Forwarding ports now clears old ports first
This commit is contained in:
parent
e825847dac
commit
e8e07d26f5
|
@ -2,6 +2,16 @@ module Vagrant
|
||||||
module Actions
|
module Actions
|
||||||
class ForwardPorts < Base
|
class ForwardPorts < Base
|
||||||
def execute!
|
def execute!
|
||||||
|
clear
|
||||||
|
forward_ports
|
||||||
|
end
|
||||||
|
|
||||||
|
def clear
|
||||||
|
logger.info "Deleting any previously set forwarded ports..."
|
||||||
|
@vm.vm.forwarded_ports.collect { |p| p.destroy(true) }
|
||||||
|
end
|
||||||
|
|
||||||
|
def forward_ports
|
||||||
logger.info "Forwarding ports..."
|
logger.info "Forwarding ports..."
|
||||||
|
|
||||||
Vagrant.config.vm.forwarded_ports.each do |name, options|
|
Vagrant.config.vm.forwarded_ports.each do |name, options|
|
||||||
|
|
|
@ -6,20 +6,45 @@ class ForwardPortsActionTest < Test::Unit::TestCase
|
||||||
mock_config
|
mock_config
|
||||||
end
|
end
|
||||||
|
|
||||||
should "create a port forwarding for the VM" do
|
context "execution" do
|
||||||
forwarded_ports = mock("forwarded_ports")
|
should "clear all previous ports and forward new ports" do
|
||||||
|
exec_seq = sequence("exec_seq")
|
||||||
Vagrant.config.vm.forwarded_ports.each do |name, opts|
|
@action.expects(:clear).once.in_sequence(exec_seq)
|
||||||
forwarded_ports.expects(:<<).with do |port|
|
@action.expects(:forward_ports).once.in_sequence(exec_seq)
|
||||||
assert_equal name, port.name
|
@action.execute!
|
||||||
assert_equal opts[:hostport], port.hostport
|
|
||||||
assert_equal opts[:guestport], port.guestport
|
|
||||||
true
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
@vm.expects(:forwarded_ports).returns(forwarded_ports)
|
context "forwarding ports" do
|
||||||
@vm.expects(:save).with(true).once
|
should "create a port forwarding for the VM" do
|
||||||
@action.execute!
|
forwarded_ports = mock("forwarded_ports")
|
||||||
|
|
||||||
|
Vagrant.config.vm.forwarded_ports.each do |name, opts|
|
||||||
|
forwarded_ports.expects(:<<).with do |port|
|
||||||
|
assert_equal name, port.name
|
||||||
|
assert_equal opts[:hostport], port.hostport
|
||||||
|
assert_equal opts[:guestport], port.guestport
|
||||||
|
true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
@vm.expects(:forwarded_ports).returns(forwarded_ports)
|
||||||
|
@vm.expects(:save).with(true).once
|
||||||
|
@action.forward_ports
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "clearing forwarded ports" do
|
||||||
|
should "call destroy on all forwarded ports" do
|
||||||
|
forwarded_ports = []
|
||||||
|
5.times do |i|
|
||||||
|
port = mock("port#{i}")
|
||||||
|
port.expects(:destroy).with(true).once
|
||||||
|
forwarded_ports << port
|
||||||
|
end
|
||||||
|
|
||||||
|
@vm.expects(:forwarded_ports).returns(forwarded_ports)
|
||||||
|
@action.clear
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue