-
Notifications
You must be signed in to change notification settings - Fork 232
Extend fact to not fail on debian packages #416
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
bac44f7
Extend fact to handle debian packages too
rwaffen 1a5ee16
add open3 require to spec
rwaffen 0faf2ce
Update lib/facter/puppetdb_version.rb
rwaffen 17ff4e2
Refactor code again:
rwaffen a535c4d
Drop work on also handling debian package.
rwaffen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 |
|---|---|---|
| @@ -1,25 +1,93 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| require 'spec_helper' | ||
| require 'facter' | ||
|
|
||
| describe 'puppetdb_version' do | ||
| subject(:fact) { Facter.fact(:puppetdb_version) } | ||
|
|
||
| before(:each) do | ||
| Facter.clear | ||
| end | ||
|
|
||
| it 'returns the correct puppetdb version' do | ||
| allow(Facter::Util::Resolution).to receive(:which).with('puppetdb').and_return('/usr/bin/puppetdb') | ||
| allow(Facter::Core::Execution).to receive(:execute).with('puppetdb --version').and_return("puppetdb version: 7.18.0\n") | ||
| context 'when puppetdb is available' do | ||
| before do | ||
| allow(Facter::Util::Resolution).to receive(:which).with('puppetdb').and_return('/usr/bin/puppetdb') | ||
| end | ||
|
|
||
| context 'on a Debian-based system' do | ||
| before do | ||
| allow(Facter).to receive(:value).with(:os).and_return({ 'family' => 'Debian' }) | ||
| end | ||
|
|
||
| context 'when Puppet Labs is the maintainer' do | ||
| before do | ||
| allow(Facter::Core::Execution).to receive(:execute) | ||
| .with('apt-cache show puppetdb | grep "Maintainer:" | head -1') | ||
| .and_return('Maintainer: Puppet Labs') | ||
| end | ||
|
|
||
| it 'returns the correct version from puppetdb --version' do | ||
| expect(Facter::Core::Execution).to receive(:execute) | ||
| .with('puppetdb --version') | ||
| .and_return('puppetdb version: 7.19.0') | ||
|
|
||
| expect(Facter.fact(:puppetdb_version).value).to eq('7.19.0') | ||
| end | ||
|
|
||
| it 'returns nil if the command execution fails' do | ||
| allow(Facter::Core::Execution).to receive(:execute).with('puppetdb --version').and_raise(Facter::Core::Execution::ExecutionFailure) | ||
|
|
||
| expect(Facter.fact(:puppetdb_version).value).to be_nil | ||
| end | ||
| end | ||
|
|
||
| context 'when Puppet Labs is not the maintainer' do | ||
| before do | ||
| allow(Facter::Core::Execution).to receive(:execute) | ||
| .with('apt-cache show puppetdb | grep "Maintainer:" | head -1') | ||
| .and_return('Maintainer: Other Maintainer') | ||
| end | ||
|
|
||
| it 'returns the correct version from dpkg-query' do | ||
| expect(Facter::Core::Execution).to receive(:execute) | ||
| .with("dpkg-query --showformat='${Version}' --show puppetdb") | ||
| .and_return('7.9.0-1ubuntu1') | ||
|
|
||
| expect(Facter.fact(:puppetdb_version).value).to eq('7.9.0') | ||
| end | ||
|
|
||
| it 'returns nil if the command execution fails' do | ||
| allow(Facter::Core::Execution).to receive(:execute).with("dpkg-query --showformat='${Version}' --show puppetdb").and_raise(Facter::Core::Execution::ExecutionFailure) | ||
|
|
||
| expect(Facter.fact(:puppetdb_version).value).to be_nil | ||
| end | ||
| end | ||
| end | ||
|
|
||
| context 'on a non-Debian-based system' do | ||
| before do | ||
| allow(Facter).to receive(:value).with(:os).and_return({ 'family' => 'RedHat' }) | ||
| end | ||
|
|
||
| it 'returns the correct version from puppetdb --version' do | ||
| expect(Facter::Core::Execution).to receive(:execute) | ||
| .with('puppetdb --version') | ||
| .and_return('puppetdb version: 7.19.0') | ||
|
|
||
| expect(Facter.fact(:puppetdb_version).value).to eq('7.19.0') | ||
| end | ||
|
|
||
| it 'returns nil if the command execution fails' do | ||
| allow(Facter::Core::Execution).to receive(:execute).with('puppetdb --version').and_raise(Facter::Core::Execution::ExecutionFailure) | ||
|
|
||
| expect(Facter.fact(:puppetdb_version).value).to eq('7.18.0') | ||
| expect(Facter.fact(:puppetdb_version).value).to be_nil | ||
| end | ||
| end | ||
| end | ||
|
|
||
| it 'returns nil if puppetdb command is not available' do | ||
| allow(Facter::Util::Resolution).to receive(:which).with('puppetdb').and_return(nil) | ||
| context 'when puppetdb is not available' do | ||
| before do | ||
| allow(Facter::Util::Resolution).to receive(:which).with('puppetdb').and_return(nil) | ||
| end | ||
|
|
||
| expect(Facter.fact(:puppetdb_version).value).to be_nil | ||
| it 'returns nil' do | ||
| expect(Facter.fact(:puppetdb_version).value).to be_nil | ||
| end | ||
| end | ||
| end |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.