From 3cccd102ba543e02725d247893729e5c73b38295 Mon Sep 17 00:00:00 2001 From: GitLab Bot Date: Wed, 20 Apr 2022 10:00:54 +0000 Subject: Add latest changes from gitlab-org/gitlab@14-10-stable-ee --- .../ci_template_unique_counter_spec.rb | 44 ++++++++++++++++------ .../gitlab_cli_activity_unique_counter_spec.rb | 15 ++++++++ 2 files changed, 48 insertions(+), 11 deletions(-) create mode 100644 spec/lib/gitlab/usage_data_counters/gitlab_cli_activity_unique_counter_spec.rb (limited to 'spec/lib/gitlab/usage_data_counters') diff --git a/spec/lib/gitlab/usage_data_counters/ci_template_unique_counter_spec.rb b/spec/lib/gitlab/usage_data_counters/ci_template_unique_counter_spec.rb index 222198a58ac..6a37bfd106d 100644 --- a/spec/lib/gitlab/usage_data_counters/ci_template_unique_counter_spec.rb +++ b/spec/lib/gitlab/usage_data_counters/ci_template_unique_counter_spec.rb @@ -5,30 +5,52 @@ require 'spec_helper' RSpec.describe Gitlab::UsageDataCounters::CiTemplateUniqueCounter do describe '.track_unique_project_event' do using RSpec::Parameterized::TableSyntax + include SnowplowHelpers - let(:project_id) { 1 } + let(:project) { build(:project) } + let(:user) { build(:user) } shared_examples 'tracks template' do + let(:subject) { described_class.track_unique_project_event(project: project, template: template_path, config_source: config_source, user: user) } + it "has an event defined for template" do expect do - described_class.track_unique_project_event( - project_id: project_id, - template: template_path, - config_source: config_source - ) + subject end.not_to raise_error end it "tracks template" do expanded_template_name = described_class.expand_template_name(template_path) expected_template_event_name = described_class.ci_template_event_name(expanded_template_name, config_source) - expect(Gitlab::UsageDataCounters::HLLRedisCounter).to(receive(:track_event)).with(expected_template_event_name, values: project_id) + expect(Gitlab::UsageDataCounters::HLLRedisCounter).to(receive(:track_event)).with(expected_template_event_name, values: project.id) + + subject + end + + context 'Snowplow' do + it 'event is not tracked if FF is disabled' do + stub_feature_flags(route_hll_to_snowplow: false) + + subject - described_class.track_unique_project_event(project_id: project_id, template: template_path, config_source: config_source) + expect_no_snowplow_event + end + + it 'tracks event' do + subject + + expect_snowplow_event( + category: described_class.to_s, + action: 'ci_templates_unique', + namespace: project.namespace, + user: user, + project: project + ) + end end end - context 'with explicit includes' do + context 'with explicit includes', :snowplow do let(:config_source) { :repository_source } (described_class.ci_templates - ['Verify/Browser-Performance.latest.gitlab-ci.yml', 'Verify/Browser-Performance.gitlab-ci.yml']).each do |template| @@ -40,7 +62,7 @@ RSpec.describe Gitlab::UsageDataCounters::CiTemplateUniqueCounter do end end - context 'with implicit includes' do + context 'with implicit includes', :snowplow do let(:config_source) { :auto_devops_source } [ @@ -60,7 +82,7 @@ RSpec.describe Gitlab::UsageDataCounters::CiTemplateUniqueCounter do it 'expands short template names' do expect do - described_class.track_unique_project_event(project_id: 1, template: 'Dependency-Scanning.gitlab-ci.yml', config_source: :repository_source) + described_class.track_unique_project_event(project: project, template: 'Dependency-Scanning.gitlab-ci.yml', config_source: :repository_source, user: user) end.not_to raise_error end end diff --git a/spec/lib/gitlab/usage_data_counters/gitlab_cli_activity_unique_counter_spec.rb b/spec/lib/gitlab/usage_data_counters/gitlab_cli_activity_unique_counter_spec.rb new file mode 100644 index 00000000000..d6eb67e5c35 --- /dev/null +++ b/spec/lib/gitlab/usage_data_counters/gitlab_cli_activity_unique_counter_spec.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Gitlab::UsageDataCounters::GitLabCliActivityUniqueCounter, :clean_gitlab_redis_shared_state do # rubocop:disable RSpec/FilePath + let(:user1) { build(:user, id: 1) } + let(:user2) { build(:user, id: 2) } + let(:time) { Time.current } + let(:action) { described_class::GITLAB_CLI_API_REQUEST_ACTION } + let(:user_agent) { { user_agent: 'GLab - GitLab CLI' } } + + context 'when tracking a gitlab cli request' do + it_behaves_like 'a request from an extension' + end +end -- cgit v1.2.1