Files
vagrant-libvirt/spec/support/libvirt_context.rb
Darragh Bailey 27a541bba9 Validate partial mocks (#1417)
Switch to using explicit references to objects to be partially mocked
and remove the need to resolve the string constants as this will catch
more instances of calls to invalid or missing methods.

Rework how the vm is added to the machine for one of the tests as it is
not a method and instead is provided via internal state being exposed
with a helper.
2021-12-03 11:28:21 +00:00

38 lines
1.2 KiB
Ruby

# frozen_string_literal: true
require 'fog/libvirt'
require 'fog/libvirt/models/compute/server'
require 'libvirt'
shared_context 'libvirt' do
include_context 'unit'
let(:libvirt_context) { true }
let(:id) { 'dummy-vagrant_dummy' }
let(:connection) { double('connection') }
let(:domain) { instance_double(::Fog::Libvirt::Compute::Server) }
let(:libvirt_client) { instance_double(::Libvirt::Connect) }
let(:libvirt_domain) { instance_double(::Libvirt::Domain) }
let(:logger) { double('logger') }
def connection_result(options = {})
result = options.fetch(:result, nil)
double('connection_result' => result)
end
before (:each) do
# 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
stub_const('::Fog::Compute', connection)
# drivers also call vm_exists? during init;
allow(connection).to receive(:servers)
.and_return(connection_result(result: nil))
allow(connection).to receive(:client).and_return(libvirt_client)
allow(machine).to receive(:id).and_return(id)
allow(Log4r::Logger).to receive(:new).and_return(logger)
end
end