From 6ebc8161a43ded42cef62b54676ce2f2e09c9fc1 Mon Sep 17 00:00:00 2001 From: Claire McQuin Date: Wed, 21 Aug 2013 12:42:30 -0700 Subject: add debug message for already loaded plugins --- lib/ohai/system.rb | 7 ++++++- spec/unit/system_spec.rb | 44 +++++++++++++++++++++++++++++++++++++++----- 2 files changed, 45 insertions(+), 6 deletions(-) diff --git a/lib/ohai/system.rb b/lib/ohai/system.rb index a1c8a15d..7245cfda 100644 --- a/lib/ohai/system.rb +++ b/lib/ohai/system.rb @@ -59,7 +59,12 @@ module Ohai md = file_regex.match(file) if md plugin_path = md[0] - loader.load_plugin(plugin_path) unless @v6_dependency_solver.has_key?(plugin_path) + + unless @v6_dependency_solver.has_key?(plugin_path) + loader.load_plugin(plugin_path) + else + Ohai::Log.debug("Already loaded plugin at #{plugin_path}") + end end end end diff --git a/spec/unit/system_spec.rb b/spec/unit/system_spec.rb index c4b2827a..e272f666 100644 --- a/spec/unit/system_spec.rb +++ b/spec/unit/system_spec.rb @@ -17,6 +17,7 @@ # require File.expand_path(File.dirname(__FILE__) + '/../spec_helper.rb') +tmp = ENV['TMPDIR'] || ENV['TMP'] || ENV['TEMP'] || '/tmp' describe Ohai::System, "initialize" do it "should return an Ohai::System object" do @@ -33,17 +34,50 @@ describe Ohai::System, "initialize" do end describe Ohai::System, "load_plugins" do + before(:all) do + begin + Dir.mkdir("#{tmp}/plugins") + rescue Errno::EEXIST + # ignore + end + + str = "Ohai.plugin do\nend\n" + file = File.open("#{tmp}/plugins/plgn.rb", "w+") + file.write(str) + file.close + + @plugin_path = Ohai::Config[:plugin_path] + Dir.should_receive(:[]).with("#{tmp}/plugins/*") + Dir.should_receive(:[]).with("#{tmp}/plugins/#{Ohai::OS.collect_os}/**/*").and_return([]) + end + before(:each) do @ohai = Ohai::System.new @ohai.stub(:from_file).and_return(true) end + after(:all) do + Ohai::Config[:plugin_path] = @plugin_path + + File.delete("#{tmp}/plugins/plgn.rb") + begin + Dir.delete("#{tmp}/plugins") + rescue + # ignore + end + end + it "should load plugins when plugin_path has a trailing slash" do - Ohai::Config[:plugin_path] = ["/tmp/plugins/"] - File.stub(:open).and_return(false) - File.stub(:expand_path).with("/tmp/plugins/").and_return("/tmp/plugins") # windows - Dir.should_receive(:[]).with("/tmp/plugins/*").and_return(["/tmp/plugins/darius.rb"]) - Dir.should_receive(:[]).with("/tmp/plugins/#{Ohai::OS.collect_os}/**/*").and_return([]) + Ohai::Config[:plugin_path] = ["#{tmp}/plugins/"] + File.stub(:expand_path).with("#{tmp}/plugins/").and_return("#{tmp}/plugins") # windows + @ohai.load_plugins + end + + it "should log debug message for already loaded plugin" do + Ohai::Config[:plugin_path] = ["#{tmp}/plugins", "#{tmp}/plugins"] + File.stub(:expand_path).with("#{tmp}/plugins").and_return("#{tmp}/plugins") # windows + + Ohai::Log.should_receive(:debug).with(/Already loaded plugin at/).once @ohai.load_plugins end end -- cgit v1.2.1