This repository has been archived by the owner on Dec 8, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
047bc01
commit 0ad19e2
Showing
2 changed files
with
59 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters