diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-08-19 12:08:42 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-08-19 12:08:42 +0300 |
commit | b76ae638462ab0f673e5915986070518dd3f9ad3 (patch) | |
tree | bdab0533383b52873be0ec0eb4d3c66598ff8b91 /spec/support/shared_examples/lib | |
parent | 434373eabe7b4be9593d18a585fb763f1e5f1a6f (diff) |
Add latest changes from gitlab-org/gitlab@14-2-stable-eev14.2.0-rc42
Diffstat (limited to 'spec/support/shared_examples/lib')
6 files changed, 167 insertions, 6 deletions
diff --git a/spec/support/shared_examples/lib/gitlab/ci/reports/security/locations/locations_shared_examples.rb b/spec/support/shared_examples/lib/gitlab/ci/reports/security/locations/locations_shared_examples.rb new file mode 100644 index 00000000000..3aa04a77e57 --- /dev/null +++ b/spec/support/shared_examples/lib/gitlab/ci/reports/security/locations/locations_shared_examples.rb @@ -0,0 +1,68 @@ +# frozen_string_literal: true + +RSpec.shared_examples 'vulnerability location' do + describe '#initialize' do + subject { described_class.new(**params) } + + context 'when all params are given' do + it 'initializes an instance' do + expect { subject }.not_to raise_error + + expect(subject).to have_attributes(**params) + end + end + + where(:param) do + mandatory_params + end + + with_them do + context "when param #{params[:param]} is missing" do + before do + params.delete(param) + end + + it 'raises an error' do + expect { subject }.to raise_error(ArgumentError) + end + end + end + end + + describe '#fingerprint' do + subject { described_class.new(**params).fingerprint } + + it "generates expected fingerprint" do + expect(subject).to eq(expected_fingerprint) + end + end + + describe '#fingerprint_path' do + subject { described_class.new(**params).fingerprint_path } + + it "generates expected fingerprint" do + expect(subject).to eq(expected_fingerprint_path) + end + end + + describe '#==' do + let(:location_1) { create(:ci_reports_security_locations_sast) } + let(:location_2) { create(:ci_reports_security_locations_sast) } + + subject { location_1 == location_2 } + + it "returns true when fingerprints are equal" do + allow(location_1).to receive(:fingerprint).and_return('fingerprint') + allow(location_2).to receive(:fingerprint).and_return('fingerprint') + + expect(subject).to eq(true) + end + + it "returns false when fingerprints are different" do + allow(location_1).to receive(:fingerprint).and_return('fingerprint') + allow(location_2).to receive(:fingerprint).and_return('another_fingerprint') + + expect(subject).to eq(false) + end + end +end diff --git a/spec/support/shared_examples/lib/gitlab/database/background_migration_job_shared_examples.rb b/spec/support/shared_examples/lib/gitlab/database/background_migration_job_shared_examples.rb index 20f3270526e..7888ade56eb 100644 --- a/spec/support/shared_examples/lib/gitlab/database/background_migration_job_shared_examples.rb +++ b/spec/support/shared_examples/lib/gitlab/database/background_migration_job_shared_examples.rb @@ -21,3 +21,46 @@ RSpec.shared_examples 'marks background migration job records' do expect(jobs_updated).to eq(1) end end + +RSpec.shared_examples 'finalized background migration' do + it 'processed the scheduled sidekiq queue' do + queued = Sidekiq::ScheduledSet + .new + .select do |scheduled| + scheduled.klass == 'BackgroundMigrationWorker' && + scheduled.args.first == job_class_name + end + expect(queued.size).to eq(0) + end + + it 'processed the async sidekiq queue' do + queued = Sidekiq::Queue.new('BackgroundMigrationWorker') + .select { |scheduled| scheduled.klass == job_class_name } + expect(queued.size).to eq(0) + end + + include_examples 'removed tracked jobs', 'pending' +end + +RSpec.shared_examples 'finalized tracked background migration' do + include_examples 'finalized background migration' + include_examples 'removed tracked jobs', 'succeeded' +end + +RSpec.shared_examples 'removed tracked jobs' do |status| + it "removes '#{status}' tracked jobs" do + jobs = Gitlab::Database::BackgroundMigrationJob + .where(status: Gitlab::Database::BackgroundMigrationJob.statuses[status]) + .for_migration_class(job_class_name) + expect(jobs).to be_empty + end +end + +RSpec.shared_examples 'retained tracked jobs' do |status| + it "retains '#{status}' tracked jobs" do + jobs = Gitlab::Database::BackgroundMigrationJob + .where(status: Gitlab::Database::BackgroundMigrationJob.statuses[status]) + .for_migration_class(job_class_name) + expect(jobs).to be_present + end +end diff --git a/spec/support/shared_examples/lib/gitlab/database/cte_materialized_shared_examples.rb b/spec/support/shared_examples/lib/gitlab/database/cte_materialized_shared_examples.rb index 88e6ffd15a8..a617342ff8c 100644 --- a/spec/support/shared_examples/lib/gitlab/database/cte_materialized_shared_examples.rb +++ b/spec/support/shared_examples/lib/gitlab/database/cte_materialized_shared_examples.rb @@ -11,7 +11,7 @@ RSpec.shared_examples 'CTE with MATERIALIZED keyword examples' do context 'when PG version is <12' do it 'does not add MATERIALIZE keyword' do - allow(Gitlab::Database).to receive(:version).and_return('11.1') + allow(Gitlab::Database.main).to receive(:version).and_return('11.1') expect(query).to include(expected_query_block_without_materialized) end @@ -19,14 +19,14 @@ RSpec.shared_examples 'CTE with MATERIALIZED keyword examples' do context 'when PG version is >=12' do it 'adds MATERIALIZE keyword' do - allow(Gitlab::Database).to receive(:version).and_return('12.1') + allow(Gitlab::Database.main).to receive(:version).and_return('12.1') expect(query).to include(expected_query_block_with_materialized) end context 'when version is higher than 12' do it 'adds MATERIALIZE keyword' do - allow(Gitlab::Database).to receive(:version).and_return('15.1') + allow(Gitlab::Database.main).to receive(:version).and_return('15.1') expect(query).to include(expected_query_block_with_materialized) end diff --git a/spec/support/shared_examples/lib/gitlab/migration_helpers_shared_examples.rb b/spec/support/shared_examples/lib/gitlab/migration_helpers_shared_examples.rb index 72d672fd36c..69a1f7ad11e 100644 --- a/spec/support/shared_examples/lib/gitlab/migration_helpers_shared_examples.rb +++ b/spec/support/shared_examples/lib/gitlab/migration_helpers_shared_examples.rb @@ -14,10 +14,10 @@ RSpec.shared_examples 'performs validation' do |validation_option| it 'performs validation' do expect(model).to receive(:disable_statement_timeout).and_call_original expect(model).to receive(:statement_timeout_disabled?).and_return(false) - expect(model).to receive(:execute).with(/statement_timeout/) + expect(model).to receive(:execute).with(/SET statement_timeout TO/) expect(model).to receive(:execute).ordered.with(/NOT VALID/) expect(model).to receive(:execute).ordered.with(/VALIDATE CONSTRAINT/) - expect(model).to receive(:execute).ordered.with(/RESET ALL/) + expect(model).to receive(:execute).ordered.with(/RESET statement_timeout/) model.add_concurrent_foreign_key(*args, **options.merge(validation_option)) end diff --git a/spec/support/shared_examples/lib/gitlab/sql/set_operator_shared_examples.rb b/spec/support/shared_examples/lib/gitlab/sql/set_operator_shared_examples.rb index 8d758ed1655..ead8b174d46 100644 --- a/spec/support/shared_examples/lib/gitlab/sql/set_operator_shared_examples.rb +++ b/spec/support/shared_examples/lib/gitlab/sql/set_operator_shared_examples.rb @@ -22,7 +22,7 @@ RSpec.shared_examples 'SQL set operator' do |operator_keyword| end it 'skips Model.none segments' do - empty_relation = User.none + empty_relation = User.none.select(:id) set_operator = described_class.new([empty_relation, relation_1, relation_2]) expect {User.where("users.id IN (#{set_operator.to_sql})").to_a}.not_to raise_error @@ -44,6 +44,17 @@ RSpec.shared_examples 'SQL set operator' do |operator_keyword| end end + context 'when uneven select values are used' do + let(:relation_1) { User.where(email: 'alice@example.com').select(*User.column_names) } + let(:relation_2) { User.where(email: 'bob@example.com') } + + it 'raises error' do + expect do + described_class.new([relation_1, relation_2]) + end.to raise_error /Relations with uneven select values were passed/ + end + end + describe 'remove_order parameter' do let(:scopes) do [ diff --git a/spec/support/shared_examples/lib/menus_shared_examples.rb b/spec/support/shared_examples/lib/menus_shared_examples.rb new file mode 100644 index 00000000000..2c2cb362b07 --- /dev/null +++ b/spec/support/shared_examples/lib/menus_shared_examples.rb @@ -0,0 +1,39 @@ +# frozen_string_literal: true + +RSpec.shared_examples_for 'pill_count formatted results' do + let(:count_service) { raise NotImplementedError } + + subject(:pill_count) { menu.pill_count } + + it 'returns all digits for count value under 1000' do + allow_next_instance_of(count_service) do |service| + allow(service).to receive(:count).and_return(999) + end + + expect(pill_count).to eq('999') + end + + it 'returns truncated digits for count value over 1000' do + allow_next_instance_of(count_service) do |service| + allow(service).to receive(:count).and_return(2300) + end + + expect(pill_count).to eq('2.3k') + end + + it 'returns truncated digits for count value over 10000' do + allow_next_instance_of(count_service) do |service| + allow(service).to receive(:count).and_return(12560) + end + + expect(pill_count).to eq('12.6k') + end + + it 'returns truncated digits for count value over 100000' do + allow_next_instance_of(count_service) do |service| + allow(service).to receive(:count).and_return(112560) + end + + expect(pill_count).to eq('112.6k') + end +end |