summaryrefslogtreecommitdiffstats
path: root/spec
diff options
context:
space:
mode:
Diffstat (limited to 'spec')
-rwxr-xr-xspec/unit/parameter.rb9
-rwxr-xr-xspec/unit/util/logging.rb45
2 files changed, 51 insertions, 3 deletions
diff --git a/spec/unit/parameter.rb b/spec/unit/parameter.rb
index 817b5c6d6..f4473248a 100755
--- a/spec/unit/parameter.rb
+++ b/spec/unit/parameter.rb
@@ -157,5 +157,12 @@ describe Puppet::Parameter do
@parameter.munge("bar").should == "bar"
end
end
-end
+ describe "when logging" do
+ it "should use its resource's log level and the provided message" do
+ @resource.expects(:[]).with(:loglevel).returns :notice
+ @parameter.expects(:send_log).with(:notice, "mymessage")
+ @parameter.log "mymessage"
+ end
+ end
+end
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