diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-11-30 00:09:59 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-11-30 00:09:59 +0300 |
commit | b5eff9f970d14c07742d3bbc60344cd738d4a9d2 (patch) | |
tree | 506389dda1530b37382085590c8ae482f8ae613d /spec/lib/generators | |
parent | 2d239d2421eea466ff5c51aebdbf05a18ded20c7 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/lib/generators')
-rw-r--r-- | spec/lib/generators/gitlab/analytics/group_fetcher_spec.rb | 100 | ||||
-rw-r--r-- | spec/lib/generators/gitlab/analytics/internal_events_generator_spec.rb | 13 |
2 files changed, 108 insertions, 5 deletions
diff --git a/spec/lib/generators/gitlab/analytics/group_fetcher_spec.rb b/spec/lib/generators/gitlab/analytics/group_fetcher_spec.rb new file mode 100644 index 00000000000..77cc3904560 --- /dev/null +++ b/spec/lib/generators/gitlab/analytics/group_fetcher_spec.rb @@ -0,0 +1,100 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Gitlab::Analytics::GroupFetcher, :silence_stdout, feature_category: :service_ping do + let(:stage_data) do + <<~YAML + stages: + analyze: + section: analytics + groups: + analytics_instrumentation: + secure: + section: security + groups: + static_analysis: + dynamic_analysis: + YAML + end + + let(:response) { instance_double(HTTParty::Response, success?: true, body: stage_data) } + + around do |example| + described_class.instance_variable_set(:@groups, nil) + example.run + described_class.instance_variable_set(:@groups, nil) + end + + before do + allow(Gitlab::HTTP).to receive(:get).and_return(response) + end + + context 'when online' do + describe '.group_unknown?' do + it 'returns false for known groups' do + expect(described_class.group_unknown?('analytics_instrumentation')).to be_falsy + end + + it 'returns true for unknown groups' do + expect(described_class.group_unknown?('unknown')).to be_truthy + end + end + + describe '.stage_text' do + it 'returns the stage name for known groups' do + expect(described_class.stage_text('analytics_instrumentation')).to eq('analyze') + end + + it 'returns empty string for unknown group' do + expect(described_class.stage_text('unknown')).to eq('') + end + end + + describe '.section_text' do + it 'returns the section name for known groups' do + expect(described_class.section_text('analytics_instrumentation')).to eq('analytics') + end + + it 'returns empty string for unknown group' do + expect(described_class.section_text('unknown')).to eq('') + end + end + end + + context 'when offline' do + before do + allow(Gitlab::HTTP).to receive(:get).and_raise(Gitlab::HTTP_V2::BlockedUrlError) + end + + describe '.group_unknown?' do + it 'returns false for known groups' do + expect(described_class.group_unknown?('analytics_instrumentation')).to be_falsy + end + + it 'returns false for unknown group' do + expect(described_class.group_unknown?('unknown')).to be_falsy + end + end + + describe '.stage_text' do + it 'returns empty string for known groups' do + expect(described_class.stage_text('analytics_instrumentation')).to eq('') + end + + it 'returns empty string for unknown groups' do + expect(described_class.stage_text('unknown')).to eq('') + end + end + + describe '.section_text' do + it 'returns empty string for known groups' do + expect(described_class.section_text('analytics_instrumentation')).to eq('') + end + + it 'returns empty string for unknown groups' do + expect(described_class.section_text('unknown')).to eq('') + end + end + end +end diff --git a/spec/lib/generators/gitlab/analytics/internal_events_generator_spec.rb b/spec/lib/generators/gitlab/analytics/internal_events_generator_spec.rb index d28d12cb0d0..520a56db713 100644 --- a/spec/lib/generators/gitlab/analytics/internal_events_generator_spec.rb +++ b/spec/lib/generators/gitlab/analytics/internal_events_generator_spec.rb @@ -10,13 +10,14 @@ RSpec.describe Gitlab::Analytics::InternalEventsGenerator, :silence_stdout, feat let(:tmpfile) { Tempfile.new('test-metadata') } let(:existing_key_paths) { {} } let(:description) { "This metric counts unique users viewing analytics metrics dashboard section" } - let(:group) { "group::analytics instrumentation" } - let(:stage) { "analytics" } + let(:group) { "analytics_instrumentation" } + let(:stage) { "analyze" } let(:section) { "analytics" } let(:mr) { "https://gitlab.com/some-group/some-project/-/merge_requests/123" } let(:event) { "view_analytics_dashboard" } let(:unique) { "user.id" } let(:time_frames) { %w[7d] } + let(:group_unknown) { false } let(:include_default_identifiers) { 'yes' } let(:base_options) do { @@ -24,8 +25,6 @@ RSpec.describe Gitlab::Analytics::InternalEventsGenerator, :silence_stdout, feat free: true, mr: mr, group: group, - stage: stage, - section: section, event: event, unique: unique }.stringify_keys @@ -45,6 +44,10 @@ RSpec.describe Gitlab::Analytics::InternalEventsGenerator, :silence_stdout, feat .and_return(description) end + allow(Gitlab::Analytics::GroupFetcher).to receive(:group_unknown?).and_return(group_unknown) + allow(Gitlab::Analytics::GroupFetcher).to receive(:stage_text).with(group).and_return(stage) + allow(Gitlab::Analytics::GroupFetcher).to receive(:section_text).with(group).and_return(section) + allow(Gitlab::TaskHelpers).to receive(:prompt).and_return(include_default_identifiers) allow(Gitlab::Usage::MetricDefinition).to receive(:definitions).and_return(existing_key_paths) end @@ -260,7 +263,7 @@ RSpec.describe Gitlab::Analytics::InternalEventsGenerator, :silence_stdout, feat context 'without obligatory parameter' do it 'raises error', :aggregate_failures do - %w[event mr section stage group].each do |option| + %w[event mr group].each do |option| expect { described_class.new([], options.without(option)).invoke_all } .to raise_error(RuntimeError) end |