|
1 |
| -# frozen_string_literal: true |
2 |
| - |
3 |
| -require 'spec_helper' |
4 | 1 | require 'facter'
|
5 | 2 |
|
6 | 3 | describe 'puppetdb_version' do
|
7 |
| - subject(:fact) { Facter.fact(:puppetdb_version) } |
8 |
| - |
9 | 4 | before(:each) do
|
10 | 5 | Facter.clear
|
11 | 6 | end
|
12 | 7 |
|
13 |
| - it 'returns the correct puppetdb version' do |
14 |
| - allow(Facter::Util::Resolution).to receive(:which).with('puppetdb').and_return('/usr/bin/puppetdb') |
15 |
| - allow(Facter::Core::Execution).to receive(:execute).with('puppetdb --version').and_return("puppetdb version: 7.18.0\n") |
| 8 | + context 'when puppetdb is available' do |
| 9 | + before(:each) do |
| 10 | + allow(Facter::Util::Resolution).to receive(:which).with('puppetdb').and_return('/usr/bin/puppetdb') |
| 11 | + end |
| 12 | + |
| 13 | + context 'on a default system' do |
| 14 | + it 'returns the correct version from puppetdb --version' do |
| 15 | + expect(Facter::Core::Execution).to receive(:execute) |
| 16 | + .with('puppetdb --version') |
| 17 | + .and_return('puppetdb version: 7.19.0') |
| 18 | + |
| 19 | + expect(Facter.fact(:puppetdb_version).value).to eq('7.19.0') |
| 20 | + end |
| 21 | + |
| 22 | + it 'returns nil if the command execution fails' do |
| 23 | + allow(Facter::Core::Execution).to receive(:execute).with('puppetdb --version').and_raise(Facter::Core::Execution::ExecutionFailure) |
16 | 24 |
|
17 |
| - expect(Facter.fact(:puppetdb_version).value).to eq('7.18.0') |
| 25 | + expect(Facter.fact(:puppetdb_version).value).to be_nil |
| 26 | + end |
| 27 | + end |
18 | 28 | end
|
19 | 29 |
|
20 |
| - it 'returns nil if puppetdb command is not available' do |
21 |
| - allow(Facter::Util::Resolution).to receive(:which).with('puppetdb').and_return(nil) |
| 30 | + context 'when puppetdb is not available' do |
| 31 | + before(:each) do |
| 32 | + allow(Facter::Util::Resolution).to receive(:which).with('puppetdb').and_return(nil) |
| 33 | + end |
22 | 34 |
|
23 |
| - expect(Facter.fact(:puppetdb_version).value).to be_nil |
| 35 | + it 'returns nil' do |
| 36 | + expect(Facter.fact(:puppetdb_version).value).to be_nil |
| 37 | + end |
24 | 38 | end
|
25 | 39 | end
|
0 commit comments