]> git.donarmstrong.com Git - dsa-puppet.git/blob - 3rdparty/modules/stdlib/spec/unit/facter/root_home_spec.rb
upgrade to stdlib 4.6.1
[dsa-puppet.git] / 3rdparty / modules / stdlib / spec / unit / facter / root_home_spec.rb
1 #! /usr/bin/env ruby -S rspec
2 require 'spec_helper'
3 require 'facter/root_home'
4
5 describe Facter::Util::RootHome do
6   context "solaris" do
7     let(:root_ent) { "root:x:0:0:Super-User:/:/sbin/sh" }
8     let(:expected_root_home) { "/" }
9
10     it "should return /" do
11       Facter::Util::Resolution.expects(:exec).with("getent passwd root").returns(root_ent)
12       expect(Facter::Util::RootHome.get_root_home).to eq(expected_root_home)
13     end
14   end
15   context "linux" do
16     let(:root_ent) { "root:x:0:0:root:/root:/bin/bash" }
17     let(:expected_root_home) { "/root" }
18
19     it "should return /root" do
20       Facter::Util::Resolution.expects(:exec).with("getent passwd root").returns(root_ent)
21       expect(Facter::Util::RootHome.get_root_home).to eq(expected_root_home)
22     end
23   end
24   context "windows" do
25     before :each do
26       Facter::Util::Resolution.expects(:exec).with("getent passwd root").returns(nil)
27     end
28     it "should be nil on windows" do
29       expect(Facter::Util::RootHome.get_root_home).to be_nil
30     end
31   end
32 end
33
34 describe 'root_home', :type => :fact do
35   before { Facter.clear }
36   after { Facter.clear }
37
38   context "macosx" do
39     before do
40       Facter.fact(:kernel).stubs(:value).returns("Darwin")
41       Facter.fact(:osfamily).stubs(:value).returns("Darwin")
42     end
43     let(:expected_root_home) { "/var/root" }
44     sample_dscacheutil = File.read(fixtures('dscacheutil','root'))
45
46     it "should return /var/root" do
47       Facter::Util::Resolution.stubs(:exec).with("dscacheutil -q user -a name root").returns(sample_dscacheutil)
48       expect(Facter.fact(:root_home).value).to eq(expected_root_home)
49     end
50   end
51
52 end