spec/beaker/hypervisor/vagrant_spec.rb in beaker-1.6.2 vs spec/beaker/hypervisor/vagrant_spec.rb in beaker-1.7.0

- old
+ new

@@ -26,10 +26,25 @@ vagrant.make_vfile( @hosts ) expect( File.read( File.expand_path( File.join( path, "Vagrantfile") ) ) ).to be === "Vagrant.configure(\"2\") do |c|\n c.vm.define 'vm1' do |v|\n v.vm.hostname = 'vm1'\n v.vm.box = 'vm1_of_my_box'\n v.vm.box_url = 'http://address.for.my.box.vm1'\n v.vm.base_mac = '0123456789'\n v.vm.network :private_network, ip: \"ip.address.for.vm1\", :netmask => \"255.255.0.0\"\n end\n c.vm.define 'vm2' do |v|\n v.vm.hostname = 'vm2'\n v.vm.box = 'vm2_of_my_box'\n v.vm.box_url = 'http://address.for.my.box.vm2'\n v.vm.base_mac = '0123456789'\n v.vm.network :private_network, ip: \"ip.address.for.vm2\", :netmask => \"255.255.0.0\"\n end\n c.vm.define 'vm3' do |v|\n v.vm.hostname = 'vm3'\n v.vm.box = 'vm3_of_my_box'\n v.vm.box_url = 'http://address.for.my.box.vm3'\n v.vm.base_mac = '0123456789'\n v.vm.network :private_network, ip: \"ip.address.for.vm3\", :netmask => \"255.255.0.0\"\n end\n c.vm.provider :virtualbox do |vb|\n vb.customize [\"modifyvm\", :id, \"--memory\", \"1024\"]\n end\nend\n" end + it "uses the memsize defined per vagrant host" do + FakeFS.activate! + path = vagrant.instance_variable_get( :@vagrant_path ) + vagrant.stub( :randmac ).and_return( "0123456789" ) + + vagrant.make_vfile( @hosts, {'vagrant_memsize' => 'hello!'} ) + + generated_file = File.read( File.expand_path( File.join( path, "Vagrantfile") ) ) + + match = generated_file.match(/vb.customize \["modifyvm", :id, "--memory", "hello!"]/) + + expect( match ).to_not be nil + + end + it "can generate a new /etc/hosts file referencing each host" do @hosts.each do |host| vagrant.should_receive( :set_etc_hosts ).with( host, "127.0.0.1\tlocalhost localhost.localdomain\nip.address.for.vm1\tvm1\nip.address.for.vm2\tvm2\nip.address.for.vm3\tvm3\n" ).once end @@ -64,27 +79,20 @@ it "can generate a ssh-config file" do host = @hosts[0] name = host.name Dir.stub( :chdir ).and_yield() - out = double( 'stdout' ) - out.stub( :read ).and_return("Host #{host.name} + vagrant.should_receive(:`).and_return("Host #{host.name} HostName 127.0.0.1 User vagrant Port 2222 UserKnownHostsFile /dev/null StrictHostKeyChecking no PasswordAuthentication no IdentityFile /home/root/.vagrant.d/insecure_private_key IdentitiesOnly yes") - wait_thr = OpenStruct.new - state = mock( 'state' ) - state.stub( :success? ).and_return( true ) - wait_thr.value = state - Open3.stub( :popen3 ).with( 'vagrant', 'ssh-config', host.name ).and_return( [ "", out, "", wait_thr ]) - file = double( 'file' ) file.stub( :path ).and_return( '/path/sshconfig' ) file.stub( :rewind ).and_return( true ) Tempfile.should_receive( :new ).with( "#{host.name}").and_return( file ) @@ -137,17 +145,18 @@ end vagrant.should_receive( :hack_etc_hosts ).with( @hosts ).once end it "can provision a set of hosts" do - vagrant.should_receive( :make_vfile ).with( @hosts ).once + options = vagrant.instance_variable_get( :@options ) + vagrant.should_receive( :make_vfile ).with( @hosts, options ).once vagrant.should_receive( :vagrant_cmd ).with( "destroy --force" ).never vagrant.provision end it "destroys an existing set of hosts before provisioning" do - vagrant.make_vfile(@hosts) - vagrant.should_receive(:vagrant_cmd).with("destroy --force").once + vagrant.make_vfile( @hosts ) + vagrant.should_receive( :vagrant_cmd ).with( "destroy --force" ).once vagrant.provision end it "can cleanup" do vagrant.should_receive( :vagrant_cmd ).with( "destroy --force" ).once