Skip to content

Commit a2e9d00

Browse files
committed
Merge pull request #215 from blkperl/add_root_home_to_mavericks
(PUP-1459) Add support for root_home on OS X 10.9
2 parents 2c8450d + fe676f0 commit a2e9d00

3 files changed

Lines changed: 41 additions & 9 deletions

File tree

lib/facter/root_home.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,16 @@ def get_root_home
1717
Facter.add(:root_home) do
1818
setcode { Facter::Util::RootHome.get_root_home }
1919
end
20+
21+
Facter.add(:root_home) do
22+
confine :kernel => :darwin
23+
setcode do
24+
str = Facter::Util::Resolution.exec("dscacheutil -q user -a name root")
25+
hash = {}
26+
str.split("\n").each do |pair|
27+
key,value = pair.split(/:/)
28+
hash[key] = value
29+
end
30+
hash['dir'].strip
31+
end
32+
end

spec/fixtures/dscacheutil/root

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
name: root
2+
password: *
3+
uid: 0
4+
gid: 0
5+
dir: /var/root
6+
shell: /bin/bash
7+
gecos: rawr Root
8+

spec/unit/facter/root_home_spec.rb

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,6 @@
2020
Facter::Util::RootHome.get_root_home.should == expected_root_home
2121
end
2222
end
23-
context "macosx" do
24-
let(:root_ent) { "root:*:0:0:System Administrator:/var/root:/bin/sh" }
25-
let(:expected_root_home) { "/var/root" }
26-
27-
it "should return /var/root" do
28-
Facter::Util::Resolution.expects(:exec).with("getent passwd root").returns(root_ent)
29-
Facter::Util::RootHome.get_root_home.should == expected_root_home
30-
end
31-
end
3223
context "windows" do
3324
before :each do
3425
Facter::Util::Resolution.expects(:exec).with("getent passwd root").returns(nil)
@@ -38,3 +29,23 @@
3829
end
3930
end
4031
end
32+
33+
describe 'root_home', :type => :fact do
34+
before { Facter.clear }
35+
after { Facter.clear }
36+
37+
context "macosx" do
38+
before do
39+
Facter.fact(:kernel).stubs(:value).returns("Darwin")
40+
Facter.fact(:osfamily).stubs(:value).returns("Darwin")
41+
end
42+
let(:expected_root_home) { "/var/root" }
43+
sample_dscacheutil = File.read(fixtures('dscacheutil','root'))
44+
45+
it "should return /var/root" do
46+
Facter::Util::Resolution.stubs(:exec).with("dscacheutil -q user -a name root").returns(sample_dscacheutil)
47+
Facter.fact(:root_home).value.should == expected_root_home
48+
end
49+
end
50+
51+
end

0 commit comments

Comments
 (0)