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