summaryrefslogtreecommitdiffstats
path: root/spec/unit/util/logging.rb
diff options
context:
space:
mode:
authorLuke Kanies <luke@madstop.com>2009-11-07 15:48:57 -0600
committertest branch <puppet-dev@googlegroups.com>2010-02-17 06:50:53 -0800
commit2292b768c93a1ccba91cfe92d60c65ed936dd45c (patch)
tree0759e4ff470941fc6bb5c9f6b5391b5f430c1291 /spec/unit/util/logging.rb
parentd93d80a0afdbd53d87dc4a7498609117091e864b (diff)
downloadpuppet-2292b768c93a1ccba91cfe92d60c65ed936dd45c.tar.gz
puppet-2292b768c93a1ccba91cfe92d60c65ed936dd45c.tar.xz
puppet-2292b768c93a1ccba91cfe92d60c65ed936dd45c.zip
Refactoring the RAL interface to logging
Previously, the Log class knew a lot about RAL objects, but now the Logging module is the only one that does. This greatly simplifies the Log class, which is good, and means that whatever complexity does need to exist is directly exposed in the Logging middleware module. Signed-off-by: Luke Kanies <luke@madstop.com>
Diffstat (limited to 'spec/unit/util/logging.rb')
-rwxr-xr-xspec/unit/util/logging.rb45
1 files changed, 43 insertions, 2 deletions
diff --git a/spec/unit/util/logging.rb b/spec/unit/util/logging.rb
index 39edbb47e..d6c38fd4c 100755
--- a/spec/unit/util/logging.rb
+++ b/spec/unit/util/logging.rb
@@ -19,6 +19,13 @@ describe Puppet::Util::Logging do
end
end
+ it "should have a method for sending a log with a specified log level" do
+ @logger.expects(:to_s).returns "I'm a string!"
+ Puppet::Util::Log.expects(:create).with { |args| args[:source] == "I'm a string!" and args[:level] == "loglevel" and args[:message] == "mymessage" }
+
+ @logger.send_log "loglevel", "mymessage"
+ end
+
describe "when sending a log" do
it "should use the Log's 'create' entrance method" do
Puppet::Util::Log.expects(:create)
@@ -26,12 +33,35 @@ describe Puppet::Util::Logging do
@logger.notice "foo"
end
- it "should send itself as the log source" do
- Puppet::Util::Log.expects(:create).with { |args| args[:source].equal?(@logger) }
+ it "should send itself converted to a string as the log source" do
+ @logger.expects(:to_s).returns "I'm a string!"
+ Puppet::Util::Log.expects(:create).with { |args| args[:source] == "I'm a string!" }
@logger.notice "foo"
end
+ it "should use the path of any provided resource type" do
+ resource = Puppet::Type.type(:mount).new :name => "foo"
+
+ resource.expects(:path).returns "/path/to/mount".to_sym
+
+ Puppet::Util::Log.expects(:create).with { |args| args[:source] == "/path/to/mount" }
+
+ resource.notice "foo"
+ end
+
+ it "should use the path of any provided resource parameter" do
+ resource = Puppet::Type.type(:mount).new :name => "foo"
+
+ param = resource.parameter(:name)
+
+ param.expects(:path).returns "/path/to/param".to_sym
+
+ Puppet::Util::Log.expects(:create).with { |args| args[:source] == "/path/to/param" }
+
+ param.notice "foo"
+ end
+
it "should send the provided argument as the log message" do
Puppet::Util::Log.expects(:create).with { |args| args[:message] == "foo" }
@@ -43,5 +73,16 @@ describe Puppet::Util::Logging do
@logger.notice ["foo", "bar", "baz"]
end
+
+ [:file, :line, :version, :tags].each do |attr|
+ it "should include #{attr} if available" do
+ @logger.metaclass.send(:attr_accessor, attr)
+
+ @logger.send(attr.to_s + "=", "myval")
+
+ Puppet::Util::Log.expects(:create).with { |args| args[attr] == "myval" }
+ @logger.notice "foo"
+ end
+ end
end
end