mirror of
https://github.com/meineerde/rackstash.git
synced 2025-12-19 15:01:12 +00:00
Ensure more consistent code formatting with Rubocop
This commit is contained in:
parent
d157e53129
commit
e7fd3677ca
@ -96,7 +96,7 @@ module Rackstash
|
|||||||
if block_given?
|
if block_given?
|
||||||
copy_with @message.gsub(pattern, &block).freeze
|
copy_with @message.gsub(pattern, &block).freeze
|
||||||
else
|
else
|
||||||
return enum_for(__method__)
|
enum_for(__method__)
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
copy_with @message.gsub(pattern, replacement, &block).freeze
|
copy_with @message.gsub(pattern, replacement, &block).freeze
|
||||||
|
|||||||
@ -27,6 +27,7 @@ describe Rackstash::Adapters::Logger do
|
|||||||
end
|
end
|
||||||
end.new([])
|
end.new([])
|
||||||
}
|
}
|
||||||
|
|
||||||
let(:logger) {
|
let(:logger) {
|
||||||
::Logger.new(bucket).tap do |logger|
|
::Logger.new(bucket).tap do |logger|
|
||||||
logger.formatter = ->(_severity, _time, _progname, msg) { msg }
|
logger.formatter = ->(_severity, _time, _progname, msg) { msg }
|
||||||
@ -35,7 +36,8 @@ describe Rackstash::Adapters::Logger do
|
|||||||
def logger.reopen
|
def logger.reopen
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
}
|
}
|
||||||
|
|
||||||
let(:logger_ducky) {
|
let(:logger_ducky) {
|
||||||
Object.new.tap do |duck|
|
Object.new.tap do |duck|
|
||||||
allow(duck).to receive(:add)
|
allow(duck).to receive(:add)
|
||||||
|
|||||||
@ -161,7 +161,7 @@ describe Rackstash::Buffer do
|
|||||||
end
|
end
|
||||||
|
|
||||||
it 'returns the given value' do
|
it 'returns the given value' do
|
||||||
fields = {key: 'value'}
|
fields = { key: 'value' }
|
||||||
expect(buffer.add_fields(fields)).to equal fields
|
expect(buffer.add_fields(fields)).to equal fields
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -24,12 +24,14 @@ describe Rackstash::Encoders::Helpers::Timestamp do
|
|||||||
describe '#normalize_timestamp' do
|
describe '#normalize_timestamp' do
|
||||||
it 'formats a Time object' do
|
it 'formats a Time object' do
|
||||||
event['@timestamp'] = Time.parse('2016-10-17 13:37:00 +03:00')
|
event['@timestamp'] = Time.parse('2016-10-17 13:37:00 +03:00')
|
||||||
expect(helper.normalize_timestamp(event).fetch('@timestamp')).to eql '2016-10-17T10:37:00.000000Z'
|
expect(helper.normalize_timestamp(event).fetch('@timestamp'))
|
||||||
|
.to eql '2016-10-17T10:37:00.000000Z'
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'formats a DateTime object' do
|
it 'formats a DateTime object' do
|
||||||
event['@timestamp'] = DateTime.parse('2016-10-17 13:37:00 +03:00')
|
event['@timestamp'] = DateTime.parse('2016-10-17 13:37:00 +03:00')
|
||||||
expect(helper.normalize_timestamp(event).fetch('@timestamp')).to eql '2016-10-17T10:37:00.000000Z'
|
expect(helper.normalize_timestamp(event).fetch('@timestamp'))
|
||||||
|
.to eql '2016-10-17T10:37:00.000000Z'
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'ignores an unset value' do
|
it 'ignores an unset value' do
|
||||||
@ -51,10 +53,10 @@ describe Rackstash::Encoders::Helpers::Timestamp do
|
|||||||
event['@timestamp'] = Time.parse('2016-10-17 13:37:00 +03:00')
|
event['@timestamp'] = Time.parse('2016-10-17 13:37:00 +03:00')
|
||||||
event['custom'] = Time.parse('2016-10-17 20:42:00 +07:00')
|
event['custom'] = Time.parse('2016-10-17 20:42:00 +07:00')
|
||||||
|
|
||||||
expect(helper.normalize_timestamp(event, field: 'custom')).to match({
|
expect(helper.normalize_timestamp(event, field: 'custom')).to match(
|
||||||
'@timestamp' => instance_of(Time),
|
'@timestamp' => instance_of(Time),
|
||||||
'custom' => '2016-10-17T13:42:00.000000Z'
|
'custom' => '2016-10-17T13:42:00.000000Z'
|
||||||
})
|
)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -14,7 +14,7 @@ describe Rackstash::Encoders::JSON do
|
|||||||
|
|
||||||
describe '#encode' do
|
describe '#encode' do
|
||||||
it 'formats the passed event hash as a JSON string' do
|
it 'formats the passed event hash as a JSON string' do
|
||||||
event = { 'hello' => 'world', 'message' => ["hello\n", "world"] }
|
event = { 'hello' => 'world', 'message' => ["hello\n", 'world'] }
|
||||||
expect(encoder.encode(event)).to eql '{"hello":"world","message":"hello\nworld"}'
|
expect(encoder.encode(event)).to eql '{"hello":"world","message":"hello\nworld"}'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@ -14,7 +14,7 @@ describe Rackstash::Encoders::Logstash do
|
|||||||
|
|
||||||
describe '#encode' do
|
describe '#encode' do
|
||||||
it 'formats the passed event hash as a JSON string and includes @version' do
|
it 'formats the passed event hash as a JSON string and includes @version' do
|
||||||
event = { 'hello' => 'world', 'message' => ["hello\n", "world"] }
|
event = { 'hello' => 'world', 'message' => ["hello\n", 'world'] }
|
||||||
expect(encoder.encode(event))
|
expect(encoder.encode(event))
|
||||||
.to match(/\A\{"hello":"world","message":"hello\\nworld","@version":"1","@timestamp":"\d{4}-\d\d-\d\dT\d\d:\d\d:\d\d\.\d{6}Z"\}\z/)
|
.to match(/\A\{"hello":"world","message":"hello\\nworld","@version":"1","@timestamp":"\d{4}-\d\d-\d\dT\d\d:\d\d:\d\d\.\d{6}Z"\}\z/)
|
||||||
end
|
end
|
||||||
|
|||||||
@ -268,7 +268,7 @@ describe Rackstash::Fields::AbstractCollection do
|
|||||||
test_self = self
|
test_self = self
|
||||||
|
|
||||||
hash = {
|
hash = {
|
||||||
beep: ->(v) {
|
beep: lambda { |v|
|
||||||
expect(self).to equal test_self
|
expect(self).to equal test_self
|
||||||
{ v.upcase => -> { self } }
|
{ v.upcase => -> { self } }
|
||||||
}
|
}
|
||||||
|
|||||||
@ -19,10 +19,10 @@ describe Rackstash::Filters::ClearColor do
|
|||||||
|
|
||||||
it 'removes color codes from a message array' do
|
it 'removes color codes from a message array' do
|
||||||
event = {
|
event = {
|
||||||
'message' => ["Some \e[31mred\e[0m\nand", "some \e[32mgreen\e[0m text" ]
|
'message' => ["Some \e[31mred\e[0m\nand", "some \e[32mgreen\e[0m text"]
|
||||||
}
|
}
|
||||||
expect(filter.call(event)).to eql 'message' => [
|
expect(filter.call(event)).to eql 'message' => [
|
||||||
"Some red\nand", "some green text"
|
"Some red\nand", 'some green text'
|
||||||
]
|
]
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -30,5 +30,4 @@ describe Rackstash::Filters::ClearColor do
|
|||||||
event = { 'foo' => 'bar' }
|
event = { 'foo' => 'bar' }
|
||||||
expect(filter.call(event)).to eql 'foo' => 'bar'
|
expect(filter.call(event)).to eql 'foo' => 'bar'
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
@ -22,17 +22,17 @@ describe Rackstash::Filters::Replace do
|
|||||||
end
|
end
|
||||||
|
|
||||||
it 'sets evaluated values from callable objects' do
|
it 'sets evaluated values from callable objects' do
|
||||||
filter!('foo' => ->(event) { event['foo'].upcase } )
|
filter!('foo' => ->(event) { event['foo'].upcase })
|
||||||
expect(event).to eql 'foo' => 'FOO VALUE', 'bar' => 'bar value'
|
expect(event).to eql 'foo' => 'FOO VALUE', 'bar' => 'bar value'
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'sets raw values' do
|
it 'sets raw values' do
|
||||||
filter!('bar' => 123 )
|
filter!('bar' => 123)
|
||||||
expect(event).to eql 'foo' => 'foo value', 'bar' => 123
|
expect(event).to eql 'foo' => 'foo value', 'bar' => 123
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'always sets fields' do
|
it 'always sets fields' do
|
||||||
filter!('baz' => 42, 'boing' => ->(event) { 'quark' })
|
filter!('baz' => 42, 'boing' => ->(_event) { 'quark' })
|
||||||
expect(event).to eql(
|
expect(event).to eql(
|
||||||
'foo' => 'foo value',
|
'foo' => 'foo value',
|
||||||
'bar' => 'bar value',
|
'bar' => 'bar value',
|
||||||
@ -42,7 +42,7 @@ describe Rackstash::Filters::Replace do
|
|||||||
end
|
end
|
||||||
|
|
||||||
it 'stringifies keys' do
|
it 'stringifies keys' do
|
||||||
filter!(foo: ->(event) { event['foo'].upcase } )
|
filter!(foo: ->(event) { event['foo'].upcase })
|
||||||
expect(event).to eql 'foo' => 'FOO VALUE', 'bar' => 'bar value'
|
expect(event).to eql 'foo' => 'FOO VALUE', 'bar' => 'bar value'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@ -37,23 +37,23 @@ describe Rackstash::Filters::TruncateMessage do
|
|||||||
describe '#call' do
|
describe '#call' do
|
||||||
context 'with selectors' do
|
context 'with selectors' do
|
||||||
it 'calls all selectors' do
|
it 'calls all selectors' do
|
||||||
selector_1 = ->(message) { true }
|
selector1 = ->(_message) { true }
|
||||||
selector_2 = callable { true }
|
selector2 = callable { true }
|
||||||
args[:selectors] = [selector_1, selector_2]
|
args[:selectors] = [selector1, selector2]
|
||||||
|
|
||||||
# selector_1 is a proc and is thus passed directly as a block to select!
|
# selector1 is a proc and is thus passed directly as a block to select!
|
||||||
expect(selector_2).to receive(:call).exactly(messages.count)
|
expect(selector2).to receive(:call).exactly(messages.count)
|
||||||
|
|
||||||
filter.call(event)
|
filter.call(event)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'stops on goal' do
|
it 'stops on goal' do
|
||||||
selector_1 = callable { false }
|
selector1 = callable { false }
|
||||||
selector_2 = callable { true }
|
selector2 = callable { true }
|
||||||
args[:selectors] = [selector_1, selector_2]
|
args[:selectors] = [selector1, selector2]
|
||||||
|
|
||||||
expect(selector_1).to receive(:call).exactly(3).times.and_call_original
|
expect(selector1).to receive(:call).exactly(3).times.and_call_original
|
||||||
expect(selector_2).not_to receive(:call)
|
expect(selector2).not_to receive(:call)
|
||||||
|
|
||||||
filter.call(event)
|
filter.call(event)
|
||||||
expect(messages).to be_empty
|
expect(messages).to be_empty
|
||||||
|
|||||||
@ -22,17 +22,17 @@ describe Rackstash::Filters::Update do
|
|||||||
end
|
end
|
||||||
|
|
||||||
it 'sets evaluated values from callable objects' do
|
it 'sets evaluated values from callable objects' do
|
||||||
filter!('foo' => ->(event) { event['foo'].upcase } )
|
filter!('foo' => ->(event) { event['foo'].upcase })
|
||||||
expect(event).to eql 'foo' => 'FOO VALUE', 'bar' => 'bar value'
|
expect(event).to eql 'foo' => 'FOO VALUE', 'bar' => 'bar value'
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'sets raw values' do
|
it 'sets raw values' do
|
||||||
filter!('bar' => 123 )
|
filter!('bar' => 123)
|
||||||
expect(event).to eql 'foo' => 'foo value', 'bar' => 123
|
expect(event).to eql 'foo' => 'foo value', 'bar' => 123
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'ignores missing fields' do
|
it 'ignores missing fields' do
|
||||||
spec = {'baz' => 42, 'boing' => ->(event) { 'quark' }}
|
spec = { 'baz' => 42, 'boing' => ->(_event) { 'quark' } }
|
||||||
expect(spec['boing']).not_to receive(:call)
|
expect(spec['boing']).not_to receive(:call)
|
||||||
|
|
||||||
filter!(spec)
|
filter!(spec)
|
||||||
@ -43,7 +43,7 @@ describe Rackstash::Filters::Update do
|
|||||||
end
|
end
|
||||||
|
|
||||||
it 'stringifies keys' do
|
it 'stringifies keys' do
|
||||||
filter!(foo: ->(event) { event['foo'].upcase } )
|
filter!(foo: ->(event) { event['foo'].upcase })
|
||||||
expect(event).to eql 'foo' => 'FOO VALUE', 'bar' => 'bar value'
|
expect(event).to eql 'foo' => 'FOO VALUE', 'bar' => 'bar value'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@ -29,7 +29,6 @@ describe Rackstash::Formatter do
|
|||||||
expect(formatter.call('ERROR', Time.now, 'progname', [1, 'y']))
|
expect(formatter.call('ERROR', Time.now, 'progname', [1, 'y']))
|
||||||
.to eql("[1, \"y\"]\n")
|
.to eql("[1, \"y\"]\n")
|
||||||
.and be_frozen
|
.and be_frozen
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'formats exceptions' do
|
it 'formats exceptions' do
|
||||||
@ -47,7 +46,7 @@ describe Rackstash::Formatter do
|
|||||||
expect(formatter.call('ERROR', Time.now, 'progname', exception))
|
expect(formatter.call('ERROR', Time.now, 'progname', exception))
|
||||||
.to match(checker)
|
.to match(checker)
|
||||||
.and be_frozen
|
.and be_frozen
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'inspects unknown objects' do
|
it 'inspects unknown objects' do
|
||||||
object = Object.new
|
object = Object.new
|
||||||
|
|||||||
@ -91,8 +91,8 @@ describe Rackstash::Message do
|
|||||||
|
|
||||||
describe '#gsub' do
|
describe '#gsub' do
|
||||||
it 'can perform simple replaces' do
|
it 'can perform simple replaces' do
|
||||||
expect(message.gsub(/s/, 'S')).to be_a described_class
|
expect(message.gsub(/ss/, 'SS')).to be_a described_class
|
||||||
expect(message.gsub(/s/, 'S').to_s).to eql 'meSSage'
|
expect(message.gsub(/ss/, 'SS').to_s).to eql 'meSSage'
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'can perform replaces with a block' do
|
it 'can perform replaces with a block' do
|
||||||
@ -108,8 +108,8 @@ describe Rackstash::Message do
|
|||||||
|
|
||||||
describe '#sub' do
|
describe '#sub' do
|
||||||
it 'can perform simple replaces' do
|
it 'can perform simple replaces' do
|
||||||
expect(message.sub(/s/, 'S')).to be_a described_class
|
expect(message.sub(/ss/, 'SS')).to be_a described_class
|
||||||
expect(message.sub(/s/, 'S').to_s).to eql 'meSsage'
|
expect(message.sub(/ss/, 'SS').to_s).to eql 'meSSage'
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'can perform replaces with a block' do
|
it 'can perform replaces with a block' do
|
||||||
@ -158,7 +158,6 @@ describe Rackstash::Message do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
describe '#message' do
|
describe '#message' do
|
||||||
it 'is aliased to to_str' do
|
it 'is aliased to to_str' do
|
||||||
message = described_class.new('hello world')
|
message = described_class.new('hello world')
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user