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) { '/' }
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)
14 context 'when linux' do
15 let(:root_ent) { 'root:x:0:0:root:/root:/bin/bash' }
16 let(:expected_root_home) { '/root' }
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)
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
31 describe 'root_home', :type => :fact do
32 before(:each) { Facter.clear }
33 after(:each) { Facter.clear }
35 context 'when macosx' do
37 allow(Facter.fact(:kernel)).to receive(:value).and_return('Darwin')
38 allow(Facter.fact(:osfamily)).to receive(:value).and_return('Darwin')
40 let(:expected_root_home) { '/var/root' }
42 sample_dscacheutil = File.read(fixtures('dscacheutil', 'root'))
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)
52 allow(Facter.fact(:kernel)).to receive(:value).and_return('AIX')
53 allow(Facter.fact(:osfamily)).to receive(:value).and_return('AIX')
55 let(:expected_root_home) { '/root' }
57 sample_lsuser = File.read(fixtures('lsuser', 'root'))
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)