Skip to content

Commit

Permalink
(FACT-2218) Add test for virtual fact. Refactor the test from is_virt…
Browse files Browse the repository at this point in the history
…ual.
  • Loading branch information
BogdanIrimie committed Jun 29, 2020
1 parent fdfac8a commit 09c9f9c
Show file tree
Hide file tree
Showing 2 changed files with 118 additions and 28 deletions.
50 changes: 22 additions & 28 deletions spec/facter/facts/macosx/is_virtual_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,30 @@
.and_return('0x123')
end

it 'calls Facter::Resolvers::Macosx::SystemProfile with model_identifier' do
expect(Facter::Resolvers::Macosx::SystemProfiler).to receive(:resolve)
.with(:model_identifier)
fact.call_the_resolver
end
context 'when on physical machine' do
it 'calls Facter::Resolvers::Macosx::SystemProfile with model_identifier' do
fact.call_the_resolver

it 'calls Facter::Resolvers::Macosx::SystemProfile with boot_rom_version' do
expect(Facter::Resolvers::Macosx::SystemProfiler).to receive(:resolve)
.with(:boot_rom_version)
fact.call_the_resolver
end
expect(Facter::Resolvers::Macosx::SystemProfiler).to have_received(:resolve).with(:model_identifier)
end

it 'calls Facter::Resolvers::Macosx::SystemProfile with subsystem_vendor_id' do
allow(Facter::Resolvers::Macosx::SystemProfiler).to receive(:resolve)
.with(:subsystem_vendor_id)
fact.call_the_resolver
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 false value' do
expect(fact.call_the_resolver)
.to be_an_instance_of(Facter::ResolvedFact)
.and have_attributes(name: 'is_virtual', value: false)
end
end

context 'when on virtual machine' do
Expand All @@ -49,8 +57,6 @@
expect(fact.call_the_resolver)
.to be_an_instance_of(Facter::ResolvedFact)
.and have_attributes(name: 'is_virtual', value: true)

fact.call_the_resolver
end
end

Expand All @@ -66,8 +72,6 @@
expect(fact.call_the_resolver)
.to be_an_instance_of(Facter::ResolvedFact)
.and have_attributes(name: 'is_virtual', value: true)

fact.call_the_resolver
end
end

Expand All @@ -83,18 +87,8 @@
expect(fact.call_the_resolver)
.to be_an_instance_of(Facter::ResolvedFact)
.and have_attributes(name: 'is_virtual', value: true)

fact.call_the_resolver
end
end
end

context 'when on physical machine' do
it 'returns resolved fact with false value' do
expect(fact.call_the_resolver)
.to be_an_instance_of(Facter::ResolvedFact)
.and have_attributes(name: 'is_virtual', value: false)
end
end
end
end
96 changes: 96 additions & 0 deletions spec/facter/facts/macosx/virtual_spec.rb
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

0 comments on commit 09c9f9c

Please sign in to comment.