diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-05-19 12:07:52 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-05-19 12:07:52 +0300 |
commit | ee3d5f16e3aa642944b121645764e33604a31307 (patch) | |
tree | 6b27cb8fca43bdac8d558d689b64c7298ea3cb37 /spec/lib/gitlab/silent_mode_spec.rb | |
parent | 765ec2e3b2eb347314af5f806c6b70bad696265a (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/lib/gitlab/silent_mode_spec.rb')
-rw-r--r-- | spec/lib/gitlab/silent_mode_spec.rb | 97 |
1 files changed, 97 insertions, 0 deletions
diff --git a/spec/lib/gitlab/silent_mode_spec.rb b/spec/lib/gitlab/silent_mode_spec.rb new file mode 100644 index 00000000000..bccf7033121 --- /dev/null +++ b/spec/lib/gitlab/silent_mode_spec.rb @@ -0,0 +1,97 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Gitlab::SilentMode, feature_category: :geo_replication do + before do + stub_application_setting(silent_mode_enabled: silent_mode) + end + + describe '.enabled?' do + context 'when silent mode is enabled' do + let(:silent_mode) { true } + + it { expect(described_class.enabled?).to be_truthy } + end + + context 'when silent mode is disabled' do + let(:silent_mode) { false } + + it { expect(described_class.enabled?).to be_falsey } + end + end + + describe '.log_info' do + let(:log_args) do + { + message: 'foo', + bar: 'baz' + } + end + + let(:expected_log_args) { log_args.merge(silent_mode_enabled: silent_mode) } + + context 'when silent mode is enabled' do + let(:silent_mode) { true } + + it 'logs to AppJsonLogger and adds the current state of silent mode' do + expect(Gitlab::AppJsonLogger).to receive(:info).with(expected_log_args) + + described_class.log_info(log_args) + end + end + + context 'when silent mode is disabled' do + let(:silent_mode) { false } + + it 'logs to AppJsonLogger and adds the current state of silent mode' do + expect(Gitlab::AppJsonLogger).to receive(:info).with(expected_log_args) + + described_class.log_info(log_args) + end + + it 'overwrites silent_mode_enabled log key if call already contains it' do + expect(Gitlab::AppJsonLogger).to receive(:info).with(expected_log_args) + + described_class.log_info(log_args.merge(silent_mode_enabled: 'foo')) + end + end + end + + describe '.log_debug' do + let(:log_args) do + { + message: 'foo', + bar: 'baz' + } + end + + let(:expected_log_args) { log_args.merge(silent_mode_enabled: silent_mode) } + + context 'when silent mode is enabled' do + let(:silent_mode) { true } + + it 'logs to AppJsonLogger and adds the current state of silent mode' do + expect(Gitlab::AppJsonLogger).to receive(:debug).with(expected_log_args) + + described_class.log_debug(log_args) + end + end + + context 'when silent mode is disabled' do + let(:silent_mode) { false } + + it 'logs to AppJsonLogger and adds the current state of silent mode' do + expect(Gitlab::AppJsonLogger).to receive(:debug).with(expected_log_args) + + described_class.log_debug(log_args) + end + + it 'overwrites silent_mode_enabled log key if call already contains it' do + expect(Gitlab::AppJsonLogger).to receive(:debug).with(expected_log_args) + + described_class.log_debug(log_args.merge(silent_mode_enabled: 'foo')) + end + end + end +end |