diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-10-20 11:43:02 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-10-20 11:43:02 +0300 |
commit | d9ab72d6080f594d0b3cae15f14b3ef2c6c638cb (patch) | |
tree | 2341ef426af70ad1e289c38036737e04b0aa5007 /spec/support/shared_examples/lib/gitlab | |
parent | d6e514dd13db8947884cd58fe2a9c2a063400a9b (diff) |
Add latest changes from gitlab-org/gitlab@14-4-stable-eev14.4.0-rc42
Diffstat (limited to 'spec/support/shared_examples/lib/gitlab')
3 files changed, 86 insertions, 11 deletions
diff --git a/spec/support/shared_examples/lib/gitlab/ci/ci_trace_shared_examples.rb b/spec/support/shared_examples/lib/gitlab/ci/ci_trace_shared_examples.rb index 3760325675a..8b4ecd7d5ae 100644 --- a/spec/support/shared_examples/lib/gitlab/ci/ci_trace_shared_examples.rb +++ b/spec/support/shared_examples/lib/gitlab/ci/ci_trace_shared_examples.rb @@ -35,8 +35,8 @@ RSpec.shared_examples 'common trace features' do stub_feature_flags(gitlab_ci_archived_trace_consistent_reads: trace.job.project) end - it 'calls ::Gitlab::Database::LoadBalancing::Sticking.unstick_or_continue_sticking' do - expect(::Gitlab::Database::LoadBalancing::Sticking).to receive(:unstick_or_continue_sticking) + it 'calls ::ApplicationRecord.sticking.unstick_or_continue_sticking' do + expect(::ApplicationRecord.sticking).to receive(:unstick_or_continue_sticking) .with(described_class::LOAD_BALANCING_STICKING_NAMESPACE, trace.job.id) .and_call_original @@ -49,8 +49,8 @@ RSpec.shared_examples 'common trace features' do stub_feature_flags(gitlab_ci_archived_trace_consistent_reads: false) end - it 'does not call ::Gitlab::Database::LoadBalancing::Sticking.unstick_or_continue_sticking' do - expect(::Gitlab::Database::LoadBalancing::Sticking).not_to receive(:unstick_or_continue_sticking) + it 'does not call ::ApplicationRecord.sticking.unstick_or_continue_sticking' do + expect(::ApplicationRecord.sticking).not_to receive(:unstick_or_continue_sticking) trace.read { |stream| stream } end @@ -305,8 +305,8 @@ RSpec.shared_examples 'common trace features' do stub_feature_flags(gitlab_ci_archived_trace_consistent_reads: trace.job.project) end - it 'calls ::Gitlab::Database::LoadBalancing::Sticking.stick' do - expect(::Gitlab::Database::LoadBalancing::Sticking).to receive(:stick) + it 'calls ::ApplicationRecord.sticking.stick' do + expect(::ApplicationRecord.sticking).to receive(:stick) .with(described_class::LOAD_BALANCING_STICKING_NAMESPACE, trace.job.id) .and_call_original @@ -319,8 +319,8 @@ RSpec.shared_examples 'common trace features' do stub_feature_flags(gitlab_ci_archived_trace_consistent_reads: false) end - it 'does not call ::Gitlab::Database::LoadBalancing::Sticking.stick' do - expect(::Gitlab::Database::LoadBalancing::Sticking).not_to receive(:stick) + it 'does not call ::ApplicationRecord.sticking.stick' do + expect(::ApplicationRecord.sticking).not_to receive(:stick) subject end @@ -497,7 +497,7 @@ RSpec.shared_examples 'trace with disabled live trace feature' do expect(build.job_artifacts_trace.file.filename).to eq('job.log') expect(File.exist?(src_path)).to be_falsy expect(src_checksum) - .to eq(described_class.hexdigest(build.job_artifacts_trace.file.path)) + .to eq(described_class.sha256_hexdigest(build.job_artifacts_trace.file.path)) expect(build.job_artifacts_trace.file_sha256).to eq(src_checksum) end end @@ -523,7 +523,7 @@ RSpec.shared_examples 'trace with disabled live trace feature' do expect(build.job_artifacts_trace.file.filename).to eq('job.log') expect(build.old_trace).to be_nil expect(src_checksum) - .to eq(described_class.hexdigest(build.job_artifacts_trace.file.path)) + .to eq(described_class.sha256_hexdigest(build.job_artifacts_trace.file.path)) expect(build.job_artifacts_trace.file_sha256).to eq(src_checksum) end end @@ -861,7 +861,7 @@ RSpec.shared_examples 'trace with enabled live trace feature' do expect(build.job_artifacts_trace.file.filename).to eq('job.log') expect(Ci::BuildTraceChunk.where(build: build)).not_to be_exist expect(src_checksum) - .to eq(described_class.hexdigest(build.job_artifacts_trace.file.path)) + .to eq(described_class.sha256_hexdigest(build.job_artifacts_trace.file.path)) expect(build.job_artifacts_trace.file_sha256).to eq(src_checksum) end end diff --git a/spec/support/shared_examples/lib/gitlab/cycle_analytics/event_shared_examples.rb b/spec/support/shared_examples/lib/gitlab/cycle_analytics/event_shared_examples.rb index 6e12b5a0e85..bd8bdd70ce5 100644 --- a/spec/support/shared_examples/lib/gitlab/cycle_analytics/event_shared_examples.rb +++ b/spec/support/shared_examples/lib/gitlab/cycle_analytics/event_shared_examples.rb @@ -33,3 +33,38 @@ RSpec.shared_examples_for 'value stream analytics event' do end end end + +RSpec.shared_examples_for 'LEFT JOIN-able value stream analytics event' do + let(:params) { {} } + let(:instance) { described_class.new(params) } + let(:record_with_data) { nil } + let(:record_without_data) { nil } + let(:scope) { instance.object_type.all } + + let(:records) do + scope_with_left_join = instance.include_in(scope) + scope_with_left_join.select(scope.model.arel_table[:id], instance.timestamp_projection.as('timestamp_column_data')).to_a + end + + it 'can use the event as LEFT JOIN' do + expected_record_count = record_without_data.nil? ? 1 : 2 + + expect(records.count).to eq(expected_record_count) + end + + context 'when looking at the record with data' do + subject(:record) { records.to_a.find { |r| r.id == record_with_data.id } } + + it 'contains the timestamp expression' do + expect(record.timestamp_column_data).not_to eq(nil) + end + end + + context 'when looking at the record without data' do + subject(:record) { records.to_a.find { |r| r.id == record_without_data.id } } + + it 'returns nil for the timestamp expression' do + expect(record.timestamp_column_data).to eq(nil) if record_without_data + end + end +end diff --git a/spec/support/shared_examples/lib/gitlab/import_export/attributes_permitter_shared_examples.rb b/spec/support/shared_examples/lib/gitlab/import_export/attributes_permitter_shared_examples.rb new file mode 100644 index 00000000000..5ce698c4701 --- /dev/null +++ b/spec/support/shared_examples/lib/gitlab/import_export/attributes_permitter_shared_examples.rb @@ -0,0 +1,40 @@ +# frozen_string_literal: true +RSpec.shared_examples 'a permitted attribute' do |relation_sym, permitted_attributes| + let(:prohibited_attributes) { %i[remote_url my_attributes my_ids token my_id test] } + + let(:import_export_config) { Gitlab::ImportExport::Config.new.to_h } + let(:project_relation_factory) { Gitlab::ImportExport::Project::RelationFactory } + + let(:relation_hash) { (permitted_attributes + prohibited_attributes).map(&:to_s).zip([]).to_h } + let(:relation_name) { project_relation_factory.overrides[relation_sym]&.to_sym || relation_sym } + let(:relation_class) { project_relation_factory.relation_class(relation_name) } + let(:excluded_keys) { import_export_config.dig(:excluded_keys, relation_sym) || [] } + + let(:cleaned_hash) do + Gitlab::ImportExport::AttributeCleaner.new( + relation_hash: relation_hash, + relation_class: relation_class, + excluded_keys: excluded_keys + ).clean + end + + let(:permitted_hash) { subject.permit(relation_sym, relation_hash) } + + if described_class.new.permitted_attributes_defined?(relation_sym) + it 'contains only attributes that are defined as permitted in the import/export config' do + expect(permitted_hash.keys).to contain_exactly(*permitted_attributes.map(&:to_s)) + end + + it 'does not contain attributes that would be cleaned with AttributeCleaner' do + expect(cleaned_hash.keys).to include(*permitted_hash.keys) + end + + it 'does not contain prohibited attributes that are not related to given relation' do + expect(permitted_hash.keys).not_to include(*prohibited_attributes.map(&:to_s)) + end + else + it 'is disabled' do + expect(subject).not_to be_permitted_attributes_defined(relation_sym) + end + end +end |