Skip to content

Commit 8528222

Browse files
Merge pull request #754 from corporate-gadfly/replace-deprecated-facter-calls
Replace deprecated calls with `Facter::Core::Execution`
2 parents 3fc880c + c56f33f commit 8528222

6 files changed

Lines changed: 50 additions & 50 deletions

File tree

‎lib/facter/pip_version.rb‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
# Make pip version available as a fact
44

55
def get_pip_version(executable)
6-
if Facter::Util::Resolution.which(executable) # rubocop:disable Style/GuardClause
7-
results = Facter::Util::Resolution.exec("#{executable} --version 2>&1").match(%r{^pip (\d+\.\d+\.?\d*).*$})
6+
if Facter::Core::Execution.which(executable) # rubocop:disable Style/GuardClause
7+
results = Facter::Core::Execution.execute("#{executable} --version 2>&1").match(%r{^pip (\d+\.\d+\.?\d*).*$})
88
results[1] if results
99
end
1010
end

‎lib/facter/python_release.rb‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
# Make python release available as facts
44

55
def get_python_release(executable)
6-
if Facter::Util::Resolution.which(executable) # rubocop:disable Style/GuardClause
7-
results = Facter::Util::Resolution.exec("#{executable} -V 2>&1").match(%r{^.*(\d+\.\d+)\.\d+\+?$})
6+
if Facter::Core::Execution.which(executable) # rubocop:disable Style/GuardClause
7+
results = Facter::Core::Execution.execute("#{executable} -V 2>&1").match(%r{^.*(\d+\.\d+)\.\d+\+?$})
88
results[1] if results
99
end
1010
end

‎lib/facter/python_version.rb‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
# Make python versions available as facts
44

55
def get_python_version(executable)
6-
if Facter::Util::Resolution.which(executable) # rubocop:disable Style/GuardClause
7-
results = Facter::Util::Resolution.exec("#{executable} -V 2>&1").match(%r{^.*(\d+\.\d+\.\d+\+?)$})
6+
if Facter::Core::Execution.which(executable) # rubocop:disable Style/GuardClause
7+
results = Facter::Core::Execution.execute("#{executable} -V 2>&1").match(%r{^.*(\d+\.\d+\.\d+\+?)$})
88
results[1] if results
99
end
1010
end

‎spec/unit/facter/pip_version_spec.rb‎

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,15 @@
2828
describe 'pip_version' do
2929
context 'returns pip version when pip present' do
3030
it do
31-
allow(Facter::Util::Resolution).to receive(:which).with('pip').and_return(true)
32-
allow(Facter::Util::Resolution).to receive(:exec).with('pip --version 2>&1').and_return(pip_version_output)
31+
allow(Facter::Core::Execution).to receive(:which).with('pip').and_return(true)
32+
allow(Facter::Core::Execution).to receive(:execute).with('pip --version 2>&1').and_return(pip_version_output)
3333
expect(Facter.value(:pip_version)).to eq('6.0.6')
3434
end
3535
end
3636

3737
context 'returns nil when pip not present' do
3838
it do
39-
allow(Facter::Util::Resolution).to receive(:which).with('pip').and_return(false)
39+
allow(Facter::Core::Execution).to receive(:which).with('pip').and_return(false)
4040
expect(Facter.value(:pip_version)).to be_nil
4141
end
4242
end
@@ -45,15 +45,15 @@
4545
describe 'pip2_version' do
4646
context 'returns pip2 version when pip2 present' do
4747
it do
48-
allow(Facter::Util::Resolution).to receive(:which).with('pip2').and_return(true)
49-
allow(Facter::Util::Resolution).to receive(:exec).with('pip2 --version 2>&1').and_return(pip2_version_output)
48+
allow(Facter::Core::Execution).to receive(:which).with('pip2').and_return(true)
49+
allow(Facter::Core::Execution).to receive(:execute).with('pip2 --version 2>&1').and_return(pip2_version_output)
5050
expect(Facter.value(:pip2_version)).to eq('9.0.1')
5151
end
5252
end
5353

