diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-06-18 14:18:50 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-06-18 14:18:50 +0300 |
commit | 8c7f4e9d5f36cff46365a7f8c4b9c21578c1e781 (patch) | |
tree | a77e7fe7a93de11213032ed4ab1f33a3db51b738 /spec/lib/gitlab/lograge | |
parent | 00b35af3db1abfe813a778f643dad221aad51fca (diff) |
Add latest changes from gitlab-org/gitlab@13-1-stable-ee
Diffstat (limited to 'spec/lib/gitlab/lograge')
-rw-r--r-- | spec/lib/gitlab/lograge/custom_options_spec.rb | 57 |
1 files changed, 34 insertions, 23 deletions
diff --git a/spec/lib/gitlab/lograge/custom_options_spec.rb b/spec/lib/gitlab/lograge/custom_options_spec.rb index 7ae8baa31b5..ebf150d21ef 100644 --- a/spec/lib/gitlab/lograge/custom_options_spec.rb +++ b/spec/lib/gitlab/lograge/custom_options_spec.rb @@ -13,21 +13,16 @@ describe Gitlab::Lograge::CustomOptions do } end - let(:event) do - ActiveSupport::Notifications::Event.new( - 'test', - 1, - 2, - 'transaction_id', - { - params: params, - user_id: 'test', - cf_ray: SecureRandom.hex, - cf_request_id: SecureRandom.hex, - metadata: { 'meta.user' => 'jane.doe' } - } - ) + let(:event_payload) do + { + params: params, + user_id: 'test', + cf_ray: SecureRandom.hex, + cf_request_id: SecureRandom.hex, + metadata: { 'meta.user' => 'jane.doe' } + } end + let(:event) { ActiveSupport::Notifications::Event.new('test', 1, 2, 'transaction_id', event_payload) } subject { described_class.call(event) } @@ -49,6 +44,18 @@ describe Gitlab::Lograge::CustomOptions do end end + context 'with transaction' do + let(:transaction) { Gitlab::Metrics::WebTransaction.new({}) } + + before do + allow(Gitlab::Metrics::Transaction).to receive(:current).and_return(transaction) + end + + it 'adds db counters' do + expect(subject).to include(:db_count, :db_write_count, :db_cached_count) + end + end + it 'adds the user id' do expect(subject[:user_id]).to eq('test') end @@ -63,19 +70,23 @@ describe Gitlab::Lograge::CustomOptions do end context 'when metadata is missing' do - let(:event) do - ActiveSupport::Notifications::Event.new( - 'test', - 1, - 2, - 'transaction_id', - { params: {} } - ) - end + let(:event_payload) { { params: {} } } it 'does not break' do expect { subject }.not_to raise_error end end + + context 'when correlation_id is overriden' do + let(:correlation_id_key) { Labkit::Correlation::CorrelationId::LOG_KEY } + + before do + event_payload[correlation_id_key] = '123456' + end + + it 'sets the overriden value' do + expect(subject[correlation_id_key]).to eq('123456') + end + end end end |