spec/beaker/hypervisor/vagrant_spec.rb in beaker-2.44.0 vs spec/beaker/hypervisor/vagrant_spec.rb in beaker-2.45.0
- old
+ new
@@ -16,10 +16,15 @@
before :each do
@hosts = make_hosts({
:mount_folders => {
:test_temp => {:from => './', :to => '/temp'},
:test_tmp => {:from => '../', :to => '/tmp'}
+ },
+ :forwarded_ports => {
+ :http => {:from => 10080, :to => 80},
+ :ssl => {:from => 4443, :to => 443},
+ :tomcat => {:from => 8080, :to => 8080}
}
})
end
it "stores the vagrant file in $WORKINGDIR/.vagrant/beaker_vagrant_files/sample.cfg" do
@@ -47,10 +52,13 @@
v.vm.box_url = 'http://address.for.my.box.vm1'
v.vm.box_check_update = 'true'
v.vm.network :private_network, ip: "ip.address.for.vm1", :netmask => "255.255.0.0", :mac => "0123456789"
v.vm.synced_folder './', '/temp', create: true
v.vm.synced_folder '../', '/tmp', create: true
+ v.vm.network :forwarded_port, guest: 80, host: 10080
+ v.vm.network :forwarded_port, guest: 443, host: 4443
+ v.vm.network :forwarded_port, guest: 8080, host: 8080
v.vm.provider :virtualbox do |vb|
vb.customize ['modifyvm', :id, '--memory', '1024', '--cpus', '1']
end
end
c.vm.define 'vm2' do |v|
@@ -59,10 +67,13 @@
v.vm.box_url = 'http://address.for.my.box.vm2'
v.vm.box_check_update = 'true'
v.vm.network :private_network, ip: "ip.address.for.vm2", :netmask => "255.255.0.0", :mac => "0123456789"
v.vm.synced_folder './', '/temp', create: true
v.vm.synced_folder '../', '/tmp', create: true
+ v.vm.network :forwarded_port, guest: 80, host: 10080
+ v.vm.network :forwarded_port, guest: 443, host: 4443
+ v.vm.network :forwarded_port, guest: 8080, host: 8080
v.vm.provider :virtualbox do |vb|
vb.customize ['modifyvm', :id, '--memory', '1024', '--cpus', '1']
end
end
c.vm.define 'vm3' do |v|
@@ -71,10 +82,13 @@
v.vm.box_url = 'http://address.for.my.box.vm3'
v.vm.box_check_update = 'true'
v.vm.network :private_network, ip: "ip.address.for.vm3", :netmask => "255.255.0.0", :mac => "0123456789"
v.vm.synced_folder './', '/temp', create: true
v.vm.synced_folder '../', '/tmp', create: true
+ v.vm.network :forwarded_port, guest: 80, host: 10080
+ v.vm.network :forwarded_port, guest: 443, host: 4443
+ v.vm.network :forwarded_port, guest: 8080, host: 8080
v.vm.provider :virtualbox do |vb|
vb.customize ['modifyvm', :id, '--memory', '1024', '--cpus', '1']
end
end
end
@@ -148,9 +162,94 @@
match = generated_file.match(/vb.customize \['modifyvm', :id, '--memory', '1024', '--cpus', 'goodbye!'\]/)
expect( match ).to_not be nil
+ end
+
+ context "port forwarding rules" do
+ it "supports all Vagrant parameters" do
+ path = vagrant.instance_variable_get( :@vagrant_path )
+ allow( vagrant ).to receive( :randmac ).and_return( "0123456789" )
+
+ hosts = make_hosts(
+ {
+ :forwarded_ports => {
+ :http => {
+ :from => 10080,
+ :from_ip => '127.0.0.1',
+ :to => 80,
+ :to_ip => '0.0.0.0',
+ :protocol => 'udp'
+ }
+ }
+ },1)
+ vagrant.make_vfile( hosts, options )
+
+ vagrantfile = File.read( File.expand_path( File.join( path, "Vagrantfile")))
+ expect( vagrantfile ).to match(/v.vm.network :forwarded_port, protocol: 'udp', guest_ip: '0.0.0.0', guest: 80, host_ip: '127.0.0.1', host: 10080/)
+ end
+
+ it "supports supports from_ip" do
+ path = vagrant.instance_variable_get( :@vagrant_path )
+ allow( vagrant ).to receive( :randmac ).and_return( "0123456789" )
+
+ hosts = make_hosts(
+ {
+ :forwarded_ports => {
+ :http => {
+ :from => 10080,
+ :from_ip => '127.0.0.1',
+ :to => 80,
+ }
+ }
+ },1)
+ vagrant.make_vfile( hosts, options )
+
+ vagrantfile = File.read( File.expand_path( File.join( path, "Vagrantfile")))
+ expect( vagrantfile ).to match(/v.vm.network :forwarded_port, guest: 80, host_ip: '127.0.0.1', host: 10080/)
+ end
+
+ it "supports all to_ip" do
+ path = vagrant.instance_variable_get( :@vagrant_path )
+ allow( vagrant ).to receive( :randmac ).and_return( "0123456789" )
+
+ hosts = make_hosts(
+ {
+ :forwarded_ports => {
+ :http => {
+ :from => 10080,
+ :to => 80,
+ :to_ip => '0.0.0.0',
+ }
+ }
+ },1)
+ vagrant.make_vfile( hosts, options )
+
+ vagrantfile = File.read( File.expand_path( File.join( path, "Vagrantfile")))
+ expect( vagrantfile ).to match(/v.vm.network :forwarded_port, guest_ip: '0.0.0.0', guest: 80, host: 10080/)
+ end
+
+ it "supports all protocol" do
+ path = vagrant.instance_variable_get( :@vagrant_path )
+ allow( vagrant ).to receive( :randmac ).and_return( "0123456789" )
+
+ hosts = make_hosts(
+ {
+ :forwarded_ports => {
+ :http => {
+ :from => 10080,
+ :to => 80,
+ :protocol => 'udp'
+ }
+ }
+ },1)
+ vagrant.make_vfile( hosts, options )
+
+ vagrantfile = File.read( File.expand_path( File.join( path, "Vagrantfile")))
+ expect( vagrantfile ).to match(/v.vm.network :forwarded_port, protocol: 'udp', guest: 80, host: 10080/)
+
+ end
end
it "can generate a new /etc/hosts file referencing each host" do
@hosts.each do |host|