|
6 | 6 | end |
7 | 7 |
|
8 | 8 | context 'when puppetdb is available' do |
9 | | - before do |
| 9 | + before(:each) do |
10 | 10 | allow(Facter::Util::Resolution).to receive(:which).with('puppetdb').and_return('/usr/bin/puppetdb') |
11 | 11 | end |
12 | 12 |
|
13 | | - context 'on a Debian-based system' do |
14 | | - before do |
15 | | - allow(Facter).to receive(:value).with(:os).and_return({ 'family' => 'Debian' }) |
16 | | - end |
17 | | - |
18 | | - context 'when Puppet Labs is the maintainer' do |
19 | | - before do |
20 | | - allow(Facter::Core::Execution).to receive(:execute) |
21 | | - .with('apt-cache show puppetdb | grep "Maintainer:" | head -1') |
22 | | - .and_return('Maintainer: Puppet Labs') |
23 | | - end |
24 | | - |
25 | | - it 'returns the correct version from puppetdb --version' do |
26 | | - expect(Facter::Core::Execution).to receive(:execute) |
27 | | - .with('puppetdb --version') |
28 | | - .and_return('puppetdb version: 7.19.0') |
29 | | - |
30 | | - expect(Facter.fact(:puppetdb_version).value).to eq('7.19.0') |
31 | | - end |
32 | | - |
33 | | - it 'returns nil if the command execution fails' do |
34 | | - allow(Facter::Core::Execution).to receive(:execute).with('puppetdb --version').and_raise(Facter::Core::Execution::ExecutionFailure) |
35 | | - |
36 | | - expect(Facter.fact(:puppetdb_version).value).to be_nil |
37 | | - end |
38 | | - end |
39 | | - |
40 | | - context 'when Puppet Labs is not the maintainer' do |
41 | | - before do |
42 | | - allow(Facter::Core::Execution).to receive(:execute) |
43 | | - .with('apt-cache show puppetdb | grep "Maintainer:" | head -1') |
44 | | - .and_return('Maintainer: Other Maintainer') |
45 | | - end |
46 | | - |
47 | | - it 'returns the correct version from dpkg-query' do |
48 | | - expect(Facter::Core::Execution).to receive(:execute) |
49 | | - .with("dpkg-query --showformat='${Version}' --show puppetdb") |
50 | | - .and_return('7.9.0-1ubuntu1') |
51 | | - |
52 | | - expect(Facter.fact(:puppetdb_version).value).to eq('7.9.0') |
53 | | - end |
54 | | - |
55 | | - it 'returns nil if the command execution fails' do |
56 | | - allow(Facter::Core::Execution).to receive(:execute).with("dpkg-query --showformat='${Version}' --show puppetdb").and_raise(Facter::Core::Execution::ExecutionFailure) |
57 | | - |
58 | | - expect(Facter.fact(:puppetdb_version).value).to be_nil |
59 | | - end |
60 | | - end |
61 | | - end |
62 | | - |
63 | | - context 'on a non-Debian-based system' do |
64 | | - before do |
65 | | - allow(Facter).to receive(:value).with(:os).and_return({ 'family' => 'RedHat' }) |
66 | | - end |
67 | | - |
| 13 | + context 'on a default system' do |
68 | 14 | it 'returns the correct version from puppetdb --version' do |
69 | 15 | expect(Facter::Core::Execution).to receive(:execute) |
70 | 16 | .with('puppetdb --version') |
|
82 | 28 | end |
83 | 29 |
|
84 | 30 | context 'when puppetdb is not available' do |
85 | | - before do |
| 31 | + before(:each) do |
86 | 32 | allow(Facter::Util::Resolution).to receive(:which).with('puppetdb').and_return(nil) |
87 | 33 | end |
88 | 34 |
|
|
0 commit comments