diff options
author | Jeremy MAURO <j.mauro@criteo.com> | 2015-02-02 11:48:24 +0100 |
---|---|---|
committer | Bryan McLellan <btm@chef.io> | 2015-03-27 13:48:58 -0700 |
commit | 55ae7f38627c6eab2599fb00fc59395b9d6a60e1 (patch) | |
tree | efc3c084ae202002e6cbad467797e1f1a57c5c59 | |
parent | 27350291b2c708189569eaa668deabc7bc96cf45 (diff) | |
download | ohai-55ae7f38627c6eab2599fb00fc59395b9d6a60e1.tar.gz |
Removing trailing space and '\r' for windows
-rw-r--r-- | lib/ohai/common/dmi.rb | 3 | ||||
-rw-r--r-- | lib/ohai/plugins/dmi.rb | 1 | ||||
-rw-r--r-- | spec/spec_helper.rb | 4 | ||||
-rw-r--r-- | spec/unit/plugins/dmi_spec.rb | 6 |
4 files changed, 13 insertions, 1 deletions
diff --git a/lib/ohai/common/dmi.rb b/lib/ohai/common/dmi.rb index 9ad27a2a..4bdce5cb 100644 --- a/lib/ohai/common/dmi.rb +++ b/lib/ohai/common/dmi.rb @@ -106,6 +106,7 @@ module Ohai next if field.to_s == 'size' next if field.to_s == 'record_id' translated = field.downcase.gsub(/[^a-z0-9]/, '_') + value = value.strip if in_common.has_key?(translated) in_common[translated] = nil unless in_common[translated] == value else @@ -115,7 +116,7 @@ module Ohai } in_common.each{ |field, value| next if value == nil - dmi[type][field] = value + dmi[type][field] = value.strip } } end diff --git a/lib/ohai/plugins/dmi.rb b/lib/ohai/plugins/dmi.rb index e63c7b92..24779ef2 100644 --- a/lib/ohai/plugins/dmi.rb +++ b/lib/ohai/plugins/dmi.rb @@ -57,6 +57,7 @@ Ohai.plugin(:DMI) do # ... similar lines trimmed so.stdout.lines do |line| next if blank_line.match(line) + line = line.encode(line.encoding, :universal_newline => true) if dmidecode_version = dmidecode_version_line.match(line) dmi[:dmidecode_version] = dmidecode_version[1] diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 6fa88491..69faded0 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -32,6 +32,10 @@ def get_plugin(plugin, ohai = Ohai::System.new, path = PLUGIN_PATH) loader.load_plugin(File.join(path, "#{plugin}.rb")) end +def convert_windows_output(stdout) + stdout.gsub("\n", "\r\n") +end + def it_should_check_from(plugin, attribute, from, value) it "should set the #{attribute} to the value from '#{from}'" do @plugin.run diff --git a/spec/unit/plugins/dmi_spec.rb b/spec/unit/plugins/dmi_spec.rb index 6afe3e38..3814920e 100644 --- a/spec/unit/plugins/dmi_spec.rb +++ b/spec/unit/plugins/dmi_spec.rb @@ -123,6 +123,12 @@ describe Ohai::System, "plugin dmi" do @plugin.run expect(@plugin[:dmi][id][attribute]).to eql(value) end + it "should have [:dmi][:#{id}][:#{attribute}] set for windows output" do + @stdout = convert_windows_output(DMI_OUT) + expect(@plugin).to receive(:shell_out).with("dmidecode").and_return(mock_shell_out(0, @stdout, "")) + @plugin.run + expect(@plugin[:dmi][id][attribute]).to eql(value) + end end end end |