File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -17,3 +17,16 @@ def get_root_home
1717Facter . add ( :root_home ) do
1818 setcode { Facter ::Util ::RootHome . get_root_home }
1919end
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
Original file line number Diff line number Diff line change 1+ name: root
2+ password: *
3+ uid: 0
4+ gid: 0
5+ dir: /var/root
6+ shell: /bin/bash
7+ gecos: rawr Root
8+
Original file line number Diff line number Diff line change 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 )
3829 end
3930 end
4031end
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
You can’t perform that action at this time.
0 commit comments