2014-12-31 19:49:49 +05:30
|
|
|
require_relative 'helper'
|
2014-12-30 12:51:36 -08:00
|
|
|
require 'sidekiq/logging'
|
|
|
|
|
2015-09-22 12:48:43 -07:00
|
|
|
class TestLogging < Sidekiq::Test
|
2014-12-30 12:51:36 -08:00
|
|
|
describe Sidekiq::Logging do
|
|
|
|
describe "#with_context" do
|
|
|
|
def context
|
|
|
|
Sidekiq::Logging.logger.formatter.context
|
|
|
|
end
|
|
|
|
|
|
|
|
it "has no context by default" do
|
2014-12-30 13:01:30 -08:00
|
|
|
context.must_equal nil
|
2014-12-30 12:51:36 -08:00
|
|
|
end
|
|
|
|
|
|
|
|
it "can add a context" do
|
|
|
|
Sidekiq::Logging.with_context "xx" do
|
|
|
|
context.must_equal " xx"
|
|
|
|
end
|
2014-12-30 13:01:30 -08:00
|
|
|
context.must_equal nil
|
2014-12-30 12:51:36 -08:00
|
|
|
end
|
|
|
|
|
|
|
|
it "can use multiple contexts" do
|
|
|
|
Sidekiq::Logging.with_context "xx" do
|
|
|
|
context.must_equal " xx"
|
|
|
|
Sidekiq::Logging.with_context "yy" do
|
2014-12-30 13:01:30 -08:00
|
|
|
context.must_equal " xx yy"
|
2014-12-30 12:51:36 -08:00
|
|
|
end
|
|
|
|
context.must_equal " xx"
|
|
|
|
end
|
2014-12-30 13:01:30 -08:00
|
|
|
context.must_equal nil
|
2014-12-30 12:51:36 -08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|