5454
context 'returns nil when pip2 not present' do
5555
it do
56-
allow(Facter::Util::Resolution).to receive(:which).with('pip2').and_return(false)
56+
allow(Facter::Core::Execution).to receive(:which).with('pip2').and_return(false)
5757
expect(Facter.value(:pip2_version)).to be_nil
5858
end
5959
end
@@ -62,15 +62,15 @@
6262
describe 'pip3_version' do
6363
context 'returns pip3 version when pip3 present' do
6464
it do
65-
allow(Facter::Util::Resolution).to receive(:which).with('pip3').and_return(true)
66-
allow(Facter::Util::Resolution).to receive(:exec).with('pip3 --version 2>&1').and_return(pip3_version_output)
65+
allow(Facter::Core::Execution).to receive(:which).with('pip3').and_return(true)
66+
allow(Facter::Core::Execution).to receive(:execute).with('pip3 --version 2>&1').and_return(pip3_version_output)
6767
expect(Facter.value(:pip3_version)).to eq('18.1')
6868
end
6969
end
7070

7171
context 'returns nil when pip3 not present' do
7272
it do
73-
allow(Facter::Util::Resolution).to receive(:which).with('pip3').and_return(false)
73+
allow(Facter::Core::Execution).to receive(:which).with('pip3').and_return(false)
7474
expect(Facter.value(:pip3_version)).to be_nil
7575
end
7676
end

‎spec/unit/facter/python_release_spec.rb‎

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,16 @@
2121
describe 'python_release' do
2222
context 'returns Python release when `python` present' do
2323
it do
24-
allow(Facter::Util::Resolution).to receive(:which).with('python').and_return(true)
25-
allow(Facter::Util::Resolution).to receive(:exec).with('python -V 2>&1').and_return(python2_version_output)
24+
allow(Facter::Core::Execution).to receive(:which).with('python').and_return(true)
25+
allow(Facter::Core::Execution).to receive(:execute).with('python -V 2>&1').and_return(python2_version_output)
2626
expect(Facter.value(:python_release)).to eq('2.7')
2727
end
2828
end
2929

3030
context 'returns nil when `python` not present' do
3131
it do
32-
allow(Facter::Util::Resolution).to receive(:exec).and_return(false)
33-
allow(Facter::Util::Resolution).to receive(:which).with('python').and_return(false)
32+
allow(Facter::Core::Execution).to receive(:execute).and_return(false)
33+
allow(Facter::Core::Execution).to receive(:which).with('python').and_return(false)
3434
expect(Facter.value(:python_release)).to be_nil
3535
end
3636
end
@@ -39,35 +39,35 @@
3939
describe 'python2_release' do
4040
context 'returns Python 2 release when `python` is present and Python 2' do
4141
it do
42-
allow(Facter::Util::Resolution).to receive(:which).with('python').and_return(true)
43-
allow(Facter::Util::Resolution).to receive(:exec).with('python -V 2>&1').and_return(python2_version_output)
42+
allow(Facter::Core::Execution).to receive(:which).with('python').and_return(true)
43+
allow(Facter::Core::Execution).to receive(:execute).with('python -V 2>&1').and_return(python2_version_output)
4444
expect(Facter.value(:python2_release)).to eq('2.7')
4545
end
4646
end
4747

4848
context 'returns Python 2 release when `python` is Python 3 and `python2` is present' do
4949
it do
50-
allow(Facter::Util::Resolution).to receive(:which).with('python').and_return(true)
51-
allow(Facter::Util::Resolution).to receive(:exec).with('python -V 2>&1').and_return(python3_version_output)
52-
allow(Facter::Util::Resolution).to receive(:which).with('python2').and_return(true)
53-
allow(Facter::Util::Resolution).to receive(:exec).with('python2 -V 2>&1').and_return(python2_version_output)
50+
allow(Facter::Core::Execution).to receive(:which).with('python').and_return(true)
51+
allow(Facter::Core::Execution).to receive(:execute).with('python -V 2>&1').and_return(python3_version_output)
52+
allow(Facter::Core::Execution).to receive(:which).with('python2').and_return(true)
53+
allow(Facter::Core::Execution).to receive(:execute).with('python2 -V 2>&1').and_return(python2_version_output)
5454
expect(Facter.value(:python2_release)).to eq('2.7')
5555
end
5656
end
5757

