summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorRyan Cragun <me@ryan.ec>2017-04-18 16:46:16 -0700
committerRyan Cragun <me@ryan.ec>2017-04-20 10:32:12 -0700
commit9d6d393f56d9da97fe53e3bdd92a2c7bf10fc66d (patch)
treecafbe5a63a61008e9e8d42018b81d18be2edbb74 /spec
parent0c5c683a23b7d4b6fd2cbb61a2010af2e513aacf (diff)
downloadmixlib-authentication-9d6d393f56d9da97fe53e3bdd92a2c7bf10fc66d.tar.gz
[CLOUD-319] Make mixlib-log an optional dependency
This change makes mixlib-log an optional dependency. When it's available in the LOAD_PATH it will be used by default, otherwise, all logging will will be forwarded to a null logger that does nothing. This is useful for cases where small utilities can consume mixlib-authentication and not have to pull in additional gems. Signed-off-by: Ryan Cragun <me@ryan.ec>
Diffstat (limited to 'spec')
-rw-r--r--spec/mixlib/authentication/mixlib_authentication_spec.rb3
-rw-r--r--spec/mixlib/authentication/mixlib_log_missing_spec.rb55
-rw-r--r--spec/spec_helper.rb1
3 files changed, 56 insertions, 3 deletions
diff --git a/spec/mixlib/authentication/mixlib_authentication_spec.rb b/spec/mixlib/authentication/mixlib_authentication_spec.rb
index d0e8071..221e803 100644
--- a/spec/mixlib/authentication/mixlib_authentication_spec.rb
+++ b/spec/mixlib/authentication/mixlib_authentication_spec.rb
@@ -63,8 +63,7 @@ class MockFile
end
# Uncomment this to get some more info from the methods we're testing.
-#Mixlib::Authentication::Log.logger = Logger.new(STDERR)
-#Mixlib::Authentication::Log.level :debug
+#Mixlib::Authentication.logger.level = :debug
describe "Mixlib::Authentication::SignedHeaderAuth" do
diff --git a/spec/mixlib/authentication/mixlib_log_missing_spec.rb b/spec/mixlib/authentication/mixlib_log_missing_spec.rb
new file mode 100644
index 0000000..4b12b12
--- /dev/null
+++ b/spec/mixlib/authentication/mixlib_log_missing_spec.rb
@@ -0,0 +1,55 @@
+describe "Mixlib::Authentication::Log" do
+ before do
+ Mixlib::Authentication.send(:remove_const, "DEFAULT_SERVER_API_VERSION")
+ Mixlib::Authentication.send(:remove_const, "Log")
+ end
+
+ context "without mixlib-log" do
+ before do
+ @mixlib_path = $LOAD_PATH.find { |p| p.match("mixlib-log") }
+ $LOAD_PATH.reject! { |p| p.match("mixlib-log") }
+
+ load "mixlib/authentication.rb"
+ end
+
+ after do
+ $LOAD_PATH.unshift(@mixlib_path)
+ end
+
+ it "uses MixlibLogMissing" do
+ expect(Mixlib::Authentication::Log.singleton_class.included_modules)
+ .to include(Mixlib::Authentication::NullLogger)
+ end
+
+ it "default log level is :error" do
+ expect(Mixlib::Authentication::Log.level).to eq(:error)
+ end
+
+ %w{debug info warn error fatal}.each do |level|
+ it "logs at level #{level}" do
+ expect(Mixlib::Authentication::Log).to receive(level).with("foo")
+
+ Mixlib::Authentication.logger.send(level, "foo")
+ end
+ end
+ end
+
+ context "with mixlib-log" do
+ before do
+ load "mixlib/authentication.rb"
+ end
+
+ it "uses Mixlib::Log" do
+ expect(Mixlib::Authentication::Log.singleton_class.included_modules)
+ .to include(Mixlib::Log)
+ end
+
+ %w{debug info warn error fatal}.each do |level|
+ it "forward #{level} to mixlib-log" do
+ expect(Mixlib::Authentication::Log.logger).to receive(level).with("foo")
+
+ Mixlib::Authentication.logger.send(level, "foo")
+ end
+ end
+ end
+end
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
index fe03c12..be55155 100644
--- a/spec/spec_helper.rb
+++ b/spec/spec_helper.rb
@@ -18,6 +18,5 @@
#
$:.unshift File.expand_path(File.join(File.dirname(__FILE__), "..", "lib")) # lib in mixlib-authentication
-$:.unshift File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "mixlib-log", "lib")) # mixlib-log/log
require "rubygems"