diff options
Diffstat (limited to 'spec/unit/util/logging.rb')
-rwxr-xr-x | spec/unit/util/logging.rb | 45 |
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 |