spec/beaker/hypervisor/vagrant_spec.rb in beaker-3.6.0 vs spec/beaker/hypervisor/vagrant_spec.rb in beaker-3.7.0
- old
+ new
@@ -145,29 +145,36 @@
vagrantfile = File.read( File.expand_path( File.join( path, "Vagrantfile")))
expect( vagrantfile ).to match(/v.vm.network :private_network, ip: "ip.address.for.vm1", :netmask => "255.255.0.0"/)
end
- it "generates a valid windows config" do
- path = vagrant.instance_variable_get( :@vagrant_path )
- allow( vagrant ).to receive( :randmac ).and_return( "0123456789" )
- @hosts[0][:platform] = 'windows'
+ context "when generating a windows config" do
+ before do
+ path = vagrant.instance_variable_get( :@vagrant_path )
+ allow( vagrant ).to receive( :randmac ).and_return( "0123456789" )
+ @hosts[0][:platform] = 'windows'
- vagrant.make_vfile( @hosts )
+ vagrant.make_vfile( @hosts )
- generated_file = File.read( File.expand_path( File.join( path, "Vagrantfile") ) )
+ @generated_file = File.read( File.expand_path( File.join( path, "Vagrantfile") ) )
+ end
- match = generated_file.match(/v.vm.network :forwarded_port, guest: 3389, host: 3389, id: 'rdp', auto_correct: true/)
- expect( match ).to_not be_nil,'Should have proper port for RDP'
+ it 'has the proper port forwarding for RDP' do
+ expect( @generated_file ).to match /v.vm.network :forwarded_port, guest: 3389, host: 3389, id: 'rdp', auto_correct: true/
+ end
- match = generated_file.match(/v.vm.network :forwarded_port, guest: 5985, host: 5985, id: 'winrm', auto_correct: true/)
- expect( match ).to_not be_nil, "Should have proper port for WinRM"
+ it 'has the proper port forwarding for WinRM' do
+ expect( @generated_file ).to match /v.vm.network :forwarded_port, guest: 5985, host: 5985, id: 'winrm', auto_correct: true/
+ end
- match = generated_file.match(/v.vm.guest = :windows/)
- expect( match ).to_not be_nil, 'Should correctly identify guest OS so Vagrant can act accordingly'
+ it 'configures the guest type to windows' do
+ expect( @generated_file ).to match /v.vm.guest = :windows/
+ end
-
+ it 'sets a non-default memsize' do
+ expect( @generated_file ).to match /'--memory', '2048',/
+ end
end
it "uses the memsize defined per vagrant host" do
path = vagrant.instance_variable_get( :@vagrant_path )
allow( vagrant ).to receive( :randmac ).and_return( "0123456789" )
@@ -380,11 +387,11 @@
end
it "raises an error if no Vagrantfile is present" do
File.delete( vagrant.instance_variable_get( :@vagrant_file ) )
@hosts.each do |host|
- expect{ vagrant.get_ip_from_vagrant_file(host.name) }.to raise_error
+ expect{ vagrant.get_ip_from_vagrant_file(host.name) }.to raise_error RuntimeError, /No vagrant file found/
end
end
end
describe "provisioning and cleanup" do
@@ -394,9 +401,45 @@
@hosts.each do |host|
host_prev_name = host['user']
expect( vagrant ).to receive( :set_ssh_config ).with( host, 'vagrant' ).once
expect( vagrant ).to receive( :copy_ssh_to_root ).with( host, options ).once
expect( vagrant ).to receive( :set_ssh_config ).with( host, host_prev_name ).once
+ end
+ expect( vagrant ).to receive( :hack_etc_hosts ).with( @hosts, options ).once
+ end
+
+ it "can provision a set of hosts" do
+ options = vagrant.instance_variable_get( :@options )
+ expect( vagrant ).to receive( :make_vfile ).with( @hosts, options ).once
+ expect( vagrant ).to receive( :vagrant_cmd ).with( "destroy --force" ).never
+ vagrant.provision
+ end
+
+ it "destroys an existing set of hosts before provisioning" do
+ vagrant.make_vfile( @hosts )
+ expect( vagrant ).to receive( :vagrant_cmd ).with( "destroy --force" ).once
+ vagrant.provision
+ end
+
+ it "can cleanup" do
+ expect( vagrant ).to receive( :vagrant_cmd ).with( "destroy --force" ).once
+ expect( FileUtils ).to receive( :rm_rf ).once
+
+ vagrant.provision
+ vagrant.cleanup
+
+ end
+
+ end
+
+ describe "provisioning and cleanup on windows" do
+ before :each do
+ expect( vagrant ).to receive( :vagrant_cmd ).with( "up" ).once
+ @hosts.each do |host|
+ host_prev_name = host['user']
+ expect( vagrant ).to receive( :set_ssh_config ).with( host, 'vagrant' ).once
+ expect( vagrant ).not_to receive( :copy_ssh_to_root ).with( host, options ).once
+ expect( vagrant ).not_to receive( :set_ssh_config ).with( host, host_prev_name ).once
end
expect( vagrant ).to receive( :hack_etc_hosts ).with( @hosts, options ).once
end
it "can provision a set of hosts" do