summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/facter/id.rb11
-rwxr-xr-xspec/unit/id_spec.rb27
2 files changed, 29 insertions, 9 deletions
diff --git a/lib/facter/id.rb b/lib/facter/id.rb
index c2c3594..1c42284 100644
--- a/lib/facter/id.rb
+++ b/lib/facter/id.rb
@@ -1,15 +1,8 @@
Facter.add(:id) do
- confine :operatingsystem => %w{Linux Fedora RedHat CentOS SuSE SLES Debian Ubuntu Gentoo AIX OEL OVS GNU/kFreeBSD windows}
setcode "whoami"
end
Facter.add(:id) do
- confine :operatingsystem => %w{Solaris}
- setcode do
- if %x{id} =~ /^uid=\d+\((\S+)\)/
- $1
- else
- nil
- end
- end
+ confine :kernel => :SunOS
+ setcode "/usr/xpg4/bin/id -un"
end
diff --git a/spec/unit/id_spec.rb b/spec/unit/id_spec.rb
new file mode 100755
index 0000000..a9e1797
--- /dev/null
+++ b/spec/unit/id_spec.rb
@@ -0,0 +1,27 @@
+#!/usr/bin/env ruby
+
+require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
+
+describe "id fact" do
+
+ kernel = [ 'Linux', 'Darwin', 'windows', 'FreeBSD', 'OpenBSD', 'NetBSD', 'AIX', 'HP-UX' ]
+
+ kernel.each do |k|
+ describe "with kernel reported as #{k}" do
+ it "should return the current user" do
+ Facter::Util::Resolution.stubs(:exec).with('uname -s').returns(k)
+ Facter::Util::Resolution.stubs(:exec).with('lsb_release -a 2>/dev/null').returns('foo')
+ Facter::Util::Resolution.expects(:exec).once.with('whoami', '/bin/sh').returns 'bar'
+
+ Facter.fact(:id).value.should == 'bar'
+ end
+ end
+ end
+
+ it "should return the current user on Solaris" do
+ Facter::Util::Resolution.stubs(:exec).with('uname -s').returns('SunOS')
+ Facter::Util::Resolution.expects(:exec).once.with('/usr/xpg4/bin/id -un', '/bin/sh').returns 'bar'
+
+ Facter.fact(:id).value.should == 'bar'
+ end
+end