Forwarding ports now clears old ports first
This commit is contained in:
parent
e825847dac
commit
e8e07d26f5
|
@ -2,6 +2,16 @@ module Vagrant
|
|||
module Actions
|
||||
class ForwardPorts < Base
|
||||
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..."
|
||||
|
||||
Vagrant.config.vm.forwarded_ports.each do |name, options|
|
||||
|
|
|
@ -6,20 +6,45 @@ class ForwardPortsActionTest < Test::Unit::TestCase
|
|||
mock_config
|
||||
end
|
||||
|
||||
should "create a port forwarding for the VM" do
|
||||
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
|
||||
context "execution" do
|
||||
should "clear all previous ports and forward new ports" do
|
||||
exec_seq = sequence("exec_seq")
|
||||
@action.expects(:clear).once.in_sequence(exec_seq)
|
||||
@action.expects(:forward_ports).once.in_sequence(exec_seq)
|
||||
@action.execute!
|
||||
end
|
||||
end
|
||||
|
||||
@vm.expects(:forwarded_ports).returns(forwarded_ports)
|
||||
@vm.expects(:save).with(true).once
|
||||
@action.execute!
|
||||
context "forwarding ports" do
|
||||
should "create a port forwarding for the VM" do
|
||||
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
|
||||
|
|
Loading…
Reference in New Issue