Sha256: bb3e06d193f46a74ea6e9ecf3aa42699666a4fe45ba90dbc15612a71fd17db1d

Contents?: true

Size: 1.84 KB

Versions: 9

Compression:

Stored size: 1.84 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")
      allow(vm_config).to receive(:graceful_halt_timeout).and_return(10)
      allow(top_config).to receive(:vm).and_return(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

9 entries across 9 versions & 3 rubygems

Version Path
vagrant-aws-detiber-0.7.2.pre.4 vendor/bundle/ruby/2.3.0/bundler/gems/vagrant-419afb4dcffe/test/unit/vagrant/action/builtin/graceful_halt_test.rb
vagrant-aws-detiber-0.7.2.pre.3 vendor/bundle/ruby/2.3.0/bundler/gems/vagrant-419afb4dcffe/test/unit/vagrant/action/builtin/graceful_halt_test.rb
vagrant-aws-detiber-0.7.2.pre.2 vendor/bundle/ruby/2.3.0/bundler/gems/vagrant-419afb4dcffe/test/unit/vagrant/action/builtin/graceful_halt_test.rb
vagrant-unbundled-2.0.2.0 test/unit/vagrant/action/builtin/graceful_halt_test.rb
vagrant-unbundled-2.0.1.0 test/unit/vagrant/action/builtin/graceful_halt_test.rb
vagrant-aws-mkubenka-0.7.2.pre.22 vendor/bundle/ruby/2.3.0/bundler/gems/vagrant-f3fdbf414272/test/unit/vagrant/action/builtin/graceful_halt_test.rb
vagrant-aws-mkubenka-0.7.2.pre.16 vendor/bundle/ruby/2.3.0/bundler/gems/vagrant-1ee58c40e3f5/test/unit/vagrant/action/builtin/graceful_halt_test.rb
vagrant-unbundled-2.0.0.1 test/unit/vagrant/action/builtin/graceful_halt_test.rb
vagrant-unbundled-1.9.8.1 test/unit/vagrant/action/builtin/graceful_halt_test.rb