Sha256: e0e2816523a88e1b87633037d7629f137531f7962b487ca4f90d4ec3a6edb43f

Contents?: true

Size: 1.76 KB

Versions: 4

Compression:

Stored size: 1.76 KB

Contents

require "test_helper"

class HaltVMActionTest < Test::Unit::TestCase
  setup do
    @klass = Vagrant::Action::VM::Halt
    @app, @env = mock_action_data

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

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

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

  context "initializing" do
    should "merge in the given options" do
      @klass.new(@app, @env, :foo => :bar)
      assert_equal :bar, @env[:foo]
    end
  end

  context "calling" do
    setup do
      @internal_vm.stubs(:running?).returns(true)

      @vm.system.stubs(:halt)
      @internal_vm.stubs(:stop)
      @internal_vm.stubs(:state).returns(:powered_off)
    end

    should "do nothing if VM not running" do
      @internal_vm.stubs(:running?).returns(false)
      @vm.system.expects(:halt).never
      @internal_vm.expects(:stop).never
      @app.expects(:call).once

      @instance.call(@env)
    end

    should "halt with the system and NOT force VM to stop if powered off" do
      @internal_vm.expects(:state).with(true).returns(:powered_off)
      @vm.system.expects(:halt).once
      @internal_vm.expects(:stop).never
      @app.expects(:call).once

      @instance.call(@env)
    end

    should "halt with the system and force VM to stop if NOT powered off" do
      @internal_vm.expects(:state).with(true).returns(:running)
      @vm.system.expects(:halt).once
      @internal_vm.expects(:stop).once
      @app.expects(:call).once

      @instance.call(@env)
    end

    should "not call halt on the system if forcing" do
      @env[:force] = true
      @vm.system.expects(:halt).never
      @instance.call(@env)
    end
  end
end

Version data entries

4 entries across 4 versions & 2 rubygems

Version Path
vagrantup-0.5.4 test/vagrant/action/vm/halt_test.rb
vagrantup-0.5.3 test/vagrant/action/vm/halt_test.rb
vagrant-0.5.4 test/vagrant/action/vm/halt_test.rb
vagrant-0.5.3 test/vagrant/action/vm/halt_test.rb