Sha256: 346ca6f458b58689e69b4ca676101d973aa642d28696632aef95ccc53ba15295

Contents?: true

Size: 1.37 KB

Versions: 92

Compression:

Stored size: 1.37 KB

Contents

#! /usr/bin/env ruby
require 'spec_helper'
require 'puppet/util/log/rate_limited_logger'

describe Puppet::Util::Log::RateLimitedLogger do

  subject { Puppet::Util::Log::RateLimitedLogger.new(60) }

  before do
    Time.stubs(:now).returns(0)
  end

  it "should be able to log all levels" do
    Puppet::Util::Log.eachlevel do |level|
      subject.should respond_to(level)
    end
  end

  it "should fail if given an invalid time interval" do
    expect { Puppet::Util::Log::RateLimitedLogger.new('foo') }.to raise_error(ArgumentError)
  end

  it "should not log the same message more than once within the given interval" do
    Puppet::Util::Log.expects(:create).once
    subject.info('foo')
    subject.info('foo')
  end

  it "should allow the same message to be logged after the given interval has passed" do
    Puppet::Util::Log.expects(:create).twice
    subject.info('foo')
    Time.stubs(:now).returns(60)
    subject.info('foo')
  end

  it "should rate-limit different message strings separately" do
    Puppet::Util::Log.expects(:create).times(3)
    subject.info('foo')
    subject.info('bar')
    subject.info('baz')
    subject.info('foo')
    subject.info('bar')
    subject.info('baz')
  end

  it "should limit the same message in different log levels independently" do
    Puppet::Util::Log.expects(:create).twice
    subject.info('foo')
    subject.warning('foo')
  end
end

Version data entries

92 entries across 92 versions & 2 rubygems

Version Path
puppet-3.4.0 spec/unit/util/log/rate_limited_logger_spec.rb
puppet-3.4.0.rc2 spec/unit/util/log/rate_limited_logger_spec.rb
puppet-3.4.0.rc1 spec/unit/util/log/rate_limited_logger_spec.rb
puppet-3.3.2 spec/unit/util/log/rate_limited_logger_spec.rb
puppet-3.3.1 spec/unit/util/log/rate_limited_logger_spec.rb
puppet-3.3.1.rc3 spec/unit/util/log/rate_limited_logger_spec.rb
puppet-3.3.1.rc2 spec/unit/util/log/rate_limited_logger_spec.rb
puppet-3.3.1.rc1 spec/unit/util/log/rate_limited_logger_spec.rb
puppet-3.3.0 spec/unit/util/log/rate_limited_logger_spec.rb
puppet-3.3.0.rc3 spec/unit/util/log/rate_limited_logger_spec.rb
puppet-3.3.0.rc2 spec/unit/util/log/rate_limited_logger_spec.rb
puppet-3.2.4 spec/unit/util/log/rate_limited_logger_spec.rb
puppet-3.2.3 spec/unit/util/log/rate_limited_logger_spec.rb
puppet-3.2.3.rc1 spec/unit/util/log/rate_limited_logger_spec.rb
puppet-3.2.2 spec/unit/util/log/rate_limited_logger_spec.rb
puppet-3.2.1 spec/unit/util/log/rate_limited_logger_spec.rb
puppet-3.2.1.rc1 spec/unit/util/log/rate_limited_logger_spec.rb
puppet-3.2.0.rc2 spec/unit/util/log/rate_limited_logger_spec.rb
librarian-puppet-0.9.9 vendor/gems/ruby/1.9.1/gems/puppet-3.1.0/spec/unit/util/log/rate_limited_logger_spec.rb
puppet-3.2.0.rc1 spec/unit/util/log/rate_limited_logger_spec.rb