Ensure ssh_run and ssh actions match vagrant (#1378)

Vagrant expects that providers raise specific errors if the machines are
not available. Update to match the built-in providers.

Fixes: #1376
This commit is contained in:
Darragh Bailey
2021-10-12 09:45:49 +01:00
committed by GitHub
parent 551c303e41
commit 5b70a4a669
2 changed files with 82 additions and 8 deletions

View File

@@ -93,4 +93,82 @@ describe VagrantPlugins::ProviderLibvirt::Action do
end
end
end
describe '#action_ssh' do
context 'when not created' do
before do
allow_action_env_result(VagrantPlugins::ProviderLibvirt::Action::IsCreated, false)
end
it 'should cause an error' do
expect{ machine.action(:ssh, ssh_opts: {})}.to raise_error(Vagrant::Errors::VMNotCreatedError)
end
end
context 'when created' do
before do
allow_action_env_result(VagrantPlugins::ProviderLibvirt::Action::IsCreated, true)
end
context 'when not running' do
before do
allow_action_env_result(VagrantPlugins::ProviderLibvirt::Action::IsRunning, false)
end
it 'should cause an error' do
expect{ machine.action(:ssh, ssh_opts: {})}.to raise_error(Vagrant::Errors::VMNotRunningError)
end
end
context 'when running' do
before do
allow_action_env_result(VagrantPlugins::ProviderLibvirt::Action::IsRunning, true)
end
it 'should call SSHExec' do
expect_any_instance_of(Vagrant::Action::Builtin::SSHExec).to receive(:call).and_return(0)
expect(machine.action(:ssh, ssh_opts: {})).to match(hash_including({:action_name => :machine_action_ssh}))
end
end
end
end
describe '#action_ssh_run' do
context 'when not created' do
before do
allow_action_env_result(VagrantPlugins::ProviderLibvirt::Action::IsCreated, false)
end
it 'should cause an error' do
expect{ machine.action(:ssh_run, ssh_opts: {})}.to raise_error(Vagrant::Errors::VMNotCreatedError)
end
end
context 'when created' do
before do
allow_action_env_result(VagrantPlugins::ProviderLibvirt::Action::IsCreated, true)
end
context 'when not running' do
before do
allow_action_env_result(VagrantPlugins::ProviderLibvirt::Action::IsRunning, false)
end
it 'should cause an error' do
expect{ machine.action(:ssh_run, ssh_opts: {})}.to raise_error(Vagrant::Errors::VMNotRunningError)
end
end
context 'when running' do
before do
allow_action_env_result(VagrantPlugins::ProviderLibvirt::Action::IsRunning, true)
end
it 'should call SSHRun' do
expect_any_instance_of(Vagrant::Action::Builtin::SSHRun).to receive(:call).and_return(0)
expect(machine.action(:ssh_run, ssh_opts: {})).to match(hash_including({:action_name => :machine_action_ssh_run}))
end
end
end
end
end