5858
context 'returns nil when `python` is Python 3 and `python2` is absent' do
5959
it do
60-
allow(Facter::Util::Resolution).to receive(:which).with('python').and_return(true)
61-
allow(Facter::Util::Resolution).to receive(:exec).with('python -V 2>&1').and_return(python3_version_output)
62-
allow(Facter::Util::Resolution).to receive(:which).with('python2').and_return(false)
60+
allow(Facter::Core::Execution).to receive(:which).with('python').and_return(true)
61+
allow(Facter::Core::Execution).to receive(:execute).with('python -V 2>&1').and_return(python3_version_output)
62+
allow(Facter::Core::Execution).to receive(:which).with('python2').and_return(false)
6363
expect(Facter.value(:python2_release)).to be_nil
6464
end
6565
end
6666

6767
context 'returns nil when `python2` and `python` are absent' do
6868
it do
69-
allow(Facter::Util::Resolution).to receive(:which).with('python').and_return(false)
70-
allow(Facter::Util::Resolution).to receive(:which).with('python2').and_return(false)
69+
allow(Facter::Core::Execution).to receive(:which).with('python').and_return(false)
70+
allow(Facter::Core::Execution).to receive(:which).with('python2').and_return(false)
7171
expect(Facter.value(:python2_release)).to be_nil
7272
end
7373
end
@@ -76,15 +76,15 @@
7676
describe 'python3_release' do
7777
context 'returns Python 3 release when `python3` present' do
7878
it do
79-
allow(Facter::Util::Resolution).to receive(:which).with('python3').and_return(true)
80-
allow(Facter::Util::Resolution).to receive(:exec).with('python3 -V 2>&1').and_return(python3_version_output)
79+
allow(Facter::Core::Execution).to receive(:which).with('python3').and_return(true)
80+
allow(Facter::Core::Execution).to receive(:execute).with('python3 -V 2>&1').and_return(python3_version_output)
8181
expect(Facter.value(:python3_release)).to eq('3.3')
8282
end
8383
end
8484

8585
context 'returns nil when `python3` not present' do
8686
it do
87-
allow(Facter::Util::Resolution).to receive(:which).with('python3').and_return(false)
87+
allow(Facter::Core::Execution).to receive(:which).with('python3').and_return(false)
8888
expect(Facter.value(:python3_release)).to be_nil
8989
end
9090
end

‎spec/unit/facter/python_version_spec.rb‎

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,15 @@
2121
describe 'python_version' do
2222
context 'returns Python version when `python` present' do
2323
it do
24-
allow(Facter::Util::Resolution).to receive(:which).with('python').and_return(true)
25-
allow(Facter::Util::Resolution).to receive(:exec).with('python -V 2>&1').and_return(python2_version_output)
24+
allow(Facter::Core::Execution).to receive(:which).with('python').and_return(true)
25+
allow(Facter::Core::Execution).to receive(:execute).with('python -V 2>&1').and_return(python2_version_output)
2626
expect(Facter.value(:python_version)).to eq('2.7.9')
2727
end
2828
end
2929

