diff options
Diffstat (limited to 'spec/lib/gitlab/usage_data_counters')
7 files changed, 100 insertions, 3 deletions
diff --git a/spec/lib/gitlab/usage_data_counters/aggregated_metrics_spec.rb b/spec/lib/gitlab/usage_data_counters/aggregated_metrics_spec.rb index e9fb5346eae..c0deb2aa00c 100644 --- a/spec/lib/gitlab/usage_data_counters/aggregated_metrics_spec.rb +++ b/spec/lib/gitlab/usage_data_counters/aggregated_metrics_spec.rb @@ -8,7 +8,7 @@ RSpec.describe 'aggregated metrics' do Gitlab::UsageDataCounters::HLLRedisCounter.known_event?(event) end - failure_message do + failure_message do |event| "Event with name: `#{event}` can not be found within `#{Gitlab::UsageDataCounters::HLLRedisCounter::KNOWN_EVENTS_PATH}`" end end diff --git a/spec/lib/gitlab/usage_data_counters/base_counter_spec.rb b/spec/lib/gitlab/usage_data_counters/base_counter_spec.rb new file mode 100644 index 00000000000..4a31191d75f --- /dev/null +++ b/spec/lib/gitlab/usage_data_counters/base_counter_spec.rb @@ -0,0 +1,34 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Gitlab::UsageDataCounters::BaseCounter do + describe '.fetch_supported_event' do + subject { described_class.fetch_supported_event(event_name) } + + let(:event_name) { 'generic_event' } + let(:prefix) { 'generic' } + let(:known_events) { %w[event another_event] } + + before do + allow(described_class).to receive(:prefix) { prefix } + allow(described_class).to receive(:known_events) { known_events } + end + + it 'returns the matching event' do + is_expected.to eq 'event' + end + + context 'when event is unknown' do + let(:event_name) { 'generic_unknown_event' } + + it { is_expected.to be_nil } + end + + context 'when prefix does not match the event name' do + let(:prefix) { 'special' } + + it { is_expected.to be_nil } + end + end +end diff --git a/spec/lib/gitlab/usage_data_counters/editor_unique_counter_spec.rb b/spec/lib/gitlab/usage_data_counters/editor_unique_counter_spec.rb index f2c1d8718d7..82db3d94493 100644 --- a/spec/lib/gitlab/usage_data_counters/editor_unique_counter_spec.rb +++ b/spec/lib/gitlab/usage_data_counters/editor_unique_counter_spec.rb @@ -74,7 +74,19 @@ RSpec.describe Gitlab::UsageDataCounters::EditorUniqueCounter, :clean_gitlab_red end end - it 'can return the count of actions per user deduplicated ' do + context 'for SSE edit actions' do + it_behaves_like 'tracks and counts action' do + def track_action(params) + described_class.track_sse_edit_action(**params) + end + + def count_unique(params) + described_class.count_sse_edit_actions(**params) + end + end + end + + it 'can return the count of actions per user deduplicated' do described_class.track_web_ide_edit_action(author: user1) described_class.track_snippet_editor_edit_action(author: user1) described_class.track_sfe_edit_action(author: user1) diff --git a/spec/lib/gitlab/usage_data_counters/guest_package_event_counter_spec.rb b/spec/lib/gitlab/usage_data_counters/guest_package_event_counter_spec.rb new file mode 100644 index 00000000000..d018100b041 --- /dev/null +++ b/spec/lib/gitlab/usage_data_counters/guest_package_event_counter_spec.rb @@ -0,0 +1,31 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Gitlab::UsageDataCounters::GuestPackageEventCounter, :clean_gitlab_redis_shared_state do + shared_examples_for 'usage counter with totals' do |counter| + it 'increments counter and returns total count' do + expect(described_class.read(counter)).to eq(0) + + 2.times { described_class.count(counter) } + + expect(described_class.read(counter)).to eq(2) + end + end + + it 'includes the right events' do + expect(described_class::KNOWN_EVENTS.size).to eq 33 + end + + described_class::KNOWN_EVENTS.each do |event| + it_behaves_like 'usage counter with totals', event + end + + describe '.fetch_supported_event' do + subject { described_class.fetch_supported_event(event_name) } + + let(:event_name) { 'package_guest_i_package_composer_guest_push' } + + it { is_expected.to eq 'i_package_composer_guest_push' } + end +end diff --git a/spec/lib/gitlab/usage_data_counters/hll_redis_counter_spec.rb b/spec/lib/gitlab/usage_data_counters/hll_redis_counter_spec.rb index 93704a39555..70ee9871486 100644 --- a/spec/lib/gitlab/usage_data_counters/hll_redis_counter_spec.rb +++ b/spec/lib/gitlab/usage_data_counters/hll_redis_counter_spec.rb @@ -30,6 +30,7 @@ RSpec.describe Gitlab::UsageDataCounters::HLLRedisCounter, :clean_gitlab_redis_s 'search', 'source_code', 'incident_management', + 'incident_management_alerts', 'testing', 'issues_edit', 'ci_secrets_management', @@ -43,7 +44,8 @@ RSpec.describe Gitlab::UsageDataCounters::HLLRedisCounter, :clean_gitlab_redis_s 'golang_packages', 'debian_packages', 'container_packages', - 'tag_packages' + 'tag_packages', + 'snippets' ) end end diff --git a/spec/lib/gitlab/usage_data_counters/issue_activity_unique_counter_spec.rb b/spec/lib/gitlab/usage_data_counters/issue_activity_unique_counter_spec.rb index 803eff05efe..bf43f7552e6 100644 --- a/spec/lib/gitlab/usage_data_counters/issue_activity_unique_counter_spec.rb +++ b/spec/lib/gitlab/usage_data_counters/issue_activity_unique_counter_spec.rb @@ -118,6 +118,16 @@ RSpec.describe Gitlab::UsageDataCounters::IssueActivityUniqueCounter, :clean_git end end + context 'for Issue cloned actions' do + it_behaves_like 'a tracked issue edit event' do + let(:action) { described_class::ISSUE_CLONED } + + def track_action(params) + described_class.track_issue_cloned_action(**params) + end + end + end + context 'for Issue relate actions' do it_behaves_like 'a tracked issue edit event' do let(:action) { described_class::ISSUE_RELATED } diff --git a/spec/lib/gitlab/usage_data_counters/search_counter_spec.rb b/spec/lib/gitlab/usage_data_counters/search_counter_spec.rb index b55e20ba555..17188a75ccb 100644 --- a/spec/lib/gitlab/usage_data_counters/search_counter_spec.rb +++ b/spec/lib/gitlab/usage_data_counters/search_counter_spec.rb @@ -20,4 +20,12 @@ RSpec.describe Gitlab::UsageDataCounters::SearchCounter, :clean_gitlab_redis_sha context 'navbar_searches counter' do it_behaves_like 'usage counter with totals', :navbar_searches end + + describe '.fetch_supported_event' do + subject { described_class.fetch_supported_event(event_name) } + + let(:event_name) { 'all_searches' } + + it { is_expected.to eq 'all_searches' } + end end |