diff options
-rw-r--r-- | bin/grab_data.rb | 5 | ||||
-rw-r--r-- | spec/unit/path/ohai_plugin_common.rb | 106 | ||||
-rw-r--r-- | spec/unit/path/ohai_plugin_common_spec.rb | 2 | ||||
-rw-r--r-- | spec/unit/plugins/erlang_spec.rb | 70 | ||||
-rw-r--r-- | spec/unit/plugins/java_spec.rb | 164 | ||||
-rw-r--r-- | spec/unit/plugins/linux/kernel_spec.rb | 29 | ||||
-rw-r--r-- | spec/unit/plugins/lua_spec.rb | 60 | ||||
-rw-r--r-- | spec/unit/plugins/nodejs_spec.rb | 51 | ||||
-rw-r--r-- | spec/unit/plugins/perl_spec.rb | 121 | ||||
-rw-r--r-- | spec/unit/plugins/php_spec.rb | 69 | ||||
-rw-r--r-- | spec/unit/plugins/python_spec.rb | 61 |
11 files changed, 370 insertions, 368 deletions
diff --git a/bin/grab_data.rb b/bin/grab_data.rb index 60039a58..6776bf4a 100644 --- a/bin/grab_data.rb +++ b/bin/grab_data.rb @@ -73,11 +73,10 @@ cli.parse_options cmd, params, platform, arch, env = cli.config[:command], cli.config[:params], cli.config[:platform], cli.config[:arch], cli.config[:env] # read in data -opc = OhaiPluginCommon.new # filename = cmd + ".output" # Mixlib::ShellOut.new("touch #{filename}").run_command -# data = opc.read_output cmd, File.expand_path( File.dirname(__FILE__)) +# data = OhaiPluginCommon.read_output cmd, File.expand_path( File.dirname(__FILE__)) data ||= {} data[platform] ||= {} data[platform][arch] ||= [] @@ -101,4 +100,4 @@ results.each do |r| data[platform][arch] << r end -puts opc.data_to_string data +puts OhaiPluginCommon.data_to_string data diff --git a/spec/unit/path/ohai_plugin_common.rb b/spec/unit/path/ohai_plugin_common.rb index 39e3de48..70c56bef 100644 --- a/spec/unit/path/ohai_plugin_common.rb +++ b/spec/unit/path/ohai_plugin_common.rb @@ -21,7 +21,7 @@ require 'rspec' require 'ohai' require 'yaml' -class OhaiPluginCommon +module OhaiPluginCommon def fake_command(data, platform, arch, env) # If the platform or architecture aren't set, take the first one @@ -47,20 +47,10 @@ class OhaiPluginCommon File.expand_path(File.dirname(__FILE__) + '../../../data/plugins') end - def get_path(path) + def get_path(path = '') File.expand_path(File.dirname(__FILE__) + path) end - def set_path(path) - ENV['PATH'] = File.expand_path(File.dirname(__FILE__) + path) - end - - def set_env(platform = nil, arch = nil, env = nil) - ENV['OHAI_TEST_PLATFORM'] = platform.to_s if !platform.nil? - ENV['OHAI_TEST_ARCH'] = arch.to_s if !arch.nil? - ENV['OHAI_TEST_ENVIRONMENT'] = env.to_json if !env.nil? - end - #checks to see if the elements in test are also in source. Recursively decends into Hashes. #nil values in test match against both nil and non-existance in source. def subsumes?(source, test) @@ -70,49 +60,8 @@ class OhaiPluginCommon source == test end end - - def check_expected(plugin_names, expected_data, cmd_list) - RSpec.describe "cross platform data" do - expected_data.each do |e| - e[:platform].each do |platform| - e[:arch].each do |arch| - e[:env].each do |env| - it "provides data when the platform is '#{platform}', the architecture is '#{arch}' and the environment is '#{env}'" do - @opc = OhaiPluginCommon.new - path = @opc.get_path '/../path' - cmd_not_found = Set.new - - cmd_list.each do |c| - data = @opc.read_output c - data = data[platform][arch].select { |f| f[:env] == env } - if data.all? { |f| /command not found/ =~ f[:stderr] && f[:exit_status] == 127 } - cmd_not_found.add c - else - @opc.create_exe c, path, platform, arch, env - end - end - - old_path = ENV['PATH'] - ENV['PATH'] = path - - @ohai = Ohai::System.new - - begin - plugin_names.each{ |plugin_name| @ohai.require_plugin plugin_name } - ensure - ENV['PATH'] = old_path - cmd_list.each { |c| Mixlib::ShellOut.new("rm #{path}/#{c}").run_command if !cmd_not_found.include?( c ) } - end - - @opc.subsumes?(@ohai.data, e[:ohai]).should be_true - end - end - end - end - end - end - end + # read in the data file for fake executables def read_output( cmd, path = "#{data_path}" ) #using an anonymous class to minimize scoping issues. @@ -151,6 +100,7 @@ class OhaiPluginCommon @data.process end + # output a fake executable case in the DSL def to_fake_exe_format(platform, arch, env, params, stdout, stderr, exit_status) <<-eos platform "#{platform}" @@ -163,6 +113,7 @@ exit_status #{exit_status} eos end + # prep fake executable data for writing to a file def data_to_string(data) a = data.map do |platform,v| v.map do |arch,v| @@ -183,10 +134,55 @@ eos require 'yaml' require '#{path}/ohai_plugin_common.rb' -OhaiPluginCommon.new.fake_command OhaiPluginCommon.new.read_output( '#{cmd}' ), '#{platform}', '#{arch}', #{env} +OhaiPluginCommon.fake_command OhaiPluginCommon.read_output( '#{cmd}' ), '#{platform}', '#{arch}', #{env} eof File.open(cmd_path, "w") { |f| f.puts file } sleep 0.01 until File.exists? cmd_path Mixlib::ShellOut.new("chmod 755 #{cmd_path}").run_command end + + module_function( :fake_command, :data_path, :get_path, :subsumes?, :read_output, + :to_fake_exe_format, :data_to_string, :create_exe ) + + # for use in + shared_context "cross platform data" do + shared_examples_for "a plugin" do |plugin_names, data, cmd_list| + data.each do |e| + e[:platform].each do |platform| + e[:arch].each do |arch| + e[:env].each do |env| + it "provides data when the platform is '#{platform}', the architecture is '#{arch}' and the environment is '#{env}'" do + path = OhaiPluginCommon.get_path + cmd_not_found = Set.new + + cmd_list.each do |c| + data = OhaiPluginCommon.read_output c + data = data[platform][arch].select { |f| f[:env] == env } + if data.all? { |f| /command not found/ =~ f[:stderr] && f[:exit_status] == 127 } + cmd_not_found.add c + else + OhaiPluginCommon.create_exe c, path, platform, arch, env + end + end + + old_path = ENV['PATH'] + ENV['PATH'] = path + + @ohai = Ohai::System.new + + begin + plugin_names.each { |plugin_name| @ohai.require_plugin plugin_name } + ensure + ENV['PATH'] = old_path + cmd_list.each { |c| Mixlib::ShellOut.new("rm #{path}/#{c}").run_command if !cmd_not_found.include?( c )} + end + + OhaiPluginCommon.subsumes?( @ohai.data, e[:ohai] ).should be_true + end + end + end + end + end + end + end end diff --git a/spec/unit/path/ohai_plugin_common_spec.rb b/spec/unit/path/ohai_plugin_common_spec.rb index 57784aa1..7ccc0f92 100644 --- a/spec/unit/path/ohai_plugin_common_spec.rb +++ b/spec/unit/path/ohai_plugin_common_spec.rb @@ -21,7 +21,7 @@ require File.expand_path(File.dirname(__FILE__) + "/ohai_plugin_common.rb") describe OhaiPluginCommon, "subsumes?" do before(:each) do @hash = { "languages" => { "python" => { "version" => "1.6.2", "type" => "interpreted" }}} - @opc = OhaiPluginCommon.new + @opc = OhaiPluginCommon end it "returns true if given an exact duplicate" do diff --git a/spec/unit/plugins/erlang_spec.rb b/spec/unit/plugins/erlang_spec.rb index b13d5210..77d070e3 100644 --- a/spec/unit/plugins/erlang_spec.rb +++ b/spec/unit/plugins/erlang_spec.rb @@ -62,40 +62,42 @@ describe Ohai::System, "plugin erlang" do @plugin.run @plugin.languages.should_not have_key(:erlang) end -end -########## -expected = [{ - :env => [[]], - :platform => ["centos-5.9", "centos-6.4", "ubuntu-10.04", "ubuntu-12.04"], - :arch => ["x86", "x64"], - :ohai => { "languages" => { "erlang" => nil }}, - },{ - :env => [[]], - :platform => ["ubuntu-13.04"], - :arch => ["x64"], - :ohai => { "languages" => { "erlang" => nil }}, - },{ - :env => [["erlang"]], - :platform => ["centos-5.9", "centos-6.4"], - :arch => ["x86", "x64"], - :ohai => { "languages" => { "erlang" => { "version" => "5.8.5", "options" => ["ASYNC_THREADS"], "emulator" => "BEAM" }}}, - },{ - :env => [["erlang"]], - :platform => ["ubuntu-10.04"], - :arch => ["x86", "x64"], - :ohai => { "languages" => { "erlang" => { "version" => "5.7.4", "options" => ["ASYNC_THREADS", "HIPE"], "emulator" => "BEAM" }}}, - },{ - :env => [["erlang"]], - :platform => ["ubuntu-12.04"], - :arch => ["x86", "x64"], - :ohai => { "languages" => { "erlang" => { "version" => "5.8.5", "options" => ["ASYNC_THREADS"], "emulator" => "BEAM" }}}, - },{ - :env => [["erlang"]], - :platform => ["ubuntu-13.04"], - :arch => ["x64"], - :ohai => { "languages" => { "erlang" => { "version" => "5.9.1", "options" => ["ASYNC_THREADS"], "emulator" => "BEAM" }}}, - }] + ########## + + expected = [{ + :env => [[]], + :platform => ["centos-5.9", "centos-6.4", "ubuntu-10.04", "ubuntu-12.04"], + :arch => ["x86", "x64"], + :ohai => { "languages" => { "erlang" => nil }}, + },{ + :env => [[]], + :platform => ["ubuntu-13.04"], + :arch => ["x64"], + :ohai => { "languages" => { "erlang" => nil }}, + },{ + :env => [["erlang"]], + :platform => ["centos-5.9", "centos-6.4"], + :arch => ["x86", "x64"], + :ohai => { "languages" => { "erlang" => { "version" => "5.8.5", "options" => ["ASYNC_THREADS"], "emulator" => "BEAM" }}}, + },{ + :env => [["erlang"]], + :platform => ["ubuntu-10.04"], + :arch => ["x86", "x64"], + :ohai => { "languages" => { "erlang" => { "version" => "5.7.4", "options" => ["ASYNC_THREADS", "HIPE"], "emulator" => "BEAM" }}}, + },{ + :env => [["erlang"]], + :platform => ["ubuntu-12.04"], + :arch => ["x86", "x64"], + :ohai => { "languages" => { "erlang" => { "version" => "5.8.5", "options" => ["ASYNC_THREADS"], "emulator" => "BEAM" }}}, + },{ + :env => [["erlang"]], + :platform => ["ubuntu-13.04"], + :arch => ["x64"], + :ohai => { "languages" => { "erlang" => { "version" => "5.9.1", "options" => ["ASYNC_THREADS"], "emulator" => "BEAM" }}}, + }] -OhaiPluginCommon.new.check_expected ["erlang"], expected, ["erl"] + include_context "cross platform data" + it_behaves_like "a plugin", ["erlang"], expected, ["erl"] +end diff --git a/spec/unit/plugins/java_spec.rb b/spec/unit/plugins/java_spec.rb index 7bed7f57..bb1bb782 100644 --- a/spec/unit/plugins/java_spec.rb +++ b/spec/unit/plugins/java_spec.rb @@ -121,85 +121,87 @@ describe Ohai::System, "plugin java (Java6 Server VM)" do @plugin.run @plugin[:languages].should_not have_key(:java) end -end -########### - -require File.expand_path(File.dirname(__FILE__) + '/../path/ohai_plugin_common.rb') - -expected = [{ - :env => [[]], - :platform => ["centos-5.9", "centos-6.4", "ubuntu-10.04", "ubuntu-12.04"], - :arch => ["x86", "x64"], - :ohai => { "languages" => { "java" => nil }}, - },{ - :env => [[]], - :platform => ["ubuntu-13.04"], - :arch => ["x64"], - :ohai => { "languages" => { "java" => nil }}, - },{ - :env => [["java"]], - :platform => ["centos-5.9"], - :arch => ["x86"], - :ohai => { "languages" => { "java" => { "version" => "1.6.0_24", - "runtime" => { "name" => "OpenJDK Runtime Environment (IcedTea6 1.11.11.90)", "build" => "rhel-1.41.1.11.11.90.el5_9-i386" }, - "hotspot" => { "name" => "OpenJDK Client VM", "build" => "20.0-b12, mixed mode" }}}}, - },{ - :env => [["java"]], - :platform => ["centos-5.9"], - :arch => ["x64"], - :ohai => { "languages" => { "java" => { "version" => "1.6.0_24", - "runtime" => { "name" => "OpenJDK Runtime Environment (IcedTea6 1.11.11.90)", "build" => "rhel-1.41.1.11.11.90.el5_9-x86_64" }, - "hotspot" => { "name" => "OpenJDK 64-Bit Server VM", "build" => "20.0-b12, mixed mode" }}}}, - },{ - :env => [["java"]], - :platform => ["centos-6.4"], - :arch => ["x86"], - :ohai => { "languages" => { "java" => { "version" => "1.6.0_24", - "runtime" => { "name" => "OpenJDK Runtime Environment (IcedTea6 1.11.11.90)", "build" => "rhel-1.62.1.11.11.90.el6_4-i386" }, - "hotspot" => { "name" => "OpenJDK Client VM", "build" => "20.0-b12, mixed mode" }}}}, - },{ - :env => [["java"]], - :platform => ["centos-6.4"], - :arch => ["x64"], - :ohai => { "languages" => { "java" => { "version" => "1.6.0_24", - "runtime" => { "name" => "OpenJDK Runtime Environment (IcedTea6 1.11.11.90)", "build" => "rhel-1.62.1.11.11.90.el6_4-x86_64" }, - "hotspot" => { "name" => "OpenJDK 64-Bit Server VM", "build" => "20.0-b12, mixed mode" }}}}, - },{ - :env => [["java"]], - :platform => ["ubuntu-10.04"], - :arch => ["x86"], - :ohai => { "languages" => { "java" => { "version" => "1.6.0_27", - "runtime" => { "name" => "OpenJDK Runtime Environment (IcedTea6 1.12.5)", "build" => "6b27-1.12.5-0ubuntu0.10.04.1" }, - "hotspot" => { "name" => "OpenJDK Client VM", "build" => "20.0-b12, mixed mode, sharing" }}}}, - },{ - :env => [["java"]], - :platform => ["ubuntu-10.04"], - :arch => ["x64"], - :ohai => { "languages" => { "java" => { "version" => "1.6.0_27", - "runtime" => { "name" => "OpenJDK Runtime Environment (IcedTea6 1.12.5)", "build" => "6b27-1.12.5-0ubuntu0.10.04.1" }, - "hotspot" => { "name" => "OpenJDK 64-Bit Server VM", "build" => "20.0-b12, mixed mode" }}}}, - },{ - :env => [["java"]], - :platform => ["ubuntu-12.04"], - :arch => ["x86"], - :ohai => { "languages" => { "java" => { "version" => "1.6.0_27", - "runtime" => { "name" => "OpenJDK Runtime Environment (IcedTea6 1.12.5)", "build" => "6b27-1.12.5-0ubuntu0.12.04.1" }, - "hotspot" => { "name" => "OpenJDK Client VM", "build" => "20.0-b12, mixed mode, sharing" }}}}, - },{ - :env => [["java"]], - :platform => ["ubuntu-12.04"], - :arch => ["x64"], - :ohai => { "languages" => { "java" => { "version" => "1.6.0_27", - "runtime" => { "name" => "OpenJDK Runtime Environment (IcedTea6 1.12.5)", "build" => "6b27-1.12.5-0ubuntu0.12.04.1" }, - "hotspot" => { "name" => "OpenJDK 64-Bit Server VM", "build" => "20.0-b12, mixed mode" }}}}, - },{ - :env => [["java"]], - :platform => ["ubuntu-13.04"], - :arch => ["x64"], - :ohai => { "languages" => { "java" => { "version" => "1.6.0_27", - "runtime" => { "name" => "OpenJDK Runtime Environment (IcedTea6 1.12.5)", "build" => "6b27-1.12.5-1ubuntu1" }, - "hotspot" => { "name" => "OpenJDK 64-Bit Server VM", "build" => "20.0-b12, mixed mode" }}}}, - }] - -OhaiPluginCommon.new.check_expected ["java"], expected, ["java"] + + ########### + + require File.expand_path(File.dirname(__FILE__) + '/../path/ohai_plugin_common.rb') + + expected = [{ + :env => [[]], + :platform => ["centos-5.9", "centos-6.4", "ubuntu-10.04", "ubuntu-12.04"], + :arch => ["x86", "x64"], + :ohai => { "languages" => { "java" => nil }}, + },{ + :env => [[]], + :platform => ["ubuntu-13.04"], + :arch => ["x64"], + :ohai => { "languages" => { "java" => nil }}, + },{ + :env => [["java"]], + :platform => ["centos-5.9"], + :arch => ["x86"], + :ohai => { "languages" => { "java" => { "version" => "1.6.0_24", + "runtime" => { "name" => "OpenJDK Runtime Environment (IcedTea6 1.11.11.90)", "build" => "rhel-1.41.1.11.11.90.el5_9-i386" }, + "hotspot" => { "name" => "OpenJDK Client VM", "build" => "20.0-b12, mixed mode" }}}}, + },{ + :env => [["java"]], + :platform => ["centos-5.9"], + :arch => ["x64"], + :ohai => { "languages" => { "java" => { "version" => "1.6.0_24", + "runtime" => { "name" => "OpenJDK Runtime Environment (IcedTea6 1.11.11.90)", "build" => "rhel-1.41.1.11.11.90.el5_9-x86_64" }, + "hotspot" => { "name" => "OpenJDK 64-Bit Server VM", "build" => "20.0-b12, mixed mode" }}}}, + },{ + :env => [["java"]], + :platform => ["centos-6.4"], + :arch => ["x86"], + :ohai => { "languages" => { "java" => { "version" => "1.6.0_24", + "runtime" => { "name" => "OpenJDK Runtime Environment (IcedTea6 1.11.11.90)", "build" => "rhel-1.62.1.11.11.90.el6_4-i386" }, + "hotspot" => { "name" => "OpenJDK Client VM", "build" => "20.0-b12, mixed mode" }}}}, + },{ + :env => [["java"]], + :platform => ["centos-6.4"], + :arch => ["x64"], + :ohai => { "languages" => { "java" => { "version" => "1.6.0_24", + "runtime" => { "name" => "OpenJDK Runtime Environment (IcedTea6 1.11.11.90)", "build" => "rhel-1.62.1.11.11.90.el6_4-x86_64" }, + "hotspot" => { "name" => "OpenJDK 64-Bit Server VM", "build" => "20.0-b12, mixed mode" }}}}, + },{ + :env => [["java"]], + :platform => ["ubuntu-10.04"], + :arch => ["x86"], + :ohai => { "languages" => { "java" => { "version" => "1.6.0_27", + "runtime" => { "name" => "OpenJDK Runtime Environment (IcedTea6 1.12.5)", "build" => "6b27-1.12.5-0ubuntu0.10.04.1" }, + "hotspot" => { "name" => "OpenJDK Client VM", "build" => "20.0-b12, mixed mode, sharing" }}}}, + },{ + :env => [["java"]], + :platform => ["ubuntu-10.04"], + :arch => ["x64"], + :ohai => { "languages" => { "java" => { "version" => "1.6.0_27", + "runtime" => { "name" => "OpenJDK Runtime Environment (IcedTea6 1.12.5)", "build" => "6b27-1.12.5-0ubuntu0.10.04.1" }, + "hotspot" => { "name" => "OpenJDK 64-Bit Server VM", "build" => "20.0-b12, mixed mode" }}}}, + },{ + :env => [["java"]], + :platform => ["ubuntu-12.04"], + :arch => ["x86"], + :ohai => { "languages" => { "java" => { "version" => "1.6.0_27", + "runtime" => { "name" => "OpenJDK Runtime Environment (IcedTea6 1.12.5)", "build" => "6b27-1.12.5-0ubuntu0.12.04.1" }, + "hotspot" => { "name" => "OpenJDK Client VM", "build" => "20.0-b12, mixed mode, sharing" }}}}, + },{ + :env => [["java"]], + :platform => ["ubuntu-12.04"], + :arch => ["x64"], + :ohai => { "languages" => { "java" => { "version" => "1.6.0_27", + "runtime" => { "name" => "OpenJDK Runtime Environment (IcedTea6 1.12.5)", "build" => "6b27-1.12.5-0ubuntu0.12.04.1" }, + "hotspot" => { "name" => "OpenJDK 64-Bit Server VM", "build" => "20.0-b12, mixed mode" }}}}, + },{ + :env => [["java"]], + :platform => ["ubuntu-13.04"], + :arch => ["x64"], + :ohai => { "languages" => { "java" => { "version" => "1.6.0_27", + "runtime" => { "name" => "OpenJDK Runtime Environment (IcedTea6 1.12.5)", "build" => "6b27-1.12.5-1ubuntu1" }, + "hotspot" => { "name" => "OpenJDK 64-Bit Server VM", "build" => "20.0-b12, mixed mode" }}}}, + }] + + include_context "cross platform data" + it_behaves_like "a plugin", ["java"], expected, ["java"] +end diff --git a/spec/unit/plugins/linux/kernel_spec.rb b/spec/unit/plugins/linux/kernel_spec.rb index a3db664f..2a038f2d 100644 --- a/spec/unit/plugins/linux/kernel_spec.rb +++ b/spec/unit/plugins/linux/kernel_spec.rb @@ -33,20 +33,19 @@ describe Ohai::System, "Linux kernel plugin" do end it_should_check_from_deep_mash("linux::kernel", "kernel", "os", "uname -o", "Linux") -end - -############################### -expected = [{ - :env => [[]], - :platform => ["centos-5.9", "centos-6.4", "ubuntu-10.04", "ubuntu-12.04"], - :arch => ["x86", "x64"], - :ohai => { "kernel" => { "os" => "GNU/Linux" }}, - },{ - :env => [[]], - :platform => ["ubuntu-13.04"], - :arch => ["x64"], - :ohai => { "kernel" => { "os" => "GNU/Linux" }}, - }] + expected = [{ + :env => [[]], + :platform => ["centos-5.9", "centos-6.4", "ubuntu-10.04", "ubuntu-12.04"], + :arch => ["x86", "x64"], + :ohai => { "kernel" => { "os" => "GNU/Linux" }}, + },{ + :env => [[]], + :platform => ["ubuntu-13.04"], + :arch => ["x64"], + :ohai => { "kernel" => { "os" => "GNU/Linux" }}, + }] -OhaiPluginCommon.new.check_expected ["kernel", "linux/kernel"], expected, ["uname", "lsmod"] + include_context "cross platform data" + it_behaves_like "a plugin", ["kernel", "linux/kernel"], expected, ["uname", "lsmod"] +end diff --git a/spec/unit/plugins/lua_spec.rb b/spec/unit/plugins/lua_spec.rb index 9f9a4e9b..351b5244 100644 --- a/spec/unit/plugins/lua_spec.rb +++ b/spec/unit/plugins/lua_spec.rb @@ -53,35 +53,35 @@ describe Ohai::System, "plugin lua" do @plugin.languages.should_not have_key(:lua) end -end - -require File.expand_path(File.join(File.dirname(__FILE__), '..', 'path', '/ohai_plugin_common.rb')) + require File.expand_path(File.join(File.dirname(__FILE__), '..', 'path', '/ohai_plugin_common.rb')) -expected = [{ - :platform => ["centos-6.4"], - :arch => ["x86", "x64"], - :env => [[], ["lua"]], - :ohai => { "languages" => { "lua" => { "version" => "5.1.4" }}}, - },{ - :platform => ["ubuntu-10.04", "ubuntu-12.04"], - :arch => ["x86", "x64"], - :env => [[]], - :ohai => { "languages" => { "lua" => nil }}, - },{ - :platform => ["ubuntu-13.04"], - :arch => ["x64"], - :env => [[]], - :ohai => { "languages" => { "lua" => nil }}, - },{ - :platform => ["ubuntu-10.04", "ubuntu-12.04" ], - :arch => ["x86", "x64"], - :env => [["lua"]], - :ohai => { "languages" => { "lua" => { "version" => "5.1.4" }}}, - },{ - :platform => ["ubuntu-13.04"], - :arch => ["x64"], - :env => [["lua"]], - :ohai => { "languages" => { "lua" => { "version" => "5.1.5" }}}, - }] + expected = [{ + :platform => ["centos-6.4"], + :arch => ["x86", "x64"], + :env => [[], ["lua"]], + :ohai => { "languages" => { "lua" => { "version" => "5.1.4" }}}, + },{ + :platform => ["ubuntu-10.04", "ubuntu-12.04"], + :arch => ["x86", "x64"], + :env => [[]], + :ohai => { "languages" => { "lua" => nil }}, + },{ + :platform => ["ubuntu-13.04"], + :arch => ["x64"], + :env => [[]], + :ohai => { "languages" => { "lua" => nil }}, + },{ + :platform => ["ubuntu-10.04", "ubuntu-12.04" ], + :arch => ["x86", "x64"], + :env => [["lua"]], + :ohai => { "languages" => { "lua" => { "version" => "5.1.4" }}}, + },{ + :platform => ["ubuntu-13.04"], + :arch => ["x64"], + :env => [["lua"]], + :ohai => { "languages" => { "lua" => { "version" => "5.1.5" }}}, + }] -OhaiPluginCommon.new.check_expected ['lua'], expected, ["lua"] + include_context "cross platform data" + it_behaves_like "a plugin", ["lua"], expected, ["lua"] +end diff --git a/spec/unit/plugins/nodejs_spec.rb b/spec/unit/plugins/nodejs_spec.rb index 1d6347d4..469abf94 100644 --- a/spec/unit/plugins/nodejs_spec.rb +++ b/spec/unit/plugins/nodejs_spec.rb @@ -51,32 +51,33 @@ describe Ohai::System, "plugin nodejs" do @plugin.run @plugin.languages.should_not have_key(:nodejs) end -end -############# + ############# -require File.expand_path(File.dirname(__FILE__) + '/../path/ohai_plugin_common.rb') + require File.expand_path(File.dirname(__FILE__) + '/../path/ohai_plugin_common.rb') -expected = [{ - :env => [[]], - :platform => ["centos-6.4", "ubuntu-10.04", "ubuntu-12.04"], - :arch => ["x86", "x64"], - :ohai => { "languages" => { "nodejs" => nil }}, - },{ - :env => [[]], - :platform => ["ubuntu-13.04"], - :arch => ["x64"], - :ohai => { "languages" => { "nodejs" => nil }}, - },{ - :env => [["nodejs"]], - :platform => ["centos-6.4", "ubuntu-10.04", "ubuntu-12.04"], - :arch => ["x86", "x64"], - :ohai => { "languages" => { "nodejs" => { "version" => "0.10.2" }}}, - },{ - :env => [["nodejs"]], - :platform => ["ubuntu-13.04"], - :arch => ["x64"], - :ohai => { "languages" => { "nodejs" => { "version" => "0.10.2" }}}, - }] + expected = [{ + :env => [[]], + :platform => ["centos-6.4", "ubuntu-10.04", "ubuntu-12.04"], + :arch => ["x86", "x64"], + :ohai => { "languages" => { "nodejs" => nil }}, + },{ + :env => [[]], + :platform => ["ubuntu-13.04"], + :arch => ["x64"], + :ohai => { "languages" => { "nodejs" => nil }}, + },{ + :env => [["nodejs"]], + :platform => ["centos-6.4", "ubuntu-10.04", "ubuntu-12.04"], + :arch => ["x86", "x64"], + :ohai => { "languages" => { "nodejs" => { "version" => "0.10.2" }}}, + },{ + :env => [["nodejs"]], + :platform => ["ubuntu-13.04"], + :arch => ["x64"], + :ohai => { "languages" => { "nodejs" => { "version" => "0.10.2" }}}, + }] -OhaiPluginCommon.new.check_expected ["nodejs"], expected, ["node"] + include_context "cross platform data" + it_behaves_like "a plugin", ["nodejs"], expected, ["node"] +end diff --git a/spec/unit/plugins/perl_spec.rb b/spec/unit/plugins/perl_spec.rb index c2133d8a..c515b5d2 100644 --- a/spec/unit/plugins/perl_spec.rb +++ b/spec/unit/plugins/perl_spec.rb @@ -34,10 +34,10 @@ OUT @stdin = StringIO.new @status = 0 @plugin.stub(:run_command).with({:no_status_check=>true, :command=>"perl -V:version -V:archname"}).and_return([ - @status, - @stdout, - @stderr - ]) + @status, + @stdout, + @stderr + ]) end it "should run perl -V:version -V:archname" do @@ -63,70 +63,71 @@ OUT it "should set languages[:perl] if perl command succeeds" do @status = 0 @plugin.stub(:run_command).with({:no_status_check=>true, :command=>"perl -V:version -V:archname"}).and_return([ - @status, - @stdout, - @stderr - ]) + @status, + @stdout, + @stderr + ]) @plugin.run @plugin.languages.should have_key(:perl) end it "should not set languages[:perl] if perl command fails" do - @status = 1 + @status = 1 @plugin.stub(:run_command).with({:no_status_check=>true, :command=>"perl -V:version -V:archname"}).and_return([ - @status, - @stdout, - @stderr - ]) - @plugin.run - @plugin.languages.should_not have_key(:perl) + @status, + @stdout, + @stderr + ]) + @plugin.run + @plugin.languages.should_not have_key(:perl) end -end -######### + ######### -require File.expand_path(File.join(File.dirname(__FILE__), '..', 'path', 'ohai_plugin_common.rb')) + require File.expand_path(File.join(File.dirname(__FILE__), '..', 'path', 'ohai_plugin_common.rb')) -expected = [{ - :env => [[], ["perl"]], - :platform => ["centos-5.9"], - :arch => ["x86"], - :ohai => { "languages" => { "perl" => { "version" => "5.8.8", "archname" => "i386-linux-thread-multi" }}}, - },{ - :env => [[], ["perl"]], - :platform => ["centos-5.9"], - :arch => ["x64"], - :ohai => { "languages" => { "perl" => { "version" => "5.8.8", "archname" => "x86_64-linux-thread-multi" }}}, - },{ - :env => [[], ["perl"]], - :platform => ["centos-6.4"], - :arch => ["x86"], - :ohai => { "languages" => { "perl" => { "version" => "5.10.1", "archname" => "i386-linux-thread-multi" }}}, - },{ - :env => [[], ["perl"]], - :platform => ["centos-6.4"], - :arch => ["x64"], - :ohai => { "languages" => { "perl" => { "version" => "5.10.1", "archname" => "x86_64-linux-thread-multi" }}}, - },{ - :env => [[], ["perl"]], - :platform => ["ubuntu-10.04"], - :arch => ["x86"], - :ohai => { "languages" => { "perl" => { "version" => "5.10.1", "archname" => "i486-linux-gnu-thread-multi" }}}, - },{ - :env => [[], ["perl"]], - :platform => ["ubuntu-10.04"], - :arch => ["x64"], - :ohai => { "languages" => { "perl" => { "version" => "5.10.1", "archname" => "x86_64-linux-gnu-thread-multi" }}}, - },{ - :env => [[], ["perl"]], - :platform => ["ubuntu-12.04"], - :arch => ["x86"], - :ohai => { "languages" => { "perl" => { "version" => "5.14.2", "archname" => "i686-linux-gnu-thread-multi-64int" }}}, - },{ - :env => [[], ["perl"]], - :platform => ["ubuntu-12.04", "ubuntu-13.04"], - :arch => ["x64"], - :ohai => { "languages" => { "perl" => { "version" => "5.14.2", "archname" => "x86_64-linux-gnu-thread-multi" }}}, - }] + expected = [{ + :env => [[], ["perl"]], + :platform => ["centos-5.9"], + :arch => ["x86"], + :ohai => { "languages" => { "perl" => { "version" => "5.8.8", "archname" => "i386-linux-thread-multi" }}}, + },{ + :env => [[], ["perl"]], + :platform => ["centos-5.9"], + :arch => ["x64"], + :ohai => { "languages" => { "perl" => { "version" => "5.8.8", "archname" => "x86_64-linux-thread-multi" }}}, + },{ + :env => [[], ["perl"]], + :platform => ["centos-6.4"], + :arch => ["x86"], + :ohai => { "languages" => { "perl" => { "version" => "5.10.1", "archname" => "i386-linux-thread-multi" }}}, + },{ + :env => [[], ["perl"]], + :platform => ["centos-6.4"], + :arch => ["x64"], + :ohai => { "languages" => { "perl" => { "version" => "5.10.1", "archname" => "x86_64-linux-thread-multi" }}}, + },{ + :env => [[], ["perl"]], + :platform => ["ubuntu-10.04"], + :arch => ["x86"], + :ohai => { "languages" => { "perl" => { "version" => "5.10.1", "archname" => "i486-linux-gnu-thread-multi" }}}, + },{ + :env => [[], ["perl"]], + :platform => ["ubuntu-10.04"], + :arch => ["x64"], + :ohai => { "languages" => { "perl" => { "version" => "5.10.1", "archname" => "x86_64-linux-gnu-thread-multi" }}}, + },{ + :env => [[], ["perl"]], + :platform => ["ubuntu-12.04"], + :arch => ["x86"], + :ohai => { "languages" => { "perl" => { "version" => "5.14.2", "archname" => "i686-linux-gnu-thread-multi-64int" }}}, + },{ + :env => [[], ["perl"]], + :platform => ["ubuntu-12.04", "ubuntu-13.04"], + :arch => ["x64"], + :ohai => { "languages" => { "perl" => { "version" => "5.14.2", "archname" => "x86_64-linux-gnu-thread-multi" }}}, + }] -OhaiPluginCommon.new.check_expected ["perl"], expected, ["perl"] + include_context "cross platform data" + it_behaves_like "a plugin", ["perl"], expected, ["perl"] +end diff --git a/spec/unit/plugins/php_spec.rb b/spec/unit/plugins/php_spec.rb index 14057919..4649a29a 100644 --- a/spec/unit/plugins/php_spec.rb +++ b/spec/unit/plugins/php_spec.rb @@ -53,40 +53,41 @@ describe Ohai::System, "plugin php" do @plugin.run @plugin.languages.should_not have_key(:php) end -end -######### + ######### -expected = [{ - :env => [[]], - :platform => ["centos-5.9", "centos-6.4", "ubuntu-10.04", "ubuntu-12.04"], - :arch => ["x86", "x64"], - :ohai => { "languages" => { "php" => nil }}, - },{ - :env => [[]], - :platform => ["ubuntu-13.04"], - :arch => ["x64"], - :ohai => { "languages" => { "php" => nil }}, - },{ - :env => [["php"]], - :platform => ["centos-5.9", "centos-6.4"], - :arch => ["x86", "x64"], - :ohai => { "languages" => { "php" => { "version" => "5.3.3" }}}, - },{ - :env => [["php"]], - :platform => ["ubuntu-10.04"], - :arch => ["x86", "x64"], - :ohai => { "languages" => { "php" => { "version" => "5.3.2-1ubuntu4.20" }}}, - },{ - :env => [["php"]], - :platform => ["ubuntu-12.04"], - :arch => ["x86", "x64"], - :ohai => { "languages" => { "php" => { "version" => "5.3.10-1ubuntu3.7" }}}, - },{ - :env => [["php"]], - :platform => ["ubuntu-13.04"], - :arch => ["x64"], - :ohai => { "languages" => { "php" => { "version" => "5.4.9-4ubuntu2.2" }}}, - }] + expected = [{ + :env => [[]], + :platform => ["centos-5.9", "centos-6.4", "ubuntu-10.04", "ubuntu-12.04"], + :arch => ["x86", "x64"], + :ohai => { "languages" => { "php" => nil }}, + },{ + :env => [[]], + :platform => ["ubuntu-13.04"], + :arch => ["x64"], + :ohai => { "languages" => { "php" => nil }}, + },{ + :env => [["php"]], + :platform => ["centos-5.9", "centos-6.4"], + :arch => ["x86", "x64"], + :ohai => { "languages" => { "php" => { "version" => "5.3.3" }}}, + },{ + :env => [["php"]], + :platform => ["ubuntu-10.04"], + :arch => ["x86", "x64"], + :ohai => { "languages" => { "php" => { "version" => "5.3.2-1ubuntu4.20" }}}, + },{ + :env => [["php"]], + :platform => ["ubuntu-12.04"], + :arch => ["x86", "x64"], + :ohai => { "languages" => { "php" => { "version" => "5.3.10-1ubuntu3.7" }}}, + },{ + :env => [["php"]], + :platform => ["ubuntu-13.04"], + :arch => ["x64"], + :ohai => { "languages" => { "php" => { "version" => "5.4.9-4ubuntu2.2" }}}, + }] -OhaiPluginCommon.new.check_expected ["php"], expected, ["php"] + include_context "cross platform data" + it_behaves_like "a plugin", ["php"], expected, ["php"] +end diff --git a/spec/unit/plugins/python_spec.rb b/spec/unit/plugins/python_spec.rb index 16b95c4a..109b8edd 100644 --- a/spec/unit/plugins/python_spec.rb +++ b/spec/unit/plugins/python_spec.rb @@ -51,37 +51,38 @@ describe Ohai::System, "plugin python" do @plugin.run @plugin.languages.should_not have_key(:python) end -end -########## + ########## -require File.expand_path(File.dirname(__FILE__) + '/../path/ohai_plugin_common.rb') + require File.expand_path(File.dirname(__FILE__) + '/../path/ohai_plugin_common.rb') -expected = [{ - :env => [[], ["python"]], - :platform => ["centos-5.9"], - :arch => ["x86", "x64"], - :ohai => { "languages" => { "python" => { "version" => "2.4.3" }}}, - },{ - :env => [[], ["python"]], - :platform => ["centos-6.4"], - :arch => ["x86", "x64"], - :ohai => { "languages" => { "python" => { "version" => "2.6.6"}}}, - },{ - :env => [[], ["python"]], - :platform => ["ubuntu-10.04"], - :arch => ["x86", "x64"], - :ohai => { "languages" => { "python" => { "version" => "2.6.5"}}}, - },{ - :env => [[], ["python"]], - :platform => ["ubuntu-12.04"], - :arch => ["x86", "x64"], - :ohai => { "languages" => { "python" => { "version" => "2.7.3"}}}, - },{ - :env => [[], ["python"]], - :platform => ["ubuntu-13.04"], - :arch => ["x64"], - :ohai => { "languages" => { "python" => { "version" => "2.7.4"}}}, - }] + expected = [{ + :env => [[], ["python"]], + :platform => ["centos-5.9"], + :arch => ["x86", "x64"], + :ohai => { "languages" => { "python" => { "version" => "2.4.3" }}}, + },{ + :env => [[], ["python"]], + :platform => ["centos-6.4"], + :arch => ["x86", "x64"], + :ohai => { "languages" => { "python" => { "version" => "2.6.6"}}}, + },{ + :env => [[], ["python"]], + :platform => ["ubuntu-10.04"], + :arch => ["x86", "x64"], + :ohai => { "languages" => { "python" => { "version" => "2.6.5"}}}, + },{ + :env => [[], ["python"]], + :platform => ["ubuntu-12.04"], + :arch => ["x86", "x64"], + :ohai => { "languages" => { "python" => { "version" => "2.7.3"}}}, + },{ + :env => [[], ["python"]], + :platform => ["ubuntu-13.04"], + :arch => ["x64"], + :ohai => { "languages" => { "python" => { "version" => "2.7.4"}}}, + }] -OhaiPluginCommon.new.check_expected ["python"], expected, ["python"] + include_context "cross platform data" + it_behaves_like "a plugin", ["python"], expected, ["python"] +end |