Skip to content

Commit

Permalink
test(job_start_log): new tests for job_start_log configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
Mahdi Dibaiee committed Apr 11, 2019
1 parent a3f68bc commit 25ac339
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions spec/sidekiq/logstash_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,16 @@
end
end

it 'logs only a single line (doesn\'t have a "started" log by default)' do
buffer = StringIO.new
Sidekiq.logger = Logger.new(buffer)

log_job = Sidekiq::LogstashJobLogger.new.call(job, :default) {}

expect(buffer.string.split("\n").length).to eq(1)
expect(buffer.string).not_to include('"job_status"=>"started"')
end

it 'filter args' do
Sidekiq::Logstash.configure do |config|
config.filter_args << 'a_secret_param'
Expand Down Expand Up @@ -51,4 +61,34 @@
expect(log_job['args'][2]).to include('[ENCRYPTED]')
end
end

context 'enable job_start_log' do
it 'generates log with job_status=started' do
buffer = StringIO.new
Sidekiq.logger = Logger.new(buffer)

Sidekiq::Logstash.configure do |config|
config.job_start_log = true
end

log_job = Sidekiq::Middleware::Server::LogstashLogging.new.log_job(job, Time.now.utc, exc = nil, start = true)

expect(log_job['job_status']).to eq('started')
end

it 'logs both the starting and finished logs' do
buffer = StringIO.new
Sidekiq.logger = Logger.new(buffer)

Sidekiq::Logstash.configure do |config|
config.job_start_log = true
end

log_job = Sidekiq::LogstashJobLogger.new.call(job, :default) {}

expect(buffer.string.split("\n").length).to eq(2)
expect(buffer.string).to include('"job_status"=>"started"')
expect(buffer.string).to include('"job_status"=>"done"')
end
end
end

0 comments on commit 25ac339

Please sign in to comment.