2015-12-31 18:33:35 -05:00
|
|
|
# frozen_string_literal: true
|
2014-12-31 09:19:49 -05:00
|
|
|
require_relative 'helper'
|
2014-12-30 15:51:36 -05:00
|
|
|
require 'sidekiq/logging'
|
|
|
|
|
2015-09-22 15:48:43 -04:00
|
|
|
class TestLogging < Sidekiq::Test
|
2014-12-30 15:51:36 -05:00
|
|
|
describe Sidekiq::Logging do
|
|
|
|
describe "#with_context" do
|
2017-01-02 15:06:02 -05:00
|
|
|
def ctx
|
2014-12-30 15:51:36 -05:00
|
|
|
Sidekiq::Logging.logger.formatter.context
|
|
|
|
end
|
|
|
|
|
|
|
|
it "has no context by default" do
|
2017-01-02 15:06:02 -05:00
|
|
|
assert_nil ctx
|
2014-12-30 15:51:36 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it "can add a context" do
|
|
|
|
Sidekiq::Logging.with_context "xx" do
|
2017-01-02 15:06:02 -05:00
|
|
|
assert_equal " xx", ctx
|
2014-12-30 15:51:36 -05:00
|
|
|
end
|
2017-01-02 15:06:02 -05:00
|
|
|
assert_nil ctx
|
2014-12-30 15:51:36 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it "can use multiple contexts" do
|
|
|
|
Sidekiq::Logging.with_context "xx" do
|
2017-01-02 15:06:02 -05:00
|
|
|
assert_equal " xx", ctx
|
2014-12-30 15:51:36 -05:00
|
|
|
Sidekiq::Logging.with_context "yy" do
|
2017-01-02 15:06:02 -05:00
|
|
|
assert_equal " xx yy", ctx
|
2014-12-30 15:51:36 -05:00
|
|
|
end
|
2017-01-02 15:06:02 -05:00
|
|
|
assert_equal " xx", ctx
|
2014-12-30 15:51:36 -05:00
|
|
|
end
|
2017-01-02 15:06:02 -05:00
|
|
|
assert_nil ctx
|
2014-12-30 15:51:36 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|