File tree 3 files changed +60
-0
lines changed
3 files changed +60
-0
lines changed Original file line number Diff line number Diff line change
1
+ # A facter fact to determine the root home directory.
2
+ # This varies on PE supported platforms and may be
3
+ # reconfigured by the end user.
4
+
5
+ module Facter ::Util ::RootHome
6
+ class << self
7
+ def get_root_home
8
+ root_ent = Facter ::Util ::Resolution . exec ( "getent passwd root" )
9
+ # The home directory is the sixth element in the passwd entry
10
+ root_ent . split ( ":" ) [ 5 ]
11
+ end
12
+ end
13
+ end
14
+
15
+ Facter . add ( :root_home ) do
16
+ setcode { Facter ::Util ::RootHome . get_root_home }
17
+ end
Original file line number Diff line number Diff line change 7
7
ARGV . clear
8
8
9
9
require 'puppet'
10
+ require 'facter'
10
11
require 'mocha'
11
12
gem 'rspec' , '>=2.0.0'
12
13
require 'rspec/expectations'
Original file line number Diff line number Diff line change
1
+ require 'spec_helper'
2
+ require 'facter/root_home'
3
+
4
+ describe Facter ::Util ::RootHome do
5
+ context "solaris" do
6
+ let ( :root_ent ) { "root:x:0:0:Super-User:/:/sbin/sh" }
7
+ let ( :expected_root_home ) { "/" }
8
+
9
+ it "should return /" do
10
+ Facter ::Util ::Resolution . expects ( :exec ) . with ( "getent passwd root" ) . returns ( root_ent )
11
+ Facter ::Util ::RootHome . get_root_home . should == expected_root_home
12
+ end
13
+ end
14
+ context "linux" do
15
+ let ( :root_ent ) { "root:x:0:0:root:/root:/bin/bash" }
16
+ let ( :expected_root_home ) { "/root" }
17
+
18
+ it "should return /root" do
19
+ Facter ::Util ::Resolution . expects ( :exec ) . with ( "getent passwd root" ) . returns ( root_ent )
20
+ Facter ::Util ::RootHome . get_root_home . should == expected_root_home
21
+ end
22
+ 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
32
+ context "windows" do
33
+ let ( :root_ent ) { "FIXME TBD on Windows" }
34
+ let ( :expected_root_home ) { "FIXME TBD on Windows" }
35
+
36
+ it "should return FIXME TBD on windows" do
37
+ pending "FIXME: TBD on windows"
38
+ Facter ::Util ::Resolution . expects ( :exec ) . with ( "getent passwd root" ) . returns ( root_ent )
39
+ Facter ::Util ::RootHome . get_root_home . should == expected_root_home
40
+ end
41
+ end
42
+ end
You can’t perform that action at this time.
0 commit comments