2021-06-30 13:27:03 +01:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
2022-11-08 16:28:32 +00:00
|
|
|
require_relative '../../spec_helper'
|
2022-10-11 18:19:52 +01:00
|
|
|
|
2021-06-14 09:57:07 -07:00
|
|
|
require 'vagrant-libvirt/action/halt_domain'
|
2021-05-08 17:14:13 +01:00
|
|
|
|
|
|
|
|
describe VagrantPlugins::ProviderLibvirt::Action::HaltDomain do
|
|
|
|
|
subject { described_class.new(app, env) }
|
|
|
|
|
|
|
|
|
|
include_context 'unit'
|
|
|
|
|
include_context 'libvirt'
|
|
|
|
|
|
2021-09-30 13:35:30 +01:00
|
|
|
let(:driver) { double('driver') }
|
2021-05-08 17:14:13 +01:00
|
|
|
let(:libvirt_domain) { double('libvirt_domain') }
|
|
|
|
|
let(:servers) { double('servers') }
|
|
|
|
|
|
2021-09-30 13:35:30 +01:00
|
|
|
before do
|
|
|
|
|
allow(machine.provider).to receive('driver').and_return(driver)
|
|
|
|
|
allow(driver).to receive(:created?).and_return(true)
|
|
|
|
|
allow(driver).to receive(:connection).and_return(connection)
|
|
|
|
|
end
|
|
|
|
|
|
2021-05-08 17:14:13 +01:00
|
|
|
describe '#call' do
|
|
|
|
|
before do
|
|
|
|
|
allow(connection).to receive(:servers).and_return(servers)
|
|
|
|
|
allow(servers).to receive(:get).and_return(domain)
|
2021-06-11 16:06:09 -07:00
|
|
|
allow(ui).to receive(:info).with('Halting domain...')
|
2021-05-08 17:14:13 +01:00
|
|
|
end
|
|
|
|
|
|
2021-06-11 16:06:09 -07:00
|
|
|
context "when state is not running" do
|
2021-09-30 13:35:30 +01:00
|
|
|
before { expect(driver).to receive(:state).at_least(1).
|
|
|
|
|
and_return(:not_created) }
|
2021-05-08 17:14:13 +01:00
|
|
|
|
2021-06-11 16:06:09 -07:00
|
|
|
it "should not poweroff when state is not running" do
|
|
|
|
|
expect(domain).not_to receive(:poweroff)
|
|
|
|
|
subject.call(env)
|
2021-05-08 17:14:13 +01:00
|
|
|
end
|
|
|
|
|
|
2021-06-11 16:06:09 -07:00
|
|
|
it "should not print halting message" do
|
|
|
|
|
expect(ui).not_to receive(:info)
|
|
|
|
|
subject.call(env)
|
2021-05-08 17:14:13 +01:00
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2021-06-11 16:06:09 -07:00
|
|
|
context "when state is running" do
|
2021-05-08 17:14:13 +01:00
|
|
|
before do
|
2021-09-30 13:35:30 +01:00
|
|
|
expect(driver).to receive(:state).and_return(:running)
|
2021-05-08 17:14:13 +01:00
|
|
|
end
|
|
|
|
|
|
2021-06-11 16:06:09 -07:00
|
|
|
it "should poweroff" do
|
2021-05-08 17:14:13 +01:00
|
|
|
expect(domain).to receive(:poweroff)
|
2021-06-11 16:06:09 -07:00
|
|
|
subject.call(env)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it "should print halting message" do
|
2021-09-30 13:35:30 +01:00
|
|
|
allow(domain).to receive(:poweroff)
|
2021-06-11 16:06:09 -07:00
|
|
|
expect(ui).to receive(:info).with('Halting domain...')
|
|
|
|
|
subject.call(env)
|
2021-05-08 17:14:13 +01:00
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|