Sha256: f3bc206179b1990b4ef2b5a155c6d7f2eff83c3e7c2370067f88ecfb59989cf7

Contents?: true

Size: 1.9 KB

Versions: 9

Compression:

Stored size: 1.9 KB

Contents

# Allow test to be run in-place without requiring a gem install
$LOAD_PATH.unshift File.dirname(__FILE__) + '/../lib'

require 'rubygems'
require 'test/unit'
require 'shoulda'
require 'mocha/setup'
require 'semantic_logger'
require 'socket'
require 'resilient_socket'
require 'syslog_protocol'

# Unit Test for SemanticLogger::Appender::Syslog
#
class AppenderSyslogTest < Test::Unit::TestCase
  context SemanticLogger::Appender::Syslog do

    should 'handle local syslog' do
      ::Syslog.expects(:open).once
      ::Syslog.expects(:log).once
      syslog_appender = SemanticLogger::Appender::Syslog.new
      syslog_appender.debug 'AppenderSyslogTest log message'
    end

    should 'handle remote syslog over TCP' do
      ::ResilientSocket::TCPClient.any_instance.stubs('closed?').returns(false)
      ::ResilientSocket::TCPClient.any_instance.stubs('connect')
      ::ResilientSocket::TCPClient.any_instance.expects(:write).with{ |message| message =~ /<70>(.*?)SemanticLogger::Appender::Syslog -- AppenderSyslogTest log message\r\n/ }
      syslog_appender = SemanticLogger::Appender::Syslog.new(:server => 'tcp://localhost:88888')
      syslog_appender.debug 'AppenderSyslogTest log message'
    end

    should 'handle remote syslog over UDP' do
      ::UDPSocket.any_instance.expects(:send).with{ |*params| params[0] =~ /<70>(.*?)SemanticLogger::Appender::Syslog -- AppenderSyslogTest log message/ }
      syslog_appender = SemanticLogger::Appender::Syslog.new(:server => 'udp://localhost:88888')
      syslog_appender.debug 'AppenderSyslogTest log message'
    end

    # Should be able to log each level.
    SemanticLogger::LEVELS.each do |level|
      should "log #{level} information" do
        ::Syslog.expects(:open).once
        ::Syslog.expects(:log).once
        syslog_appender = SemanticLogger::Appender::Syslog.new
        syslog_appender.send(level, 'AppenderSyslogTest #{level.to_s} message')
      end
    end

  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
semantic_logger-2.9.1 test/appender_syslog_test.rb
semantic_logger-2.9.0 test/appender_syslog_test.rb
semantic_logger-2.8.0 test/appender_syslog_test.rb
semantic_logger-2.7.0 test/appender_syslog_test.rb
semantic_logger-2.6.1 test/appender_syslog_test.rb
semantic_logger-2.6.0 test/appender_syslog_test.rb
semantic_logger-2.5.0 test/appender_syslog_test.rb
semantic_logger-2.4.1 test/appender_syslog_test.rb
semantic_logger-2.4.0 test/appender_syslog_test.rb