Skip to content

Commit 72eefd0

Browse files
authored
Merge pull request #2621 from mhashizume/maint/main/debian-arm-aarch
(FACT-3436) Standardize Debian architecture fact
2 parents 3c43f9e + bc5a529 commit 72eefd0

File tree

2 files changed

+7
-54
lines changed

2 files changed

+7
-54
lines changed

lib/facter/facts/debian/architecture.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@ class Architecture
88
ALIASES = 'architecture'
99

1010
def call_the_resolver
11-
fact_value = Facter::Resolvers::Uname.resolve(:machine)
12-
fact_value = 'amd64' if fact_value == 'x86_64'
13-
fact_value = 'i386' if /i[3456]86|pentium/.match?(fact_value)
11+
fact_value = Facter::Core::Execution.execute('dpkg --print-architecture')
1412

1513
[Facter::ResolvedFact.new(FACT_NAME, fact_value), Facter::ResolvedFact.new(ALIASES, fact_value, :legacy)]
1614
end

spec/facter/facts/debian/os/architecture_spec.rb

Lines changed: 6 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -4,61 +4,16 @@
44
describe '#call_the_resolver' do
55
subject(:fact) { Facts::Debian::Os::Architecture.new }
66

7-
context 'when resolver does not return x86_64' do
8-
let(:value) { 'i86pc' }
7+
%w[amd64 arm64 i386].each do |arch|
8+
it 'calls Facter::Core::Execution and returns architecture fact' do
9+
allow(Facter::Core::Execution).to receive(:execute).and_return(arch)
910

10-
before do
11-
allow(Facter::Resolvers::Uname).to receive(:resolve).with(:machine).and_return(value)
12-
end
13-
14-
it 'calls Facter::Resolvers::Uname' do
15-
fact.call_the_resolver
16-
expect(Facter::Resolvers::Uname).to have_received(:resolve).with(:machine)
17-
end
18-
19-
it 'returns architecture fact' do
20-
expect(fact.call_the_resolver).to be_an_instance_of(Array).and \
21-
contain_exactly(an_object_having_attributes(name: 'os.architecture', value: value),
22-
an_object_having_attributes(name: 'architecture', value: value, type: :legacy))
23-
end
24-
end
25-
26-
context 'when os is 32-bit' do
27-
let(:value) { 'i586' }
28-
let(:fact_value) { 'i386' }
29-
30-
before do
31-
allow(Facter::Resolvers::Uname).to receive(:resolve).with(:machine).and_return(value)
32-
end
33-
34-
it 'calls Facter::Resolvers::Uname' do
3511
fact.call_the_resolver
36-
expect(Facter::Resolvers::Uname).to have_received(:resolve).with(:machine)
37-
end
38-
39-
it 'returns architecture fact' do
40-
expect(fact.call_the_resolver).to be_an_instance_of(Array).and \
41-
contain_exactly(an_object_having_attributes(name: 'os.architecture', value: fact_value),
42-
an_object_having_attributes(name: 'architecture', value: fact_value, type: :legacy))
43-
end
44-
end
45-
46-
context 'when resolver returns x86_64' do
47-
let(:value) { 'x86_64' }
48-
49-
before do
50-
allow(Facter::Resolvers::Uname).to receive(:resolve).with(:machine).and_return(value)
51-
end
52-
53-
it 'calls Facter::Resolvers::Uname' do
54-
fact.call_the_resolver
55-
expect(Facter::Resolvers::Uname).to have_received(:resolve).with(:machine)
56-
end
12+
expect(Facter::Core::Execution).to have_received(:execute).with('dpkg --print-architecture')
5713

58-
it 'returns architecture fact' do
5914
expect(fact.call_the_resolver).to be_an_instance_of(Array).and \
60-
contain_exactly(an_object_having_attributes(name: 'os.architecture', value: 'amd64'),
61-
an_object_having_attributes(name: 'architecture', value: 'amd64', type: :legacy))
15+
contain_exactly(an_object_having_attributes(name: 'os.architecture', value: arch),
16+
an_object_having_attributes(name: 'architecture', value: arch, type: :legacy))
6217
end
6318
end
6419
end

0 commit comments

Comments
 (0)