diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-11-19 11:27:35 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-11-19 11:27:35 +0300 |
commit | 7e9c479f7de77702622631cff2628a9c8dcbc627 (patch) | |
tree | c8f718a08e110ad7e1894510980d2155a6549197 /spec/services/packages/create_event_service_spec.rb | |
parent | e852b0ae16db4052c1c567d9efa4facc81146e88 (diff) |
Add latest changes from gitlab-org/gitlab@13-6-stable-eev13.6.0-rc42
Diffstat (limited to 'spec/services/packages/create_event_service_spec.rb')
-rw-r--r-- | spec/services/packages/create_event_service_spec.rb | 78 |
1 files changed, 65 insertions, 13 deletions
diff --git a/spec/services/packages/create_event_service_spec.rb b/spec/services/packages/create_event_service_spec.rb index 7e66b430a8c..55703e9127f 100644 --- a/spec/services/packages/create_event_service_spec.rb +++ b/spec/services/packages/create_event_service_spec.rb @@ -15,40 +15,92 @@ RSpec.describe Packages::CreateEventService do subject { described_class.new(nil, user, params).execute } describe '#execute' do - shared_examples 'package event creation' do |originator_type, expected_scope| - it 'creates the event' do - expect { subject }.to change { Packages::Event.count }.by(1) - - expect(subject.originator_type).to eq(originator_type) - expect(subject.originator).to eq(user&.id) - expect(subject.event_scope).to eq(expected_scope) - expect(subject.event_type).to eq(event_name) + shared_examples 'db package event creation' do |originator_type, expected_scope| + before do + allow(::Gitlab::UsageDataCounters::HLLRedisCounter).to receive(:track_event) + end + + context 'with feature flag disable' do + before do + stub_feature_flags(collect_package_events: false) + end + + it 'does not create an event object' do + expect { subject }.not_to change { Packages::Event.count } + end + end + + context 'with feature flag enabled' do + before do + stub_feature_flags(collect_package_events: true) + end + + it 'creates the event' do + expect { subject }.to change { Packages::Event.count }.by(1) + + expect(subject.originator_type).to eq(originator_type) + expect(subject.originator).to eq(user&.id) + expect(subject.event_scope).to eq(expected_scope) + expect(subject.event_type).to eq(event_name) + end + end + end + + shared_examples 'redis package event creation' do |originator_type, expected_scope| + context 'with feature flag disable' do + before do + stub_feature_flags(collect_package_events_redis: false) + end + + it 'does not track the event' do + expect(::Gitlab::UsageDataCounters::HLLRedisCounter).not_to receive(:track_event) + + subject + end + end + + it 'tracks the event' do + expect(::Gitlab::UsageDataCounters::HLLRedisCounter).to receive(:track_event).with(user.id, Packages::Event.allowed_event_name(expected_scope, event_name, originator_type)) + + subject end end context 'with a user' do let(:user) { create(:user) } - it_behaves_like 'package event creation', 'user', 'container' + it_behaves_like 'db package event creation', 'user', 'container' + it_behaves_like 'redis package event creation', 'user', 'container' end context 'with a deploy token' do let(:user) { create(:deploy_token) } - it_behaves_like 'package event creation', 'deploy_token', 'container' + it_behaves_like 'db package event creation', 'deploy_token', 'container' + it_behaves_like 'redis package event creation', 'deploy_token', 'container' end context 'with no user' do let(:user) { nil } - it_behaves_like 'package event creation', 'guest', 'container' + it_behaves_like 'db package event creation', 'guest', 'container' end context 'with a package as scope' do - let(:user) { nil } let(:scope) { create(:npm_package) } - it_behaves_like 'package event creation', 'guest', 'npm' + context 'as guest' do + let(:user) { nil } + + it_behaves_like 'db package event creation', 'guest', 'npm' + end + + context 'with user' do + let(:user) { create(:user) } + + it_behaves_like 'db package event creation', 'user', 'npm' + it_behaves_like 'redis package event creation', 'user', 'npm' + end end end end |