Skip to content

Commit

Permalink
Merge pull request #2715 from joshcooper/order-dependent-failures
Browse files Browse the repository at this point in the history
(FACT-3465) Order dependent failures
  • Loading branch information
cthorn42 authored May 23, 2024
2 parents bb4a33c + d857633 commit 2ab655b
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 2 deletions.
2 changes: 2 additions & 0 deletions lib/facter/resolvers/uname.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
module Facter
module Resolvers
class Uname < BaseResolver
@log = Facter::Log.new(self)

init_resolver

class << self
Expand Down
2 changes: 2 additions & 0 deletions lib/facter/resolvers/xen.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ def find_command
return XEN_TOOLSTACK if num_stacks > 1 && File.exist?(XEN_TOOLSTACK)

XEN_COMMANDS.each { |command| return command if File.exist?(command) }

nil
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/facter/resolvers/amzn/os_release_rpm_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
describe Facter::Resolvers::Amzn::OsReleaseRpm do
subject(:os_release_resolver) { Facter::Resolvers::Amzn::OsReleaseRpm }

let(:log_spy) { Facter::Log }
let(:log_spy) { instance_spy(Facter::Log) }

before do
os_release_resolver.instance_variable_set(:@log, log_spy)
Expand Down
1 change: 1 addition & 0 deletions spec/facter/resolvers/ec2_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

before do
Facter::Util::Resolvers::Http.instance_variable_set(:@log, log_spy)
allow(Socket).to receive(:tcp) if Gem.win_platform?
end

after do
Expand Down
10 changes: 10 additions & 0 deletions spec/facter/resolvers/processors_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,10 @@
allow(Facter::Util::FileHelper).to receive(:safe_readlines)
.with('/proc/cpuinfo')
.and_return(load_fixture('cpuinfo_wo_physical_id').readlines)
allow(Dir).to receive(:entries).and_call_original
allow(Dir).to receive(:entries).with('/sys/devices/system/cpu').and_return(%w[cpu0 cpu1 cpuindex])

allow(File).to receive(:exist?).and_call_original
allow(File).to receive(:exist?)
.with('/sys/devices/system/cpu/cpu0/topology/physical_package_id')
.and_return(true)
Expand Down Expand Up @@ -117,9 +119,13 @@
.with('/proc/cpuinfo')
.and_return(load_fixture('cpuinfo_powerpc').readlines)

allow(Dir).to receive(:entries).and_call_original
allow(Dir).to receive(:entries).with('/sys/devices/system/cpu').and_return(%w[cpu0 cpu1 cpuindex])

allow(File).to receive(:exist?).and_call_original
allow(File).to receive(:exist?).with('/sys/devices/system/cpu/cpu0/topology/physical_package_id').and_return(true)
allow(File).to receive(:exist?).with('/sys/devices/system/cpu/cpu1/topology/physical_package_id').and_return(true)

allow(Facter::Util::FileHelper).to receive(:safe_read)
.with('/sys/devices/system/cpu/cpu0/topology/physical_package_id')
.and_return('0')
Expand Down Expand Up @@ -164,9 +170,13 @@
.with('/proc/cpuinfo')
.and_return(load_fixture('cpuinfo_arm64').readlines)

allow(Dir).to receive(:entries).and_call_original
allow(Dir).to receive(:entries).with('/sys/devices/system/cpu').and_return(%w[cpu0 cpu1 cpuindex])

allow(File).to receive(:exist?).and_call_original
allow(File).to receive(:exist?).with('/sys/devices/system/cpu/cpu0/topology/physical_package_id').and_return(true)
allow(File).to receive(:exist?).with('/sys/devices/system/cpu/cpu1/topology/physical_package_id').and_return(true)

allow(Facter::Util::FileHelper).to receive(:safe_read)
.with('/sys/devices/system/cpu/cpu0/topology/physical_package_id')
.and_return('0')
Expand Down
7 changes: 6 additions & 1 deletion spec/facter/resolvers/uname_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
describe Facter::Resolvers::Uname do
subject(:uname_resolver) { Facter::Resolvers::Uname }

let(:log_spy) { Facter::Log }
let(:log_spy) { instance_spy(Facter::Log) }

before do
uname_resolver.instance_variable_set(:@log, log_spy)
Expand All @@ -22,6 +22,11 @@
Darwin Kernel Version 18.2.0: Fri Oct 5 19:41:49 PDT 2018; root:xnu-4903.221.2~2/RELEASE_X86_64')
end

after do
uname_resolver.instance_variable_set(:@log, nil)
Facter::Resolvers::Uname.invalidate_cache
end

it 'returns machine' do
expect(uname_resolver.resolve(:machine)).to eq('x86_64')
end
Expand Down
13 changes: 13 additions & 0 deletions spec/facter/resolvers/xen_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

before do
xen_resolver.instance_variable_set(:@log, log_spy)
allow(File).to receive(:exist?).and_call_original
allow(File).to receive(:exist?).with('/dev/xen/evtchn').and_return(evtchn_file)
allow(File).to receive(:exist?).with('/proc/xen').and_return(proc_xen_file)
allow(File).to receive(:exist?).with('/dev/xvda1').and_return(xvda1_file)
Expand All @@ -26,6 +27,18 @@
xen_resolver.invalidate_cache
end

context 'when not xen' do
let(:evtchn_file) { false }
let(:proc_xen_file) { false }
let(:xvda1_file) { false }

it 'returns' do
allow(File).to receive(:exist?).with('/usr/sbin/xm').and_return(false)

expect(xen_resolver.resolve(:vm)).to be_nil
end
end

context 'when xen is privileged' do
context 'when /dev/xen/evtchn exists' do
let(:domains) { load_fixture('xen_domains').read }
Expand Down
2 changes: 2 additions & 0 deletions spec/facter/util/linux/if_inet6_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
describe '#read_flags' do
context 'when only ipv6 link-local and lo ipv6 present' do
before do
allow(File).to receive(:exist?).and_call_original
allow(File).to receive(:exist?).with('/proc/net/if_inet6').and_return(true)
allow(Facter::Util::FileHelper).to receive(:safe_read)
.with('/proc/net/if_inet6', nil).and_return(load_fixture('proc_net_if_inet6').read)
Expand All @@ -38,6 +39,7 @@

context 'when multiple IPv6 addresses present with different flags' do
before do
allow(File).to receive(:exist?).and_call_original
allow(File).to receive(:exist?).with('/proc/net/if_inet6').and_return(true)
allow(Facter::Util::FileHelper).to receive(:safe_read)
.with('/proc/net/if_inet6', nil).and_return(load_fixture('proc_net_if_inet6_complex').read)
Expand Down

0 comments on commit 2ab655b

Please sign in to comment.