summaryrefslogtreecommitdiff
path: root/spec/mixlib/authentication
diff options
context:
space:
mode:
authorRyan Cragun <me@ryan.ec>2017-04-18 16:46:16 -0700
committerRyan Cragun <me@ryan.ec>2017-04-19 13:26:37 -0700
commit88ff22da3888462e23be414de46ec1a7426e69b8 (patch)
tree0b853d7616ee871deae12fc4d7db9cf967012a01 /spec/mixlib/authentication
parent0c5c683a23b7d4b6fd2cbb61a2010af2e513aacf (diff)
downloadmixlib-authentication-ryan/cloud-319.tar.gz
[CLOUD-319] Make mixlib-log an optional dependencyryan/cloud-319
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/mixlib/authentication')
-rw-r--r--spec/mixlib/authentication/mixlib_authentication_spec.rb3
-rw-r--r--spec/mixlib/authentication/mixlib_log_missing_spec.rb61
2 files changed, 62 insertions, 2 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..d3a6b4c
--- /dev/null
+++ b/spec/mixlib/authentication/mixlib_log_missing_spec.rb
@@ -0,0 +1,61 @@
+describe "Mixlib::Authentication::Log" do
+ let(:stdout) { StringIO.new }
+
+ 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") }
+
+ @old_std_out = $stdout
+ $stdout = stdout
+
+ load "mixlib/authentication.rb"
+ end
+
+ after do
+ $stdout = @old_std_out
+ $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