summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTheodore Nordsieck <theo@opscode.com>2013-08-20 18:27:49 -0700
committerTheodore Nordsieck <theo@opscode.com>2013-08-22 11:06:28 -0700
commitad806de0565bdcd7625c77bb0a2ce25193ea2617 (patch)
treee4ca11631eed44c7fcd455d4e08b3d205e162584
parent312c7b7099a5f52dda9ffb2b63362481a0831c19 (diff)
downloadohai-ad806de0565bdcd7625c77bb0a2ce25193ea2617.tar.gz
wrapped individual ohai data leaves in it blocks instead of the entire test
-rw-r--r--spec/unit/path/ohai_plugin_common.rb94
1 files changed, 51 insertions, 43 deletions
diff --git a/spec/unit/path/ohai_plugin_common.rb b/spec/unit/path/ohai_plugin_common.rb
index 85fccf6b..5e26cf39 100644
--- a/spec/unit/path/ohai_plugin_common.rb
+++ b/spec/unit/path/ohai_plugin_common.rb
@@ -56,16 +56,6 @@ module OhaiPluginCommon
get_path '/../../../lib/ohai/plugins'
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)
- if source.is_a?( Hash ) && test.is_a?( Hash )
- test.all? { |k,v| subsumes?( source[k], v )}
- else
- source == test
- end
- end
-
# read in the data file for fake executables
def read_output( cmd, path = "#{data_path}" )
@@ -156,49 +146,67 @@ eof
Mixlib::ShellOut.new("chmod 755 #{cmd_path}").run_command
end
- module_function( :fake_command, :data_path, :get_path, :subsumes?, :read_output,
+ module_function( :fake_command, :data_path, :get_path, :read_output,
: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.
+def subsumes?(source, test, path = [])
+ if source.is_a?( Hash ) && test.is_a?( Hash )
+ test.all? { |k,v| subsumes?( source[k], v, path << k )}
+ else
+ it "should set " + path.map { |s| "[#{s}]" }.join + " to #{source || 'nil'}" do
+ source.should eq( test )
+ end
+ end
+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|
- 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
+ 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
+
+ subsumes?( @ohai.data, e[:ohai] )
end
end
-
- 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
-
- OhaiPluginCommon.subsumes?( @ohai.data, e[:ohai] ).should be_true
end
end
end