3030
context 'returns nil when `python` not present' do
3131
it do
32-
allow(Facter::Util::Resolution).to receive(:which).with('python').and_return(false)
32+
allow(Facter::Core::Execution).to receive(:which).with('python').and_return(false)
3333
expect(Facter.value(:python_version)).to be_nil
3434
end
3535
end
@@ -38,35 +38,35 @@
3838
describe 'python2_version' do
3939
context 'returns Python 2 version when `python` is present and Python 2' do
4040
it do
41-
allow(Facter::Util::Resolution).to receive(:which).with('python').and_return(true)
42-
allow(Facter::Util::Resolution).to receive(:exec).with('python -V 2>&1').and_return(python2_version_output)
41+
allow(Facter::Core::Execution).to receive(:which).with('python').and_return(true)
42+
allow(Facter::Core::Execution).to receive(:execute).with('python -V 2>&1').and_return(python2_version_output)
4343
expect(Facter.value(:python2_version)).to eq('2.7.9')
4444
end
4545
end
4646

4747
context 'returns Python 2 version when `python` is Python 3 and `python2` is present' do
4848
it do
49-
allow(Facter::Util::Resolution).to receive(:which).with('python').and_return(true)
50-
allow(Facter::Util::Resolution).to receive(:exec).with('python -V 2>&1').and_return(python3_version_output)
51-
allow(Facter::Util::Resolution).to receive(:which).with('python2').and_return(true)
52-
allow(Facter::Util::Resolution).to receive(:exec).with('python2 -V 2>&1').and_return(python2_version_output)
49+
allow(Facter::Core::Execution).to receive(:which).with('python').and_return(true)
50+
allow(Facter::Core::Execution).to receive(:execute).with('python -V 2>&1').and_return(python3_version_output)
51+
allow(Facter::Core::Execution).to receive(:which).with('python2').and_return(true)
52+
allow(Facter::Core::Execution).to receive(:execute).with('python2 -V 2>&1').and_return(python2_version_output)
5353
expect(Facter.value(:python2_version)).to eq('2.7.9')
5454
end
5555
end
5656

5757
context 'returns nil when `python` is Python 3 and `python2` is absent' do
5858
it do
59-
allow(Facter::Util::Resolution).to receive(:which).with('python').and_return(true)
60-
allow(Facter::Util::Resolution).to receive(:exec).with('python -V 2>&1').and_return(python3_version_output)
61-
allow(Facter::Util::Resolution).to receive(:which).with('python2').and_return(false)
59+
allow(Facter::Core::Execution).to receive(:which).with('python').and_return(true)
60+
allow(Facter::Core::Execution).to receive(:execute).with('python -V 2>&1').and_return(python3_version_output)
61+
allow(Facter::Core::Execution).to receive(:which).with('python2').and_return(false)
6262
expect(Facter.value(:python2_version)).to be_nil
6363
end
6464
end
6565

6666
context 'returns nil when `python2` and `python` are absent' do
6767
it do
68-
allow(Facter::Util::Resolution).to receive(:which).with('python2').and_return(false)
69-
allow(Facter::Util::Resolution).to receive(:which).with('python').and_return(false)
68+
allow(Facter::Core::Execution).to receive(:which).with('python2').and_return(false)
69+
allow(Facter::Core::Execution).to receive(:which).with('python').and_return(false)
7070
expect(Facter.value(:python2_version)).to be_nil
7171
end
7272
end
@@ -75,15 +75,15 @@
7575
describe 'python3_version' do
7676
context 'returns Python 3 version when `python3` present' do
7777
it do
78-
allow(Facter::Util::Resolution).to receive(:which).with('python3').and_return(true)
79-
allow(Facter::Util::Resolution).to receive(:exec).with('python3 -V 2>&1').and_return(python3_version_output)
78+
allow(Facter::Core::Execution).to receive(:which).with('python3').and_return(true)
79+
allow(Facter::Core::Execution).to receive(:execute).with('python3 -V 2>&1').and_return(python3_version_output)
8080
expect(Facter.value(:python3_version)).to eq('3.3.0')
8181
end
8282
end
8383

8484
context 'returns nil when `python3` not present' do
8585
it do
86-
allow(Facter::Util::Resolution).to receive(:which).with('python3').and_return(false)
86+
allow(Facter::Core::Execution).to receive(:which).with('python3').and_return(false)
8787
expect(Facter.value(:python3_version)).to be_nil
8888
end
8989
end

0 commit comments

Comments
 (0)