|
2 | 2 |
|
3 | 3 | require 'spec_helper' |
4 | 4 | require 'facter/root_home' |
5 | | -describe 'Root Home Specs' do |
6 | | - describe Facter::Util::RootHome do |
7 | | - context 'when solaris' do |
8 | | - let(:root_ent) { 'root:x:0:0:Super-User:/:/sbin/sh' } |
9 | | - let(:expected_root_home) { '/' } |
10 | 5 |
|
11 | | - it 'returns /' do |
12 | | - expect(Facter::Core::Execution).to receive(:execute).with('getent passwd root').and_return(root_ent) |
13 | | - expect(described_class.returnt_root_home).to eq(expected_root_home) |
14 | | - end |
15 | | - end |
16 | | - context 'when linux' do |
17 | | - let(:root_ent) { 'root:x:0:0:root:/root:/bin/bash' } |
18 | | - let(:expected_root_home) { '/root' } |
| 6 | +describe 'root_home', type: :fact do |
| 7 | + subject { Facter.fact(:root_home) } |
19 | 8 |
|
20 | | - it 'returns /root' do |
21 | | - expect(Facter::Core::Execution).to receive(:execute).with('getent passwd root').and_return(root_ent) |
22 | | - expect(described_class.returnt_root_home).to eq(expected_root_home) |
23 | | - end |
24 | | - end |
25 | | - context 'when windows' do |
26 | | - it 'is nil on windows' do |
27 | | - expect(Facter::Core::Execution).to receive(:execute).with('getent passwd root').and_return(nil) |
28 | | - expect(described_class.returnt_root_home).to be_nil |
29 | | - end |
30 | | - end |
31 | | - end |
32 | | - |
33 | | - describe 'root_home', type: :fact do |
34 | | - before(:each) { Facter.clear } |
35 | | - after(:each) { Facter.clear } |
36 | | - |
37 | | - context 'when macosx' do |
38 | | - before(:each) do |
39 | | - allow(Facter.fact(:kernel)).to receive(:value).and_return('Darwin') |
40 | | - allow(Facter.fact(:osfamily)).to receive(:value).and_return('Darwin') |
41 | | - end |
42 | | - let(:expected_root_home) { '/var/root' } |
| 9 | + before(:each) { Facter.clear } |
| 10 | + after(:each) { Facter.clear } |
43 | 11 |
|
44 | | - sample_dscacheutil = File.read(fixtures('dscacheutil', 'root')) |
45 | | - |
46 | | - it 'returns /var/root' do |
47 | | - allow(Facter::Core::Execution).to receive(:execute).with('dscacheutil -q user -a name root').and_return(sample_dscacheutil) |
48 | | - expect(Facter.fact(:root_home).value).to eq(expected_root_home) |
49 | | - end |
50 | | - end |
51 | | - |
52 | | - context 'when aix' do |
53 | | - before(:each) do |
54 | | - allow(Facter.fact(:kernel)).to receive(:value).and_return('AIX') |
55 | | - allow(Facter.fact(:osfamily)).to receive(:value).and_return('AIX') |
56 | | - end |
57 | | - let(:expected_root_home) { '/root' } |
| 12 | + context 'when Windows', if: Facter.value(:kernel) == 'Windows' do |
| 13 | + it { expect(subject.value).to be(nil) } |
| 14 | + end |
58 | 15 |
|
59 | | - sample_lsuser = File.read(fixtures('lsuser', 'root')) |
| 16 | + context 'when non-Windows', if: Facter.value(:kernel) != 'Windows' do |
| 17 | + let(:expected) { Facter.value(:kernel) == 'Darwin' ? '/var/root' : '/root' } |
60 | 18 |
|
61 | | - it 'returns /root' do |
62 | | - allow(Facter::Core::Execution).to receive(:execute).with('lsuser -c -a home root').and_return(sample_lsuser) |
63 | | - expect(Facter.fact(:root_home).value).to eq(expected_root_home) |
64 | | - end |
65 | | - end |
| 19 | + it { expect(subject.value).to eq(expected) } |
66 | 20 | end |
67 | 21 | end |
0 commit comments