diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-09-20 02:18:09 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-09-20 02:18:09 +0300 |
commit | 6ed4ec3e0b1340f96b7c043ef51d1b33bbe85fde (patch) | |
tree | dc4d20fe6064752c0bd323187252c77e0a89144b /spec/tooling/danger | |
parent | 9868dae7fc0655bd7ce4a6887d4e6d487690eeed (diff) |
Add latest changes from gitlab-org/gitlab@15-4-stable-eev15.4.0-rc42
Diffstat (limited to 'spec/tooling/danger')
-rw-r--r-- | spec/tooling/danger/config_files_spec.rb | 91 | ||||
-rw-r--r-- | spec/tooling/danger/datateam_spec.rb | 2 | ||||
-rw-r--r-- | spec/tooling/danger/project_helper_spec.rb | 2 |
3 files changed, 94 insertions, 1 deletions
diff --git a/spec/tooling/danger/config_files_spec.rb b/spec/tooling/danger/config_files_spec.rb new file mode 100644 index 00000000000..0e01908a1dd --- /dev/null +++ b/spec/tooling/danger/config_files_spec.rb @@ -0,0 +1,91 @@ +# frozen_string_literal: true + +require 'gitlab-dangerfiles' +require 'danger' +require 'danger/plugins/internal/helper' +require 'gitlab/dangerfiles/spec_helper' + +require_relative '../../../tooling/danger/config_files' +require_relative '../../../tooling/danger/project_helper' + +RSpec.describe Tooling::Danger::ConfigFiles do + include_context "with dangerfile" + + let(:fake_danger) { DangerSpecHelper.fake_danger.include(described_class) } + let(:fake_project_helper) { instance_double(Tooling::Danger::ProjectHelper) } + let(:matching_line) { "+ introduced_by_url:" } + + subject(:config_file) { fake_danger.new(helper: fake_helper) } + + before do + allow(config_file).to receive(:project_helper).and_return(fake_project_helper) + end + + describe '#add_suggestion_for_missing_introduced_by_url' do + let(:file_lines) do + [ + "---", + "name: about_your_company_registration_flow", + "introduced_by_url: #{url}", + "rollout_issue_url: https://gitlab.com/gitlab-org/gitlab/-/issues/355909", + "milestone: '14.10'" + ] + end + + let(:filename) { 'config/feature_flags/new_ff.yml' } + + before do + allow(config_file.project_helper).to receive(:file_lines).and_return(file_lines) + allow(config_file.helper).to receive(:added_files).and_return([filename]) + allow(config_file.helper).to receive(:mr_web_url).and_return(url) + end + + context 'when config file has an empty introduced_by_url line' do + let(:url) { '' } + + it 'adds suggestions at the correct line' do + expected_format = format(described_class::SUGGEST_INTRODUCED_BY_COMMENT, url: url) + expect(config_file).to receive(:markdown).with(expected_format, file: filename, line: 3) + + config_file.add_suggestion_for_missing_introduced_by_url + end + end + + context 'when config file has an introduced_by_url line with value' do + let(:url) { 'https://gitlab.com/gitlab-org/gitlab/-/issues/1' } + + it 'does not add suggestion' do + expect(config_file).not_to receive(:markdown) + + config_file.add_suggestion_for_missing_introduced_by_url + end + end + end + + describe '#new_config_files' do + let(:expected_files) do + %w[ + config/feature_flags/first.yml + config/events/1234_new_event.yml + config/metrics/count_7d/new_metric.yml + ] + end + + before do + all_new_files = %w[ + app/workers/a.rb + doc/events/new_event.md + config/feature_flags/first.yml + config/events/1234_new_event.yml + config/metrics/count_7d/new_metric.yml + app/assets/index.js + ] + + allow(config_file.helper).to receive(:added_files).and_return(all_new_files) + end + + it 'returns added, modified, and renamed_after files by default' do + expect(config_file.new_config_files).to match_array(expected_files) + end + end +end diff --git a/spec/tooling/danger/datateam_spec.rb b/spec/tooling/danger/datateam_spec.rb index e4ab3a6f4b1..de8a93baa27 100644 --- a/spec/tooling/danger/datateam_spec.rb +++ b/spec/tooling/danger/datateam_spec.rb @@ -24,7 +24,7 @@ RSpec.describe Tooling::Danger::Datateam do impacted: true, impacted_files: %w(db/structure.sql) }, - 'with structure.sql changes and Data Warehouse::Impact Check label' => { + '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'], diff --git a/spec/tooling/danger/project_helper_spec.rb b/spec/tooling/danger/project_helper_spec.rb index 2f52c0fd36c..4cc5df385a5 100644 --- a/spec/tooling/danger/project_helper_spec.rb +++ b/spec/tooling/danger/project_helper_spec.rb @@ -31,6 +31,8 @@ RSpec.describe Tooling::Danger::ProjectHelper do end where(:path, :expected_categories) do + 'glfm_specification/example_snapshots/prosemirror_json.yml' | [:frontend] + 'glfm_specification/input/glfm_anything.yml' | [:frontend, :backend] 'usage_data.rb' | [:database, :backend, :product_intelligence] 'doc/foo.md' | [:docs] 'CONTRIBUTING.md' | [:docs] |