Forwarding ports action
This commit is contained in:
parent
1a89e50da7
commit
0fa8a94f32
|
@ -0,0 +1,20 @@
|
|||
module Vagrant
|
||||
module Actions
|
||||
class ForwardPorts < Base
|
||||
def execute!
|
||||
logger.info "Forwarding ports..."
|
||||
|
||||
Vagrant.config.vm.forwarded_ports.each do |name, options|
|
||||
logger.info "Forwarding \"#{name}\": #{options[:guestport]} => #{options[:hostport]}"
|
||||
port = VirtualBox::ForwardedPort.new
|
||||
port.name = name
|
||||
port.hostport = options[:hostport]
|
||||
port.guestport = options[:guestport]
|
||||
@vm.forwarded_ports << port
|
||||
end
|
||||
|
||||
@vm.save(true)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,25 @@
|
|||
require File.join(File.dirname(__FILE__), '..', '..', 'test_helper')
|
||||
|
||||
class ForwardPortsActionTest < Test::Unit::TestCase
|
||||
setup do
|
||||
@mock_vm, @vm, @action = mock_action(Vagrant::Actions::ForwardPorts)
|
||||
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
|
||||
end
|
||||
|
||||
@mock_vm.expects(:forwarded_ports).returns(forwarded_ports)
|
||||
@mock_vm.expects(:save).with(true).once
|
||||
@action.execute!
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue