From edaa33dee2ff2f7ea3fac488d41558eb5f86d68c Mon Sep 17 00:00:00 2001 From: GitLab Bot Date: Thu, 20 Jan 2022 09:16:11 +0000 Subject: Add latest changes from gitlab-org/gitlab@14-7-stable-ee --- spec/tooling/danger/datateam_spec.rb | 113 +++++++++++++++++++++++++ spec/tooling/danger/project_helper_spec.rb | 2 +- spec/tooling/docs/deprecation_handling_spec.rb | 40 +++++++++ 3 files changed, 154 insertions(+), 1 deletion(-) create mode 100644 spec/tooling/danger/datateam_spec.rb create mode 100644 spec/tooling/docs/deprecation_handling_spec.rb (limited to 'spec/tooling') diff --git a/spec/tooling/danger/datateam_spec.rb b/spec/tooling/danger/datateam_spec.rb new file mode 100644 index 00000000000..3bcef3ac886 --- /dev/null +++ b/spec/tooling/danger/datateam_spec.rb @@ -0,0 +1,113 @@ +# frozen_string_literal: true + +require 'rspec-parameterized' +require 'gitlab-dangerfiles' +require 'gitlab/dangerfiles/spec_helper' +require 'pry' +require_relative '../../../tooling/danger/datateam' + +RSpec.describe Tooling::Danger::Datateam do + include_context "with dangerfile" + + let(:fake_danger) { DangerSpecHelper.fake_danger.include(described_class) } + let(:datateam) { fake_danger.new(helper: fake_helper) } + + describe 'data team danger' do + using RSpec::Parameterized::TableSyntax + + where do + { + 'with structure.sql changes and no Data Warehouse::Impact Check label' => { + modified_files: %w(db/structure.sql app/models/user.rb), + changed_lines: ['+group_id bigint NOT NULL'], + mr_labels: [], + impacted: true, + impacted_files: %w(db/structure.sql) + }, + 'with structure.sql changes and Data Warehouse::Impact Check label' => { + modified_files: %w(db/structure.sql), + changed_lines: ['+group_id bigint NOT NULL)'], + mr_labels: ['Data Warehouse::Impact Check'], + impacted: false, + impacted_files: %w(db/structure.sql) + }, + 'with user model changes' => { + modified_files: %w(app/models/users.rb), + changed_lines: ['+has_one :namespace'], + mr_labels: [], + impacted: false, + impacted_files: [] + }, + 'with perfomance indicator changes and no Data Warehouse::Impact Check label' => { + modified_files: %w(config/metrics/20210216182127_user_secret_detection_jobs.yml app/models/user.rb), + changed_lines: ['+-gmau'], + mr_labels: [], + impacted: true, + impacted_files: %w(config/metrics/20210216182127_user_secret_detection_jobs.yml) + }, + 'with perfomance indicator changes and Data Warehouse::Impact Check label' => { + modified_files: %w(config/metrics/20210216182127_user_secret_detection_jobs.yml), + changed_lines: ['+-gmau'], + mr_labels: ['Data Warehouse::Impact Check'], + impacted: false, + impacted_files: %w(config/metrics/20210216182127_user_secret_detection_jobs.yml) + }, + 'with metric file changes and no performance indicator changes' => { + modified_files: %w(config/metrics/20210216182127_user_secret_detection_jobs.yml), + changed_lines: ['-product_stage: growth'], + mr_labels: [], + impacted: false, + impacted_files: [] + }, + 'with metric file changes and no performance indicator changes and other label' => { + modified_files: %w(config/metrics/20210216182127_user_secret_detection_jobs.yml), + changed_lines: ['-product_stage: growth'], + mr_labels: ['type::tooling'], + impacted: false, + impacted_files: [] + }, + 'with performance indicator changes and other label' => { + modified_files: %w(config/metrics/20210216182127_user_secret_detection_jobs.yml app/models/user.rb), + changed_lines: ['+-gmau'], + mr_labels: ['type::tooling'], + impacted: true, + impacted_files: %w(config/metrics/20210216182127_user_secret_detection_jobs.yml) + }, + 'with performance indicator changes, Data Warehouse::Impact Check and other label' => { + modified_files: %w(config/metrics/20210216182127_user_secret_detection_jobs.yml app/models/user.rb), + changed_lines: ['+-gmau'], + mr_labels: ['type::tooling', 'Data Warehouse::Impact Check'], + impacted: false, + impacted_files: %w(config/metrics/20210216182127_user_secret_detection_jobs.yml) + }, + 'with performance indicator changes and other labels' => { + modified_files: %w(config/metrics/20210216182127_user_secret_detection_jobs.yml app/models/user.rb), + changed_lines: ['+-gmau'], + mr_labels: ['type::tooling', 'Data Warehouse::Impacted'], + impacted: false, + impacted_files: %w(config/metrics/20210216182127_user_secret_detection_jobs.yml) + } + } + end + + with_them do + before do + allow(fake_helper).to receive(:modified_files).and_return(modified_files) + allow(fake_helper).to receive(:changed_lines).and_return(changed_lines) + allow(fake_helper).to receive(:mr_labels).and_return(mr_labels) + allow(fake_helper).to receive(:markdown_list).with(impacted_files).and_return(impacted_files.map { |item| "* `#{item}`" }.join("\n")) + end + + it :aggregate_failures do + expect(datateam.impacted?).to be(impacted) + expect(datateam.build_message).to match_expected_message + end + end + end + + def match_expected_message + return be_nil unless impacted + + start_with(described_class::CHANGED_SCHEMA_MESSAGE).and(include(*impacted_files)) + end +end diff --git a/spec/tooling/danger/project_helper_spec.rb b/spec/tooling/danger/project_helper_spec.rb index f13083bdf0a..52aa90beb2b 100644 --- a/spec/tooling/danger/project_helper_spec.rb +++ b/spec/tooling/danger/project_helper_spec.rb @@ -269,7 +269,7 @@ RSpec.describe Tooling::Danger::ProjectHelper do describe '.local_warning_message' do it 'returns an informational message with rules that can run' do - expect(described_class.local_warning_message).to eq('==> Only the following Danger rules can be run locally: changelog, ci_config, database, documentation, duplicate_yarn_dependencies, eslint, gitaly, pajamas, pipeline, prettier, product_intelligence, utility_css, vue_shared_documentation') + expect(described_class.local_warning_message).to eq('==> Only the following Danger rules can be run locally: changelog, ci_config, database, documentation, duplicate_yarn_dependencies, eslint, gitaly, pajamas, pipeline, prettier, product_intelligence, utility_css, vue_shared_documentation, datateam') end end diff --git a/spec/tooling/docs/deprecation_handling_spec.rb b/spec/tooling/docs/deprecation_handling_spec.rb new file mode 100644 index 00000000000..e389fe882b2 --- /dev/null +++ b/spec/tooling/docs/deprecation_handling_spec.rb @@ -0,0 +1,40 @@ +# frozen_string_literal: true + +require_relative '../../fast_spec_helper' +require_relative '../../../tooling/docs/deprecation_handling' +require_relative '../../support/helpers/next_instance_of' + +RSpec.describe Docs::DeprecationHandling do + include ::NextInstanceOf + + let(:type) { 'deprecation' } + + subject { described_class.new(type).render } + + before do + allow(Rake::FileList).to receive(:new).and_return( + ['14-10-c.yml', '14-2-b.yml', '14-2-a.yml'] + ) + # Create dummy YAML data based on file name + allow(YAML).to receive(:load_file) do |file_name| + { + 'name' => file_name[/[a-z]*\.yml/], + 'announcement_milestone' => file_name[/\d+-\d+/].tr('-', '.') + } + end + end + + it 'sorts entries and milestones' do + allow_next_instance_of(ERB) do |template| + expect(template).to receive(:result_with_hash) do |arguments| + milestones = arguments[:milestones] + entries = arguments[:entries] + + expect(milestones).to eq(['14.2', '14.10']) + expect(entries.map { |e| e['name'] }).to eq(['a.yml', 'b.yml', 'c.yml']) + end + end + + subject + end +end -- cgit v1.2.3