Sha256: 63a4734c59bd0a044fa1c5b6e06d4cbc1c9c964bd3614d5689f1654d3f48c3c4

Contents?: true

Size: 1.82 KB

Versions: 5

Compression:

Stored size: 1.82 KB

Contents

require "spec_helper"

describe Timber::LogDevices::HTTP::TriggeredBuffer do
  describe "#write" do
    it "should trigger a buffer overflow for large messages" do
      buffer = described_class.new(:payload_limit_bytes => 10)
      msg = "a" * 11
      expect(buffer).to receive(:handle_overflow).exactly(1).times.with(msg)
      buffer.write(msg)
    end

    it "should trigger a buffer overflow when exceeding the limit" do
      buffer = described_class.new(:limit_bytes => 10)
      msg = "a" * 11
      expect(buffer).to receive(:handle_overflow).exactly(1).times.with(msg)
      buffer.write(msg)
    end

    it "should start a new buffer when empty and append when not" do
      buffer = described_class.new
      result = buffer.write("test")
      expect(result).to be_nil
      expect(buffer.send(:writable_buffer)).to eq("test")
      result = buffer.write("again")
      expect(result).to be_nil
      expect(buffer.send(:writable_buffer)).to eq("testagain")
    end

    it "should return the old buffer when it has exceeded it's limit" do
      buffer = described_class.new(:payload_limit_bytes => 10)
      msg = "a" * 6
      result = buffer.write(msg)
      expect(result).to be_nil
      result = buffer.write(msg)
      expect(result).to eq(msg)
      expect(result).to be_frozen
    end

    it "should write a new buffer when the latest is frozen" do
      buffer = described_class.new
      buffer.write("test")
      result = buffer.reserve
      expect(result).to eq("test")
      buffer.write("again")
      expect(buffer.send(:writable_buffer)).to eq("again")
    end
  end

  describe "#reserve" do
    it "should reserve the latest buffer and freeze it" do
      buffer = described_class.new
      buffer.write("test")
      result = buffer.reserve
      expect(result).to eq("test")
      expect(result).to be_frozen
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
timber-1.0.8 spec/timber/log_devices/http/triggered_buffer_spec.rb
timber-1.0.7 spec/timber/log_devices/http/triggered_buffer_spec.rb
timber-1.0.6 spec/timber/log_devices/http/triggered_buffer_spec.rb
timber-1.0.5 spec/timber/log_devices/http/triggered_buffer_spec.rb
timber-1.0.4 spec/timber/log_devices/http/triggered_buffer_spec.rb