2021-06-30 13:27:03 +01:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
2016-01-25 19:07:14 +00:00
|
|
|
require 'fog/libvirt'
|
2021-11-08 11:31:04 +00:00
|
|
|
require 'fog/libvirt/models/compute/server'
|
|
|
|
|
require 'libvirt'
|
2016-01-25 19:07:14 +00:00
|
|
|
|
2016-12-06 23:20:29 +01:00
|
|
|
shared_context 'libvirt' do
|
|
|
|
|
include_context 'unit'
|
2016-01-25 19:07:14 +00:00
|
|
|
|
|
|
|
|
let(:libvirt_context) { true }
|
2016-12-06 23:20:29 +01:00
|
|
|
let(:id) { 'dummy-vagrant_dummy' }
|
|
|
|
|
let(:connection) { double('connection') }
|
2022-05-06 20:30:55 +01:00
|
|
|
let(:driver) { instance_double(VagrantPlugins::ProviderLibvirt::Driver) }
|
2021-12-03 11:28:21 +00:00
|
|
|
let(:domain) { instance_double(::Fog::Libvirt::Compute::Server) }
|
|
|
|
|
let(:libvirt_client) { instance_double(::Libvirt::Connect) }
|
|
|
|
|
let(:libvirt_domain) { instance_double(::Libvirt::Domain) }
|
2020-12-05 15:24:42 +00:00
|
|
|
let(:logger) { double('logger') }
|
2016-01-25 19:07:14 +00:00
|
|
|
|
2016-12-06 23:20:29 +01:00
|
|
|
def connection_result(options = {})
|
2016-01-25 19:07:14 +00:00
|
|
|
result = options.fetch(:result, nil)
|
2016-12-06 23:20:29 +01:00
|
|
|
double('connection_result' => result)
|
2016-01-25 19:07:14 +00:00
|
|
|
end
|
|
|
|
|
|
2016-01-26 16:58:17 +00:00
|
|
|
before (:each) do
|
2016-01-25 19:07:14 +00:00
|
|
|
# we don't want unit tests to ever run commands on the system; so we wire
|
|
|
|
|
# in a double to ensure any unexpected messages raise exceptions
|
2016-12-06 23:20:29 +01:00
|
|
|
stub_const('::Fog::Compute', connection)
|
2016-01-25 19:07:14 +00:00
|
|
|
|
|
|
|
|
# drivers also call vm_exists? during init;
|
2021-11-08 11:31:04 +00:00
|
|
|
allow(connection).to receive(:servers)
|
2016-12-06 23:20:29 +01:00
|
|
|
.and_return(connection_result(result: nil))
|
2016-01-26 17:00:53 +00:00
|
|
|
|
2021-11-08 11:31:04 +00:00
|
|
|
allow(connection).to receive(:client).and_return(libvirt_client)
|
2016-11-24 17:54:15 +00:00
|
|
|
|
2020-08-16 16:06:05 +01:00
|
|
|
allow(machine).to receive(:id).and_return(id)
|
2020-12-05 15:24:42 +00:00
|
|
|
allow(Log4r::Logger).to receive(:new).and_return(logger)
|
2022-05-06 20:30:55 +01:00
|
|
|
|
|
|
|
|
allow(machine.provider).to receive('driver').and_return(driver)
|
|
|
|
|
allow(driver).to receive(:connection).and_return(connection)
|
2016-01-25 19:07:14 +00:00
|
|
|
end
|
|
|
|
|
end
|