diff options
author | Tim Smith <tsmith@chef.io> | 2018-02-12 22:47:11 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-02-12 22:47:11 +0100 |
commit | 8ce9f4d016b5edbb5d7faee6ab2e18bcccadf169 (patch) | |
tree | 501a87e5ccac503027b45cd3c61a4e310093e0a0 | |
parent | 849a4caf9926a4e11f12f9175b6f4dcd8a9ccaf1 (diff) | |
parent | 475d242c3d1cfc1ca752fe24272d35663c36d6c7 (diff) | |
download | ohai-8ce9f4d016b5edbb5d7faee6ab2e18bcccadf169.tar.gz |
Merge pull request #1132 from rmcleod8/patch-1
adds whitespace stripping for the shellout stdout
-rw-r--r-- | lib/ohai/plugins/aix/uptime.rb | 2 | ||||
-rw-r--r-- | spec/unit/plugins/aix/uptime_spec.rb | 14 |
2 files changed, 10 insertions, 6 deletions
diff --git a/lib/ohai/plugins/aix/uptime.rb b/lib/ohai/plugins/aix/uptime.rb index 85537ba7..ec515aa2 100644 --- a/lib/ohai/plugins/aix/uptime.rb +++ b/lib/ohai/plugins/aix/uptime.rb @@ -27,7 +27,7 @@ Ohai.plugin(:Uptime) do # 1148-20:54:50 # This reads as 1148 days, 20 hours, 54 minutes, 50 seconds since the process was started (elapsed) # who -b does not return the YEAR, so we need something more concrete - so = shell_out("LC_ALL=POSIX ps -o etime= -p 1").stdout + so = shell_out("LC_ALL=POSIX ps -o etime= -p 1").stdout.strip # Here we'll check our shell_out for a dash, which indicates there is a # of days involved # We'll chunk off the days, hours (where applicable), minutes, seconds into seperate vars diff --git a/spec/unit/plugins/aix/uptime_spec.rb b/spec/unit/plugins/aix/uptime_spec.rb index f9bf2368..d3cf47c8 100644 --- a/spec/unit/plugins/aix/uptime_spec.rb +++ b/spec/unit/plugins/aix/uptime_spec.rb @@ -24,15 +24,19 @@ describe Ohai::System, "Aix plugin uptime" do @plugin = get_plugin("aix/uptime") allow(@plugin).to receive(:collect_os).and_return(:aix) allow(@plugin).to receive(:shell_out).and_call_original - allow(@plugin).to receive(:shell_out).with("LC_ALL=POSIX ps -o etime= -p 1").and_return(mock_shell_out(0, "1148-20:54:50", nil)) - @plugin.run end - it "should set uptime_seconds to uptime with days" do + it "should set uptime_seconds and uptime standard case" do + allow(@plugin).to receive(:shell_out).with("LC_ALL=POSIX ps -o etime= -p 1").and_return(mock_shell_out(0, "1148-20:54:50", nil)) + @plugin.run expect(@plugin[:uptime_seconds]).to eq(99262490) + expect(@plugin[:uptime]).to eq("1148 days 20 hours 54 minutes 50 seconds") end - it "should set uptime to a human readable date with days" do - expect(@plugin[:uptime]).to eq("1148 days 20 hours 54 minutes 50 seconds") + it "should set uptime_seconds and uptime in the whitespace case" do + allow(@plugin).to receive(:shell_out).with("LC_ALL=POSIX ps -o etime= -p 1").and_return(mock_shell_out(0, " 2-20:54:50", nil)) + @plugin.run + expect(@plugin[:uptime_seconds]).to eq(248090) + expect(@plugin[:uptime]).to eq("2 days 20 hours 54 minutes 50 seconds") end end |