summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClaire McQuin <claire@opscode.com>2013-08-21 12:42:30 -0700
committerClaire McQuin <claire@opscode.com>2013-08-21 12:42:30 -0700
commit6ebc8161a43ded42cef62b54676ce2f2e09c9fc1 (patch)
tree9681b322e7b2a24e393423e9e1fc2345907b00b9
parent14cb8ed121fdd434bb0fb45caead07a75dce65a2 (diff)
downloadohai-6ebc8161a43ded42cef62b54676ce2f2e09c9fc1.tar.gz
add debug message for already loaded plugins
-rw-r--r--lib/ohai/system.rb7
-rw-r--r--spec/unit/system_spec.rb44
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