summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTheodore Nordsieck <theo@opscode.com>2013-08-21 18:35:01 -0700
committerTheodore Nordsieck <theo@opscode.com>2013-08-22 11:09:08 -0700
commit56cf01b384b2e3770f4865e982c2c7accbfa5840 (patch)
treecf0043251987efcea3758aae8d7a6359caa3018e
parent5e550d167817f10765c28bc83163b832a7c420db (diff)
downloadohai-56cf01b384b2e3770f4865e982c2c7accbfa5840.tar.gz
remove old plugin format from ohai_plugin_common.rb
-rw-r--r--spec/unit/path/ohai_plugin_common.rb75
1 files changed, 6 insertions, 69 deletions
diff --git a/spec/unit/path/ohai_plugin_common.rb b/spec/unit/path/ohai_plugin_common.rb
index 54cf4325..879738c8 100644
--- a/spec/unit/path/ohai_plugin_common.rb
+++ b/spec/unit/path/ohai_plugin_common.rb
@@ -18,7 +18,6 @@
require 'rubygems'
require 'yajl'
-require 'rspec'
require 'ohai'
require 'yaml'
@@ -150,8 +149,8 @@ eof
:to_fake_exe_format, :data_to_string, :create_exe, :plugin_path )
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.
+# 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, path = [], &block)
if source.is_a?( Hash ) && test.is_a?( Hash )
test.all? { |k,v| subsumes?( source[k], v, path.clone << k, &block )}
@@ -161,7 +160,9 @@ def subsumes?(source, test, path = [], &block)
end
end
+# test that a plugin conforms populates ohai with the correct data
def test_plugin(plugin_names, cmd_list)
+ require 'rspec'
l = lambda do | platforms, archs, envs, ohai |
platforms.each do |platform|
describe "when the platform is #{platform}" do
@@ -192,8 +193,8 @@ def test_plugin(plugin_names, cmd_list)
begin
plugin_names.each do | plugin_name |
- Ohai::Loader.new( @ohai ).load_plugin( File.join( OhaiPluginCommon.plugin_path, plugin_name + ".rb" ), plugin_name )
- @plugin = @ohai.plugins[plugin_name.to_sym][:plugin].new( @ohai )
+ @loader = Ohai::Loader.new( @ohai )
+ @plugin = @loader.load_plugin( File.join( OhaiPluginCommon.plugin_path, plugin_name + ".rb" ) ).new(@ohai)
@plugin.safe_run
end
ensure
@@ -227,67 +228,3 @@ def test_plugin(plugin_names, cmd_list)
end
yield l
end
-
-# for use in plugins
-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|
- describe "when the platform is #{platform}" do
- e[:arch].each do |arch|
- describe "and the architecture is #{arch}" do
- e[:env].each do |env|
- describe "and the environment is #{env}" do
- path = OhaiPluginCommon.get_path
- cmd_not_found = Set.new
-
- # create fake exe's
- 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
-
- # preserve the old path
- old_path = ENV['PATH']
- ENV['PATH'] = path
-
- @ohai = Ohai::System.new
-
- begin
- plugin_names.each do | plugin_name |
- @loader = Ohai::Loader.new( @ohai )
- @plugin = @loader.load_plugin( File.join( OhaiPluginCommon.plugin_path, plugin_name + ".rb" ) ).new(@ohai)
- @plugin.safe_run
- end
- ensure
- ENV['PATH'] = old_path
- cmd_list.each { |c| [ "", ".bat" ].each { |ext| Mixlib::ShellOut.new("rm #{path}/#{c}#{ext}").run_command if !cmd_not_found.include?( c )}}
- end
-
- enc = Yajl::Encoder
- subsumes?( @ohai.data, e[:ohai] ) do | path, source, test |
- path_txt = path.map { |p| "[#{enc.encode( p )}]" }.join
- if source.nil?
- txt = "should not set #{path_txt}"
- else
- txt = "should set #{path_txt} to #{enc.encode( source )}"
- end
- it txt do
- source.should eq( test )
- end
- end
- end
- end
- end
- end
- end
- end
- end
- end
-end