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'
|
|
|
|
|
2019-02-28 15:43:50 -05:00
|
|
|
describe Sidekiq::Logging do
|
|
|
|
describe "#with_context" do
|
|
|
|
def ctx
|
|
|
|
Sidekiq::Logging.logger.formatter.context
|
|
|
|
end
|
2014-12-30 15:51:36 -05:00
|
|
|
|
2019-02-28 15:43:50 -05:00
|
|
|
it "has no context by default" do
|
|
|
|
assert_nil ctx
|
|
|
|
end
|
2014-12-30 15:51:36 -05:00
|
|
|
|
2019-02-28 15:43:50 -05:00
|
|
|
it "can add a context" do
|
|
|
|
Sidekiq::Logging.with_context "xx" do
|
|
|
|
assert_equal " xx", ctx
|
2014-12-30 15:51:36 -05:00
|
|
|
end
|
2019-02-28 15:43:50 -05:00
|
|
|
assert_nil ctx
|
|
|
|
end
|
2014-12-30 15:51:36 -05:00
|
|
|
|
2019-02-28 15:43:50 -05:00
|
|
|
it "can use multiple contexts" do
|
|
|
|
Sidekiq::Logging.with_context "xx" do
|
|
|
|
assert_equal " xx", ctx
|
|
|
|
Sidekiq::Logging.with_context "yy" do
|
|
|
|
assert_equal " xx yy", ctx
|
2014-12-30 15:51:36 -05:00
|
|
|
end
|
2019-02-28 15:43:50 -05:00
|
|
|
assert_equal " xx", ctx
|
2014-12-30 15:51:36 -05:00
|
|
|
end
|
2019-02-28 15:43:50 -05:00
|
|
|
assert_nil ctx
|
2014-12-30 15:51:36 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|