Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2023-04-25 00:18:05 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2023-04-25 00:18:05 +0300
commit3d911c6c1f34df47036f1d7e0838e4d5876ee923 (patch)
tree492dfc9e4a3d3ea6d4749f35a78abafe634889f6 /spec
parent0bf82aa5cb3b1ed826dd5c0d46331e17aa60d9e9 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
-rw-r--r--spec/controllers/projects/blame_controller_spec.rb10
-rw-r--r--spec/helpers/blame_helper_spec.rb23
-rw-r--r--spec/routing/project_routing_spec.rb8
-rw-r--r--spec/tooling/lib/tooling/find_files_using_feature_flags_spec.rb122
-rw-r--r--spec/tooling/lib/tooling/helpers/predictive_tests_helper_spec.rb (renamed from spec/tooling/lib/tooling/mappings/base_spec.rb)13
-rw-r--r--spec/workers/namespaces/root_statistics_worker_spec.rb116
-rw-r--r--spec/workers/namespaces/schedule_aggregation_worker_spec.rb98
7 files changed, 223 insertions, 167 deletions
diff --git a/spec/controllers/projects/blame_controller_spec.rb b/spec/controllers/projects/blame_controller_spec.rb
index 06c82bcb404..50556bdb652 100644
--- a/spec/controllers/projects/blame_controller_spec.rb
+++ b/spec/controllers/projects/blame_controller_spec.rb
@@ -54,4 +54,14 @@ RSpec.describe Projects::BlameController, feature_category: :source_code_managem
it_behaves_like 'blame_response'
end
+
+ describe 'GET streaming' do
+ render_views
+
+ before do
+ get :streaming, params: { namespace_id: project.namespace, project_id: project, id: id }
+ end
+
+ it_behaves_like 'blame_response'
+ end
end
diff --git a/spec/helpers/blame_helper_spec.rb b/spec/helpers/blame_helper_spec.rb
index d305c4c595e..54d714b2038 100644
--- a/spec/helpers/blame_helper_spec.rb
+++ b/spec/helpers/blame_helper_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-RSpec.describe BlameHelper do
+RSpec.describe BlameHelper, feature_category: :source_code_management do
describe '#get_age_map_start_date' do
let(:dates) do
[Time.zone.local(2014, 3, 17, 0, 0, 0),
@@ -67,4 +67,25 @@ RSpec.describe BlameHelper do
end
end
end
+
+ describe '#entire_blame_path' do
+ subject { helper.entire_blame_path(id, project, blame_mode) }
+
+ let_it_be(:project) { build_stubbed(:project) }
+
+ let(:id) { 'main/README.md' }
+ let(:blame_mode) { instance_double('Gitlab::Git::BlameMode', 'streaming_supported?' => streaming_enabled) }
+
+ context 'when streaming is supported' do
+ let(:streaming_enabled) { true }
+
+ it { is_expected.to eq "/#{project.full_path}/-/blame/#{id}/streaming" }
+ end
+
+ context 'when streaming is not supported' do
+ let(:streaming_enabled) { false }
+
+ it { is_expected.to eq "/#{project.full_path}/-/blame/#{id}?no_pagination=true" }
+ end
+ end
end
diff --git a/spec/routing/project_routing_spec.rb b/spec/routing/project_routing_spec.rb
index b1fafffb253..c2a3afc0e57 100644
--- a/spec/routing/project_routing_spec.rb
+++ b/spec/routing/project_routing_spec.rb
@@ -491,6 +491,14 @@ RSpec.describe 'project routing' do
namespace_id: 'gitlab', project_id: 'gitlabhq',
id: "master/#{newline_file}" })
end
+
+ it 'to #streaming' do
+ expect(get('/gitlab/gitlabhq/-/blame/master/app/models/project.rb/streaming')).to route_to('projects/blame#streaming', namespace_id: 'gitlab', project_id: 'gitlabhq', id: 'master/app/models/project.rb', streaming: true)
+ end
+
+ it 'to #page' do
+ expect(get('/gitlab/gitlabhq/-/blame_page/master/app/models/project.rb')).to route_to('projects/blame#page', namespace_id: 'gitlab', project_id: 'gitlabhq', id: 'master/app/models/project.rb')
+ end
end
# project_blob GET /:project_id/-/blob/:id(.:format) blob#show {id: /[^\0]+/, project_id: /[^\/]+/}
diff --git a/spec/tooling/lib/tooling/find_files_using_feature_flags_spec.rb b/spec/tooling/lib/tooling/find_files_using_feature_flags_spec.rb
new file mode 100644
index 00000000000..f553d34768f
--- /dev/null
+++ b/spec/tooling/lib/tooling/find_files_using_feature_flags_spec.rb
@@ -0,0 +1,122 @@
+# frozen_string_literal: true
+
+require 'tempfile'
+require_relative '../../../../tooling/lib/tooling/find_files_using_feature_flags'
+
+RSpec.describe Tooling::FindFilesUsingFeatureFlags, feature_category: :tooling do
+ attr_accessor :changed_files_file
+
+ let(:changed_files_pathname) { changed_files_file.path }
+ let(:instance) { described_class.new(changed_files_pathname: changed_files_pathname) }
+ let(:changed_files_content) { '' }
+
+ around do |example|
+ self.changed_files_file = Tempfile.new('changed_files_file')
+
+ # See https://ruby-doc.org/stdlib-1.9.3/libdoc/tempfile/rdoc/
+ # Tempfile.html#class-Tempfile-label-Explicit+close
+ begin
+ example.run
+ ensure
+ changed_files_file.close
+ changed_files_file.unlink
+ end
+ end
+
+ before do
+ allow(File).to receive(:exist?).and_call_original
+ allow(File).to receive(:read).and_call_original
+
+ File.write(changed_files_pathname, changed_files_content)
+ end
+
+ describe '#execute' do
+ subject { instance.execute }
+
+ let(:valid_ff_pathname_1) { 'config/feature_flags/development/my_feature_flag.yml' }
+ let(:valid_ff_pathname_2) { 'config/feature_flags/development/my_other_feature_flag.yml' }
+ let(:changed_files_content) { "#{valid_ff_pathname_1} #{valid_ff_pathname_2}" }
+ let(:ruby_files) { [] }
+
+ before do
+ allow(File).to receive(:exist?).with(valid_ff_pathname_1).and_return(true)
+ allow(File).to receive(:exist?).with(valid_ff_pathname_2).and_return(true)
+ allow(Dir).to receive(:[]).with('**/*.rb').and_return(ruby_files)
+ end
+
+ context 'when no ruby files are using the modified feature flag' do
+ let(:ruby_files) { [] }
+
+ it 'does not add anything to the input file' do
+ expect { subject }.not_to change { File.read(changed_files_pathname) }
+ end
+ end
+
+ context 'when some ruby files are using the modified feature flags' do
+ let(:matching_ruby_file_1) { 'first-ruby-file' }
+ let(:matching_ruby_file_2) { 'second-ruby-file' }
+ let(:not_matching_ruby_file) { 'third-ruby-file' }
+ let(:ruby_files) { [matching_ruby_file_1, matching_ruby_file_2, not_matching_ruby_file] }
+
+ before do
+ allow(File).to receive(:read).with(matching_ruby_file_1).and_return('my_feature_flag')
+ allow(File).to receive(:read).with(matching_ruby_file_2).and_return('my_other_feature_flag')
+ allow(File).to receive(:read).with(not_matching_ruby_file).and_return('other text')
+ end
+
+ it 'add the matching ruby files to the input file' do
+ expect { subject }.to change { File.read(changed_files_pathname) }
+ .from(changed_files_content)
+ .to("#{changed_files_content} #{matching_ruby_file_1} #{matching_ruby_file_2}")
+ end
+ end
+ end
+
+ describe '#filter_files' do
+ subject { instance.filter_files }
+
+ let(:changed_files_content) { path_to_file }
+
+ context 'when the file does not exist on disk' do
+ let(:path_to_file) { "config/other_feature_flags_folder/feature.yml" }
+
+ before do
+ allow(File).to receive(:exist?).with(path_to_file).and_return(false)
+ end
+
+ it 'returns an empty array' do
+ expect(subject).to be_empty
+ end
+ end
+
+ context 'when the file exists on disk' do
+ before do
+ allow(File).to receive(:exist?).with(path_to_file).and_return(true)
+ end
+
+ context 'when the file is not in the features folder' do
+ let(:path_to_file) { "config/other_folder/development/feature.yml" }
+
+ it 'returns an empty array' do
+ expect(subject).to be_empty
+ end
+ end
+
+ context 'when the filename does not have the correct extension' do
+ let(:path_to_file) { "config/feature_flags/development/feature.rb" }
+
+ it 'returns an empty array' do
+ expect(subject).to be_empty
+ end
+ end
+
+ context 'when the ruby file uses a valid feature flag file' do
+ let(:path_to_file) { "config/feature_flags/development/feature.yml" }
+
+ it 'returns the file' do
+ expect(subject).to match_array(path_to_file)
+ end
+ end
+ end
+ end
+end
diff --git a/spec/tooling/lib/tooling/mappings/base_spec.rb b/spec/tooling/lib/tooling/helpers/predictive_tests_helper_spec.rb
index 935f833fa8b..48a5866ac56 100644
--- a/spec/tooling/lib/tooling/mappings/base_spec.rb
+++ b/spec/tooling/lib/tooling/helpers/predictive_tests_helper_spec.rb
@@ -1,12 +1,19 @@
# frozen_string_literal: true
-require_relative '../../../../../tooling/lib/tooling/mappings/view_to_js_mappings'
+require 'tempfile'
+require_relative '../../../../../tooling/lib/tooling/helpers/predictive_tests_helper'
+
+class MockClass # rubocop:disable Gitlab/NamespacedClass
+ include Tooling::Helpers::PredictiveTestsHelper
+end
+
+RSpec.describe Tooling::Helpers::PredictiveTestsHelper, feature_category: :tooling do
+ let(:instance) { MockClass.new }
-RSpec.describe Tooling::Mappings::Base, feature_category: :tooling do
describe '#folders_for_available_editions' do
let(:base_folder_path) { 'app/views' }
- subject { described_class.new.folders_for_available_editions(base_folder_path) }
+ subject { instance.folders_for_available_editions(base_folder_path) }
context 'when FOSS' do
before do
diff --git a/spec/workers/namespaces/root_statistics_worker_spec.rb b/spec/workers/namespaces/root_statistics_worker_spec.rb
index bc2eca86711..2224d94cd9d 100644
--- a/spec/workers/namespaces/root_statistics_worker_spec.rb
+++ b/spec/workers/namespaces/root_statistics_worker_spec.rb
@@ -7,84 +7,44 @@ RSpec.describe Namespaces::RootStatisticsWorker, '#perform', feature_category: :
subject(:worker) { described_class.new }
- RSpec.shared_examples 'bypasses aggregation schedule' do
+ context 'with a namespace' do
it 'executes refresher service' do
expect_any_instance_of(Namespaces::StatisticsRefresherService)
.to receive(:execute).and_call_original
- expect(group).not_to receive(:aggregation_scheduled?)
worker.perform(group.id)
end
- it 'does not change AggregationSchedule count' do
- expect do
- worker.perform(group.id)
- end.not_to change { Namespace::AggregationSchedule.count }
- end
- end
-
- context 'with a namespace' do
- context 'with remove_aggregation_schedule_lease feature flag enabled' do
- it_behaves_like 'bypasses aggregation schedule'
-
- context 'when something goes wrong when updating' do
- before do
- allow_any_instance_of(Namespaces::StatisticsRefresherService)
- .to receive(:execute)
- .and_raise(Namespaces::StatisticsRefresherService::RefresherError, 'error')
- end
-
- it 'logs the error' do
- expect(Gitlab::ErrorTracking).to receive(:track_exception).once
+ it 'deletes namespace aggregated schedule row' do
+ worker.perform(group.id)
- worker.perform(group.id)
- end
- end
+ expect(group.reload.aggregation_schedule).to be_nil
end
- context 'with remove_aggregation_schedule_lease feature flag disabled' do
+ context 'when something goes wrong when updating' do
before do
- stub_feature_flags(remove_aggregation_schedule_lease: false)
- end
-
- it 'executes refresher service' do
- expect_any_instance_of(Namespaces::StatisticsRefresherService)
- .to receive(:execute).and_call_original
-
- worker.perform(group.id)
+ allow_any_instance_of(Namespaces::StatisticsRefresherService)
+ .to receive(:execute)
+ .and_raise(Namespaces::StatisticsRefresherService::RefresherError, 'error')
end
- it 'deletes namespace aggregated schedule row' do
+ it 'does not delete the aggregation schedule' do
worker.perform(group.id)
- expect(group.reload.aggregation_schedule).to be_nil
+ expect(group.reload.aggregation_schedule).to be_present
end
- context 'when something goes wrong when updating' do
- before do
- allow_any_instance_of(Namespaces::StatisticsRefresherService)
- .to receive(:execute)
- .and_raise(Namespaces::StatisticsRefresherService::RefresherError, 'error')
- end
-
- it 'does not delete the aggregation schedule' do
- worker.perform(group.id)
-
- expect(group.reload.aggregation_schedule).to be_present
- end
-
- it 'logs the error' do
- # A Namespace::RootStatisticsWorker is scheduled when
- # a Namespace::AggregationSchedule is created, so having
- # create(:group, :with_aggregation_schedule), will execute
- # another worker
- allow_any_instance_of(Namespace::AggregationSchedule)
- .to receive(:schedule_root_storage_statistics).and_return(nil)
+ it 'logs the error' do
+ # A Namespace::RootStatisticsWorker is scheduled when
+ # a Namespace::AggregationSchedule is created, so having
+ # create(:group, :with_aggregation_schedule), will execute
+ # another worker
+ allow_any_instance_of(Namespace::AggregationSchedule)
+ .to receive(:schedule_root_storage_statistics).and_return(nil)
- expect(Gitlab::ErrorTracking).to receive(:track_exception).once
+ expect(Gitlab::ErrorTracking).to receive(:track_exception).once
- worker.perform(group.id)
- end
+ worker.perform(group.id)
end
end
end
@@ -107,42 +67,22 @@ RSpec.describe Namespaces::RootStatisticsWorker, '#perform', feature_category: :
group.aggregation_schedule.destroy!
end
- context 'with remove_aggregation_schedule_lease feature flag disabled' do
- before do
- stub_feature_flags(remove_aggregation_schedule_lease: false)
- end
-
- it 'does not execute the refresher service' do
- expect_any_instance_of(Namespaces::StatisticsRefresherService)
- .not_to receive(:execute)
-
- worker.perform(group.id)
- end
- end
+ it 'does not execute the refresher service' do
+ expect_any_instance_of(Namespaces::StatisticsRefresherService)
+ .not_to receive(:execute)
- context 'with remove_aggregation_schedule_lease feature flag enabled' do
- it_behaves_like 'bypasses aggregation schedule'
+ worker.perform(group.id)
end
end
it_behaves_like 'an idempotent worker' do
let(:job_args) { [group.id] }
- context 'with remove_aggregation_schedule_lease feature flag disabled' do
- before do
- stub_feature_flags(remove_aggregation_schedule_lease: false)
- end
-
- it 'deletes one aggregation schedule' do
- # Make sure the group and it's aggregation schedule are created before
- # counting
- group
-
- expect { worker.perform(*job_args) }
- .to change { Namespace::AggregationSchedule.count }.by(-1)
- expect { worker.perform(*job_args) }
- .not_to change { Namespace::AggregationSchedule.count }
- end
+ it 'deletes one aggregation schedule' do
+ expect { worker.perform(*job_args) }
+ .to change { Namespace::AggregationSchedule.count }.by(-1)
+ expect { worker.perform(*job_args) }
+ .not_to change { Namespace::AggregationSchedule.count }
end
end
diff --git a/spec/workers/namespaces/schedule_aggregation_worker_spec.rb b/spec/workers/namespaces/schedule_aggregation_worker_spec.rb
index 249c143606f..7d0746a4bb0 100644
--- a/spec/workers/namespaces/schedule_aggregation_worker_spec.rb
+++ b/spec/workers/namespaces/schedule_aggregation_worker_spec.rb
@@ -7,64 +7,28 @@ RSpec.describe Namespaces::ScheduleAggregationWorker, '#perform', :clean_gitlab_
subject(:worker) { described_class.new }
- RSpec.shared_examples 'schedule root statistic worker' do
- it 'enqueues only RootStatisticsWorker' do
- expect(Namespaces::RootStatisticsWorker).to receive(:perform_async).with(group.root_ancestor.id)
- expect(Namespace::AggregationSchedule).not_to receive(:safe_find_or_create_by!)
- .with(namespace_id: group.root_ancestor.id)
-
- worker.perform(group.id)
- end
-
- it 'does not change AggregationSchedule count' do
- expect do
- worker.perform(group.root_ancestor.id)
- end.not_to change { Namespace::AggregationSchedule.count }
- end
- end
-
context 'when group is the root ancestor' do
- context 'with remove_aggregation_schedule_lease feature flag enabled' do
- context 'when aggregation schedule does not exist' do
- it_behaves_like "schedule root statistic worker"
- end
+ context 'when aggregation schedule exists' do
+ it 'does not create a new one' do
+ stub_aggregation_schedule_statistics
- context 'when aggregation schedule does exist' do
- before do
- Namespace::AggregationSchedule.safe_find_or_create_by!(namespace_id: group.id)
- end
+ Namespace::AggregationSchedule.safe_find_or_create_by!(namespace_id: group.id)
- it_behaves_like "schedule root statistic worker"
+ expect do
+ worker.perform(group.id)
+ end.not_to change { Namespace::AggregationSchedule.count }
end
end
- context 'with remove_aggregation_schedule_lease feature flag disabled' do
- before do
- stub_feature_flags(remove_aggregation_schedule_lease: false)
- end
-
- context 'when aggregation schedule exists' do
- it 'does not create a new one' do
- stub_aggregation_schedule_statistics
-
- Namespace::AggregationSchedule.safe_find_or_create_by!(namespace_id: group.id)
-
- expect do
- worker.perform(group.id)
- end.not_to change { Namespace::AggregationSchedule.count }
- end
- end
-
- context 'when aggregation schedule does not exist' do
- it 'creates one' do
- stub_aggregation_schedule_statistics
+ context 'when aggregation schedule does not exist' do
+ it 'creates one' do
+ stub_aggregation_schedule_statistics
- expect do
- worker.perform(group.id)
- end.to change { Namespace::AggregationSchedule.count }.by(1)
+ expect do
+ worker.perform(group.id)
+ end.to change { Namespace::AggregationSchedule.count }.by(1)
- expect(group.aggregation_schedule).to be_present
- end
+ expect(group.aggregation_schedule).to be_present
end
end
end
@@ -73,22 +37,12 @@ RSpec.describe Namespaces::ScheduleAggregationWorker, '#perform', :clean_gitlab_
let(:parent_group) { create(:group) }
let(:group) { create(:group, parent: parent_group) }
- context 'with remove_aggregation_schedule_lease feature flag enabled' do
- it_behaves_like "schedule root statistic worker"
- end
+ it 'creates an aggregation schedule for the root' do
+ stub_aggregation_schedule_statistics
- context 'with remove_aggregation_schedule_lease feature flag disabled' do
- before do
- stub_feature_flags(remove_aggregation_schedule_lease: false)
- end
-
- it 'creates an aggregation schedule for the root' do
- stub_aggregation_schedule_statistics
-
- worker.perform(group.id)
+ worker.perform(group.id)
- expect(parent_group.aggregation_schedule).to be_present
- end
+ expect(parent_group.aggregation_schedule).to be_present
end
end
@@ -103,17 +57,11 @@ RSpec.describe Namespaces::ScheduleAggregationWorker, '#perform', :clean_gitlab_
it_behaves_like 'an idempotent worker' do
let(:job_args) { [group.id] }
- context 'with remove_aggregation_schedule_lease feature flag disabled' do
- before do
- stub_feature_flags(remove_aggregation_schedule_lease: false)
- end
-
- it 'creates a single aggregation schedule' do
- expect { worker.perform(*job_args) }
- .to change { Namespace::AggregationSchedule.count }.by(1)
- expect { worker.perform(*job_args) }
- .not_to change { Namespace::AggregationSchedule.count }
- end
+ it 'creates a single aggregation schedule' do
+ expect { worker.perform(*job_args) }
+ .to change { Namespace::AggregationSchedule.count }.by(1)
+ expect { worker.perform(*job_args) }
+ .not_to change { Namespace::AggregationSchedule.count }
end
end