Sha256: 2a67682fbb071794f4738e8f17c3af922616bf977341daf275d8257a30302c1a

Contents?: true

Size: 1.97 KB

Versions: 101

Compression:

Stored size: 1.97 KB

Contents

require "test_helper"

class BootVMActionTest < Test::Unit::TestCase
  setup do
    @klass = Vagrant::Action::VM::Boot
    @app, @env = action_env

    @vm = mock("vm")
    @vm.stubs(:ssh).returns(mock("ssh"))
    @env["vm"] = @vm

    @internal_vm = mock("internal")
    @vm.stubs(:vm).returns(@internal_vm)

    @instance = @klass.new(@app, @env)
  end

  context "calling" do
    should "run the proper methods on success" do
      boot_seq = sequence("boot_seq")
      @instance.expects(:boot).in_sequence(boot_seq)
      @instance.expects(:wait_for_boot).returns(true).in_sequence(boot_seq)
      @app.expects(:call).with(@env).once.in_sequence(boot_seq)
      @instance.call(@env)
    end

    should "error and halt chain if boot failed" do
      boot_seq = sequence("boot_seq")
      @instance.expects(:boot).in_sequence(boot_seq)
      @instance.expects(:wait_for_boot).returns(false).in_sequence(boot_seq)
      @app.expects(:call).never
      assert_raises(Vagrant::Errors::VMFailedToBoot) {
        @instance.call(@env)
      }
    end
  end

  context "booting" do
    should "start the VM in specified mode" do
      mode = mock("boot_mode")
      @env.env.config.vm.boot_mode = mode
      @internal_vm.expects(:start).with(mode).once
      @instance.boot
    end
  end

  context "waiting for boot" do
    should "repeatedly ping the SSH port and return false with no response" do
      seq = sequence('pings')
      @vm.ssh.expects(:up?).times(@env.env.config.ssh.max_tries.to_i - 1).returns(false).in_sequence(seq)
      @vm.ssh.expects(:up?).once.returns(true).in_sequence(seq)
      assert @instance.wait_for_boot
    end

    should "return right away if interrupted" do
      @env.interrupt!
      @vm.ssh.expects(:up?).times(1).returns(false)
      assert @instance.wait_for_boot
    end

    should "ping the max number of times then just return" do
      @vm.ssh.expects(:up?).times(@env.env.config.ssh.max_tries.to_i).returns(false)
      assert !@instance.wait_for_boot
    end
  end
end

Version data entries

101 entries across 101 versions & 9 rubygems

Version Path
bmhatfield-vagrant-1.0.10 test/unit_legacy/vagrant/action/vm/boot_test.rb
bmhatfield-vagrant-1.0.9 test/unit_legacy/vagrant/action/vm/boot_test.rb
bmhatfield-vagrant-1.0.8 test/unit_legacy/vagrant/action/vm/boot_test.rb
bmhatfield-vagrant-1.0.7 test/unit_legacy/vagrant/action/vm/boot_test.rb
vagrantup-1.0.7 test/unit_legacy/vagrant/action/vm/boot_test.rb
vagrantup-1.0.6 test/unit_legacy/vagrant/action/vm/boot_test.rb
vagrantup-1.0.5 test/unit_legacy/vagrant/action/vm/boot_test.rb
vagrantup-1.0.4 test/unit_legacy/vagrant/action/vm/boot_test.rb
vagrantup-1.0.3 test/unit_legacy/vagrant/action/vm/boot_test.rb
vagrantup-1.0.2 test/unit_legacy/vagrant/action/vm/boot_test.rb
vagrantup-1.0.1 test/unit_legacy/vagrant/action/vm/boot_test.rb
vagrantup-1.0.0 test/unit_legacy/vagrant/action/vm/boot_test.rb
vagrantup-0.9.99.2 test/unit_legacy/vagrant/action/vm/boot_test.rb
vagrantup-0.9.99.1 test/unit_legacy/vagrant/action/vm/boot_test.rb
vagrantup-0.9.7 test/unit_legacy/vagrant/action/vm/boot_test.rb
vagrantup-0.9.6 test/unit_legacy/vagrant/action/vm/boot_test.rb
vagrantup-0.9.5 test/unit_legacy/vagrant/action/vm/boot_test.rb
vagrantup-0.9.4 test/unit_legacy/vagrant/action/vm/boot_test.rb
vagrantup-0.9.3 test/unit_legacy/vagrant/action/vm/boot_test.rb
vagrantup-0.9.2 test/unit_legacy/vagrant/action/vm/boot_test.rb