-
Notifications
You must be signed in to change notification settings - Fork 495
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(FACT-2218) Add test for virtual fact. Refactor the test from is_virt…
…ual.
- Loading branch information
BogdanIrimie
committed
Jun 29, 2020
1 parent
fdfac8a
commit 09c9f9c
Showing
2 changed files
with
118 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
# frozen_string_literal: true | ||
|
||
describe Facts::Macosx::Virtual do | ||
subject(:fact) { Facts::Macosx::Virtual.new } | ||
|
||
describe '#call_the_resolver' do | ||
before do | ||
allow(Facter::Resolvers::Macosx::SystemProfiler).to receive(:resolve) | ||
.with(:model_identifier) | ||
.and_return('MacBookPro11,4') | ||
|
||
allow(Facter::Resolvers::Macosx::SystemProfiler).to receive(:resolve) | ||
.with(:boot_rom_version) | ||
.and_return('1037.60.58.0.0 (iBridge: 17.16.12551.0.0,0)') | ||
|
||
allow(Facter::Resolvers::Macosx::SystemProfiler).to receive(:resolve) | ||
.with(:subsystem_vendor_id) | ||
.and_return('0x123') | ||
end | ||
|
||
context 'when on physical machine' do | ||
it 'calls Facter::Resolvers::Macosx::SystemProfile with model_identifier' do | ||
fact.call_the_resolver | ||
|
||
expect(Facter::Resolvers::Macosx::SystemProfiler).to have_received(:resolve).with(:model_identifier) | ||
end | ||
|
||
it 'calls Facter::Resolvers::Macosx::SystemProfile with boot_rom_version' do | ||
fact.call_the_resolver | ||
|
||
expect(Facter::Resolvers::Macosx::SystemProfiler).to have_received(:resolve).with(:boot_rom_version) | ||
end | ||
|
||
it 'calls Facter::Resolvers::Macosx::SystemProfile with subsystem_vendor_id' do | ||
fact.call_the_resolver | ||
|
||
expect(Facter::Resolvers::Macosx::SystemProfiler).to have_received(:resolve).with(:subsystem_vendor_id) | ||
end | ||
|
||
it 'returns resolved fact with true value' do | ||
expect(fact.call_the_resolver) | ||
.to be_an_instance_of(Facter::ResolvedFact) | ||
.and have_attributes(name: 'virtual', value: nil) | ||
|
||
fact.call_the_resolver | ||
end | ||
end | ||
|
||
context 'when on virtual machine' do | ||
context 'with hypervisor vmware' do | ||
before do | ||
allow(Facter::Resolvers::Macosx::SystemProfiler) | ||
.to receive(:resolve) | ||
.with(:model_identifier) | ||
.and_return('VMware') | ||
end | ||
|
||
it 'returns resolved fact with true value' do | ||
expect(fact.call_the_resolver) | ||
.to be_an_instance_of(Facter::ResolvedFact) | ||
.and have_attributes(name: 'virtual', value: 'vmware') | ||
end | ||
end | ||
|
||
context 'when hypervisor VirtualBox' do | ||
before do | ||
allow(Facter::Resolvers::Macosx::SystemProfiler) | ||
.to receive(:resolve) | ||
.with(:boot_rom_version) | ||
.and_return('VirtualBox') | ||
end | ||
|
||
it 'returns resolved fact with true value' do | ||
expect(fact.call_the_resolver) | ||
.to be_an_instance_of(Facter::ResolvedFact) | ||
.and have_attributes(name: 'virtual', value: 'virtualbox') | ||
end | ||
end | ||
|
||
context 'when hypervisor Parallels' do | ||
before do | ||
allow(Facter::Resolvers::Macosx::SystemProfiler) | ||
.to receive(:resolve) | ||
.with(:subsystem_vendor_id) | ||
.and_return('0x1ab8') | ||
end | ||
|
||
it 'returns resolved fact with true value' do | ||
expect(fact.call_the_resolver) | ||
.to be_an_instance_of(Facter::ResolvedFact) | ||
.and have_attributes(name: 'virtual', value: 'parallels') | ||
end | ||
end | ||
end | ||
end | ||
end |