Sha256: 6a8e7347f985334c2ce575d7a0baa3a465fe8f27fe47db86acdccc5f46549da1

Contents?: true

Size: 1.79 KB

Versions: 22

Compression:

Stored size: 1.79 KB

Contents

require File.expand_path("../../../../base", __FILE__)

describe Vagrant::Action::Builtin::GracefulHalt do
  let(:app) { lambda { |env| } }
  let(:env) { { machine: machine, ui: ui } }
  let(:machine) do
    result = double("machine")
    allow(result).to receive(:config).and_return(machine_config)
    allow(result).to receive(:guest).and_return(machine_guest)
    allow(result).to receive(:state).and_return(machine_state)
    result
  end
  let(:machine_config) do
    double("machine_config").tap do |top_config|
      vm_config = double("machien_vm_config")
      vm_config.stub(graceful_halt_timeout: 10)
      top_config.stub(vm: vm_config)
    end
  end
  let(:machine_guest) { double("machine_guest") }
  let(:machine_state) do
    double("machine_state").tap do |result|
      allow(result).to receive(:id).and_return(:unknown)
    end
  end
  let(:target_state) { :target }
  let(:ui) do
    double("ui").tap do |result|
      allow(result).to receive(:output)
    end
  end

  it "should do nothing if force is specified" do
    env[:force_halt] = true

    expect(machine_guest).not_to receive(:capability)

    described_class.new(app, env, target_state).call(env)

    expect(env[:result]).to eq(false)
  end

  it "should do nothing if there is an invalid source state" do
    allow(machine_state).to receive(:id).and_return(:invalid_source)
    expect(machine_guest).not_to receive(:capability)

    described_class.new(app, env, target_state, :target_source).call(env)

    expect(env[:result]).to eq(false)
  end

  it "should gracefully halt and wait for the target state" do
    expect(machine_guest).to receive(:capability).with(:halt).once
    allow(machine_state).to receive(:id).and_return(target_state)

    described_class.new(app, env, target_state).call(env)

    expect(env[:result]).to eq(true)
  end
end

Version data entries

22 entries across 19 versions & 5 rubygems

Version Path
vagrant-unbundled-1.9.7.1 test/unit/vagrant/action/builtin/graceful_halt_test.rb
vagrant-aws-mkubenka-0.7.2.pre.14 vendor/bundle/ruby/2.3.0/bundler/gems/vagrant-5333e60e2d38/test/unit/vagrant/action/builtin/graceful_halt_test.rb
vagrant-aws-mkubenka-0.7.2.pre.11 vendor/bundle/ruby/2.3.0/bundler/gems/vagrant-5333e60e2d38/test/unit/vagrant/action/builtin/graceful_halt_test.rb
vagrant-aws-mkubenka-0.7.2.pre.10 vendor/bundle/ruby/2.3.0/bundler/gems/vagrant-5333e60e2d38/test/unit/vagrant/action/builtin/graceful_halt_test.rb
vagrant-aws-mkubenka-0.7.2.pre.9 vendor/bundle/ruby/2.3.0/bundler/gems/vagrant-5333e60e2d38/test/unit/vagrant/action/builtin/graceful_halt_test.rb
vagrant-unbundled-1.9.5.1 test/unit/vagrant/action/builtin/graceful_halt_test.rb
vagrant-unbundled-1.9.1.1 test/unit/vagrant/action/builtin/graceful_halt_test.rb
vagrant-compose-yaml-0.1.3 vendor/bundle/ruby/2.2.0/bundler/gems/vagrant-dbb756c7b6da/test/unit/vagrant/action/builtin/graceful_halt_test.rb
vagrant-compose-yaml-0.1.2 vendor/bundle/ruby/2.2.0/bundler/gems/vagrant-dbb756c7b6da/test/unit/vagrant/action/builtin/graceful_halt_test.rb
vagrant-compose-yaml-0.1.1 vendor/bundle/ruby/2.2.0/bundler/gems/vagrant-dbb756c7b6da/test/unit/vagrant/action/builtin/graceful_halt_test.rb
vagrant-compose-yaml-0.1.0 vendor/bundle/ruby/2.2.0/bundler/gems/vagrant-dbb756c7b6da/test/unit/vagrant/action/builtin/graceful_halt_test.rb
vagrant-unbundled-1.8.5.2 test/unit/vagrant/action/builtin/graceful_halt_test.rb
vagrant-unbundled-1.8.5.1 test/unit/vagrant/action/builtin/graceful_halt_test.rb
vagrant-unbundled-1.8.4.2 test/unit/vagrant/action/builtin/graceful_halt_test.rb
vagrant-unbundled-1.8.4.1 test/unit/vagrant/action/builtin/graceful_halt_test.rb
vagrant-unbundled-1.8.1.2 test/unit/vagrant/action/builtin/graceful_halt_test.rb
vagrant-unbundled-1.8.1.1 test/unit/vagrant/action/builtin/graceful_halt_test.rb
vagrant-cloudstack-1.1.0 vendor/bundle/bundler/gems/vagrant-b421af58e8b3/test/unit/vagrant/action/builtin/graceful_halt_test.rb
vagrant-cloudstack-1.1.0 vendor/bundle/bundler/gems/vagrant-1cf2a8db4ccb/test/unit/vagrant/action/builtin/graceful_halt_test.rb
vagrant-cloudstack-1.1.0 vendor/bundle/bundler/gems/vagrant-309e896975d1/test/unit/vagrant/action/builtin/graceful_halt_test.rb