diff options
| author | Luke Kanies <luke@madstop.com> | 2005-06-28 04:15:48 +0000 |
|---|---|---|
| committer | Luke Kanies <luke@madstop.com> | 2005-06-28 04:15:48 +0000 |
| commit | b6b1f5a8f08859d6c3975beb3ecbcd39ff5f250e (patch) | |
| tree | 5a3998d34392cf94472c23cad8df9b0b5e1a7351 /test | |
| parent | e3c32834c4cc5f7e378d2929b99253982ca264d8 (diff) | |
| download | puppet-b6b1f5a8f08859d6c3975beb3ecbcd39ff5f250e.tar.gz puppet-b6b1f5a8f08859d6c3975beb3ecbcd39ff5f250e.tar.xz puppet-b6b1f5a8f08859d6c3975beb3ecbcd39ff5f250e.zip | |
logging now exactly supports the list of levels that syslog supports, and multiple destinations (syslog, files, and console) are now supported
git-svn-id: https://reductivelabs.com/svn/puppet/library/trunk@311 980ebf18-57e1-0310-9a29-db15c13687c0
Diffstat (limited to 'test')
| -rw-r--r-- | test/other/tc_log.rb | 101 | ||||
| -rw-r--r-- | test/types/tc_basic.rb | 2 |
2 files changed, 102 insertions, 1 deletions
diff --git a/test/other/tc_log.rb b/test/other/tc_log.rb new file mode 100644 index 000000000..77d33a406 --- /dev/null +++ b/test/other/tc_log.rb @@ -0,0 +1,101 @@ +if __FILE__ == $0 + $:.unshift '..' + $:.unshift '../../lib' + $puppetbase = "../../../../language/trunk/" +end + +require 'puppet/log' +require 'puppet' +require 'test/unit' + +# $Id$ + +class TestLog < Test::Unit::TestCase + @@logfile = "/tmp/puppettest.log" + + def teardown + system("rm -f %s" % @@logfile) + Puppet::Log.destination(:console) + end + + def getlevels + levels = nil + assert_nothing_raised() { + levels = Puppet::Log.levels + } + return levels + end + + def mkmsgs(levels) + levels.collect { |level| + assert_nothing_raised() { + Puppet::Log.new( + :level => level, + :source => "Test", + :message => "Unit test for %s" % level + ) + } + } + end + + def test_logfile + Puppet[:debug] = true if __FILE__ == $0 + fact = nil + levels = nil + levels = getlevels + assert_nothing_raised() { + Puppet::Log.destination(@@logfile) + } + msgs = mkmsgs(levels) + assert(msgs.length == levels.length) + Puppet::Log.close + count = 0 + assert_nothing_raised() { + File.open(@@logfile) { |of| + count = of.readlines.length + } + } + assert(count == levels.length) + end + + def test_syslog + levels = nil + assert_nothing_raised() { + levels = getlevels.reject { |level| + level == :emerg || level == :crit + } + } + assert_nothing_raised() { + Puppet::Log.destination("syslog") + } + # there's really no way to verify that we got syslog messages... + msgs = mkmsgs(levels) + assert(msgs.length == levels.length) + end + + def test_consolelog + Puppet[:debug] = true if __FILE__ == $0 + fact = nil + levels = nil + assert_nothing_raised() { + levels = Puppet::Log.levels + } + assert_nothing_raised() { + Puppet::Log.destination(:console) + } + msgs = mkmsgs(levels) + assert(msgs.length == levels.length) + Puppet::Log.close + end + + def test_levelmethods + assert_nothing_raised() { + Puppet::Log.destination("/dev/null") + } + getlevels.each { |level| + assert_nothing_raised() { + Puppet.send(level,"Testing for %s" % level) + } + } + end +end diff --git a/test/types/tc_basic.rb b/test/types/tc_basic.rb index 0e54cb3b7..0732624e5 100644 --- a/test/types/tc_basic.rb +++ b/test/types/tc_basic.rb @@ -60,7 +60,7 @@ class TestBasic < Test::Unit::TestCase def test_name_calls [@sleeper,@configfile].each { |obj| - Puppet.error "obj is %s" % obj + Puppet.debug "obj is %s" % obj assert_nothing_raised(){ obj.name } |
