diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-06-20 14:10:13 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-06-20 14:10:13 +0300 |
commit | 0ea3fcec397b69815975647f5e2aa5fe944a8486 (patch) | |
tree | 7979381b89d26011bcf9bdc989a40fcc2f1ed4ff /spec/tooling | |
parent | 72123183a20411a36d607d70b12d57c484394c8e (diff) |
Add latest changes from gitlab-org/gitlab@15-1-stable-eev15.1.0-rc42
Diffstat (limited to 'spec/tooling')
-rw-r--r-- | spec/tooling/danger/datateam_spec.rb | 14 | ||||
-rw-r--r-- | spec/tooling/danger/project_helper_spec.rb | 10 | ||||
-rw-r--r-- | spec/tooling/lib/tooling/find_codeowners_spec.rb | 107 | ||||
-rw-r--r-- | spec/tooling/lib/tooling/test_map_generator_spec.rb | 14 | ||||
-rw-r--r-- | spec/tooling/quality/test_level_spec.rb | 43 |
5 files changed, 117 insertions, 71 deletions
diff --git a/spec/tooling/danger/datateam_spec.rb b/spec/tooling/danger/datateam_spec.rb index e6698dd8970..e4ab3a6f4b1 100644 --- a/spec/tooling/danger/datateam_spec.rb +++ b/spec/tooling/danger/datateam_spec.rb @@ -86,6 +86,20 @@ RSpec.describe Tooling::Danger::Datateam do mr_labels: ['type::maintenance', 'Data Warehouse::Impacted'], impacted: false, impacted_files: %w(config/metrics/20210216182127_user_secret_detection_jobs.yml) + }, + 'with metric status removed' => { + modified_files: %w(config/metrics/20210216182127_user_secret_detection_jobs.yml app/models/user.rb), + changed_lines: ['+status: removed'], + mr_labels: ['type::maintenance'], + impacted: true, + impacted_files: %w(config/metrics/20210216182127_user_secret_detection_jobs.yml) + }, + 'with metric status active' => { + modified_files: %w(config/metrics/20210216182127_user_secret_detection_jobs.yml app/models/user.rb), + changed_lines: ['+status: active'], + mr_labels: ['type::maintenance'], + impacted: false, + impacted_files: %w(config/metrics/20210216182127_user_secret_detection_jobs.yml) } } end diff --git a/spec/tooling/danger/project_helper_spec.rb b/spec/tooling/danger/project_helper_spec.rb index 78e9c8e9c62..f48ca5b8f8c 100644 --- a/spec/tooling/danger/project_helper_spec.rb +++ b/spec/tooling/danger/project_helper_spec.rb @@ -101,14 +101,15 @@ RSpec.describe Tooling::Danger::ProjectHelper do 'Rakefile' | [:backend] 'FOO_VERSION' | [:backend] - 'lib/scripts/bar.rb' | [:backend, :tooling] - 'lib/scripts/bar.js' | [:frontend, :tooling] + 'scripts/glfm/bar.rb' | [:backend] + 'scripts/glfm/bar.js' | [:frontend] + 'scripts/lib/glfm/bar.rb' | [:backend] + 'scripts/lib/glfm/bar.js' | [:frontend] 'scripts/bar.rb' | [:backend, :tooling] 'scripts/bar.js' | [:frontend, :tooling] - 'lib/scripts/subdir/bar.rb' | [:backend, :tooling] - 'lib/scripts/subdir/bar.js' | [:frontend, :tooling] 'scripts/subdir/bar.rb' | [:backend, :tooling] 'scripts/subdir/bar.js' | [:frontend, :tooling] + 'scripts/foo' | [:tooling] 'Dangerfile' | [:tooling] 'danger/bundle_size/Dangerfile' | [:tooling] @@ -118,7 +119,6 @@ RSpec.describe Tooling::Danger::ProjectHelper do '.gitlab-ci.yml' | [:tooling] '.gitlab/ci/cng.gitlab-ci.yml' | [:tooling] '.gitlab/ci/ee-specific-checks.gitlab-ci.yml' | [:tooling] - 'scripts/foo' | [:tooling] 'tooling/danger/foo' | [:tooling] 'ee/tooling/danger/foo' | [:tooling] 'lefthook.yml' | [:tooling] diff --git a/spec/tooling/lib/tooling/find_codeowners_spec.rb b/spec/tooling/lib/tooling/find_codeowners_spec.rb index b29c5f35ec9..10c2a076847 100644 --- a/spec/tooling/lib/tooling/find_codeowners_spec.rb +++ b/spec/tooling/lib/tooling/find_codeowners_spec.rb @@ -31,13 +31,37 @@ RSpec.describe Tooling::FindCodeowners do end end.to output(<<~CODEOWNERS).to_stdout [Section name] - /dir0/dir1 @group + /dir0/dir1/ @group /file @group CODEOWNERS end end describe '#load_definitions' do + before do + allow(subject).to receive(:load_config).and_return( + { + '[Authentication and Authorization]': { + '@gitlab-org/manage/authentication-and-authorization': { + allow: { + keywords: %w[password auth token], + patterns: + %w[ + /{,ee/}app/**/*%{keyword}*{,/**/*} + /{,ee/}config/**/*%{keyword}*{,/**/*} + /{,ee/}lib/**/*%{keyword}*{,/**/*} + ] + }, + deny: { + keywords: %w[*author.* *author_* *authored*], + patterns: ['%{keyword}'] + } + } + } + } + ) + end + it 'expands the allow and deny list with keywords and patterns' do subject.load_definitions.each do |section, group_defintions| group_defintions.each do |group, definitions| @@ -54,56 +78,20 @@ RSpec.describe Tooling::FindCodeowners do expect(auth).to eq( allow: %w[ - /{,ee/}app/**/*password*{/**/*,} - /{,ee/}config/**/*password*{/**/*,} - /{,ee/}lib/**/*password*{/**/*,} - /{,ee/}app/**/*auth*{/**/*,} - /{,ee/}config/**/*auth*{/**/*,} - /{,ee/}lib/**/*auth*{/**/*,} - /{,ee/}app/**/*token*{/**/*,} - /{,ee/}config/**/*token*{/**/*,} - /{,ee/}lib/**/*token*{/**/*,} + /{,ee/}app/**/*password*{,/**/*} + /{,ee/}config/**/*password*{,/**/*} + /{,ee/}lib/**/*password*{,/**/*} + /{,ee/}app/**/*auth*{,/**/*} + /{,ee/}config/**/*auth*{,/**/*} + /{,ee/}lib/**/*auth*{,/**/*} + /{,ee/}app/**/*token*{,/**/*} + /{,ee/}config/**/*token*{,/**/*} + /{,ee/}lib/**/*token*{,/**/*} ], deny: %w[ - **/*author.*{/**/*,} - **/*author_*{/**/*,} - **/*authored*{/**/*,} - **/*authoring*{/**/*,} - **/*.png*{/**/*,} - **/*.svg*{/**/*,} - **/*deploy_token*{/**/*,} - **/*runner{,s}_token*{/**/*,} - **/*job_token*{/**/*,} - **/*autocomplete_tokens*{/**/*,} - **/*dast_site_token*{/**/*,} - **/*reset_prometheus_token*{/**/*,} - **/*reset_registration_token*{/**/*,} - **/*runners_registration_token*{/**/*,} - **/*terraform_registry_token*{/**/*,} - **/*tokenizer*{/**/*,} - **/*filtered_search*{/**/*,} - **/*/alert_management/*{/**/*,} - **/*/analytics/*{/**/*,} - **/*/bitbucket/*{/**/*,} - **/*/clusters/*{/**/*,} - **/*/clusters_list/*{/**/*,} - **/*/dast/*{/**/*,} - **/*/dast_profiles/*{/**/*,} - **/*/dast_site_tokens/*{/**/*,} - **/*/dast_site_validation/*{/**/*,} - **/*/dependency_proxy/*{/**/*,} - **/*/error_tracking/*{/**/*,} - **/*/google_api/*{/**/*,} - **/*/google_cloud/*{/**/*,} - **/*/jira_connect/*{/**/*,} - **/*/kubernetes/*{/**/*,} - **/*/protected_environments/*{/**/*,} - **/*/config/feature_flags/development/jira_connect_*{/**/*,} - **/*/config/metrics/*{/**/*,} - **/*/app/controllers/groups/dependency_proxy_auth_controller.rb*{/**/*,} - **/*/app/finders/ci/auth_job_finder.rb*{/**/*,} - **/*/ee/config/metrics/*{/**/*,} - **/*/lib/gitlab/conan_token.rb*{/**/*,} + *author.* + *author_* + *authored* ] ) end @@ -159,12 +147,31 @@ RSpec.describe Tooling::FindCodeowners do expected_flags = ::File::FNM_DOTMATCH | ::File::FNM_PATHNAME | ::File::FNM_EXTGLOB - expect(File).to receive(:fnmatch?).with(pattern, path, expected_flags) + expect(File).to receive(:fnmatch?) + .with("/**/#{pattern}", path, expected_flags) subject.path_matches?(pattern, path) end end + describe '#normalize_pattern' do + it 'returns /**/* if the input is *' do + expect(subject.normalize_pattern('*')).to eq('/**/*') + end + + it 'prepends /** if the input does not start with /' do + expect(subject.normalize_pattern('app')).to eq('/**/app') + end + + it 'returns the pattern if the input starts with /' do + expect(subject.normalize_pattern('/app')).to eq('/app') + end + + it 'appends **/* if the input ends with /' do + expect(subject.normalize_pattern('/app/')).to eq('/app/**/*') + end + end + describe '#consolidate_paths' do before do allow(subject).to receive(:find_dir_maxdepth_1).and_return(<<~LINES) diff --git a/spec/tooling/lib/tooling/test_map_generator_spec.rb b/spec/tooling/lib/tooling/test_map_generator_spec.rb index b52d78b01a3..1b369923d8d 100644 --- a/spec/tooling/lib/tooling/test_map_generator_spec.rb +++ b/spec/tooling/lib/tooling/test_map_generator_spec.rb @@ -17,7 +17,7 @@ RSpec.describe Tooling::TestMapGenerator do :timestamp: 1602668405 :version: --- - "./spec/factories_spec.rb[1]": + "./spec/models/factories_spec.rb[1]": - lib/gitlab/current_settings.rb - lib/feature.rb - lib/gitlab/marginalia.rb @@ -62,13 +62,13 @@ RSpec.describe Tooling::TestMapGenerator do let(:expected_mapping) do { 'lib/gitlab/current_settings.rb' => [ - 'spec/factories_spec.rb' + 'spec/models/factories_spec.rb' ], 'lib/feature.rb' => [ - 'spec/factories_spec.rb' + 'spec/models/factories_spec.rb' ], 'lib/gitlab/marginalia.rb' => [ - 'spec/factories_spec.rb' + 'spec/models/factories_spec.rb' ] } end @@ -96,15 +96,15 @@ RSpec.describe Tooling::TestMapGenerator do let(:expected_mapping) do { 'lib/gitlab/current_settings.rb' => [ - 'spec/factories_spec.rb', + 'spec/models/factories_spec.rb', 'spec/models/project_spec.rb' ], 'lib/feature.rb' => [ - 'spec/factories_spec.rb', + 'spec/models/factories_spec.rb', 'spec/models/project_spec.rb' ], 'lib/gitlab/marginalia.rb' => [ - 'spec/factories_spec.rb', + 'spec/models/factories_spec.rb', 'spec/models/project_spec.rb' ] } diff --git a/spec/tooling/quality/test_level_spec.rb b/spec/tooling/quality/test_level_spec.rb index 98034eb4b0a..10afcb18a73 100644 --- a/spec/tooling/quality/test_level_spec.rb +++ b/spec/tooling/quality/test_level_spec.rb @@ -1,8 +1,33 @@ # frozen_string_literal: true +require 'spec_helper' + require_relative '../../../tooling/quality/test_level' RSpec.describe Quality::TestLevel do + describe 'TEST_LEVEL_FOLDERS constant' do + it 'all directories it refers to exists', :aggregate_failures do + ee_only_directories = %w[ + lib/ee/gitlab/background_migration + elastic + elastic_integration + replicators + ] + + described_class::TEST_LEVEL_FOLDERS.values.flatten.each do |dir| + next if ee_only_directories.include?(dir) && !Gitlab.ee? + + spec_directory = if ee_only_directories.include?(dir) + File.join('ee', 'spec', dir) + else + File.join('spec', dir) + end + + expect(File.exist?(spec_directory)).to eq(true), "#{spec_directory} does not exist!" + end + end + end + describe '#pattern' do context 'when level is all' do it 'returns a pattern' do @@ -21,7 +46,7 @@ RSpec.describe Quality::TestLevel do context 'when level is unit' do it 'returns a pattern' do expect(subject.pattern(:unit)) - .to eq("spec/{bin,channels,config,db,dependencies,elastic,elastic_integration,experiments,events,factories,finders,frontend,graphql,haml_lint,helpers,initializers,javascripts,lib,metrics_server,models,policies,presenters,rack_servers,replicators,routing,rubocop,scripts,serializers,services,sidekiq,sidekiq_cluster,spam,support_specs,tasks,uploaders,validators,views,workers,tooling,component}{,/**/}*_spec.rb") + .to eq("spec/{bin,channels,config,db,dependencies,elastic,elastic_integration,experiments,events,factories,finders,frontend,graphql,haml_lint,helpers,initializers,lib,metrics_server,models,policies,presenters,rack_servers,replicators,routing,rubocop,scripts,serializers,services,sidekiq,sidekiq_cluster,spam,support_specs,tasks,uploaders,validators,views,workers,tooling,components}{,/**/}*_spec.rb") end end @@ -89,56 +114,56 @@ RSpec.describe Quality::TestLevel do context 'when level is frontend_fixture' do it 'returns a regexp' do expect(subject.regexp(:frontend_fixture)) - .to eq(%r{spec/(frontend/fixtures)}) + .to eq(%r{spec/(frontend/fixtures)/}) end end context 'when level is unit' do it 'returns a regexp' do expect(subject.regexp(:unit)) - .to eq(%r{spec/(bin|channels|config|db|dependencies|elastic|elastic_integration|experiments|events|factories|finders|frontend|graphql|haml_lint|helpers|initializers|javascripts|lib|metrics_server|models|policies|presenters|rack_servers|replicators|routing|rubocop|scripts|serializers|services|sidekiq|sidekiq_cluster|spam|support_specs|tasks|uploaders|validators|views|workers|tooling|component)}) + .to eq(%r{spec/(bin|channels|config|db|dependencies|elastic|elastic_integration|experiments|events|factories|finders|frontend|graphql|haml_lint|helpers|initializers|lib|metrics_server|models|policies|presenters|rack_servers|replicators|routing|rubocop|scripts|serializers|services|sidekiq|sidekiq_cluster|spam|support_specs|tasks|uploaders|validators|views|workers|tooling|components)/}) end end context 'when level is migration' do it 'returns a regexp' do expect(subject.regexp(:migration)) - .to eq(%r{spec/(migrations|lib/gitlab/background_migration|lib/ee/gitlab/background_migration)}) + .to eq(%r{spec/(migrations|lib/gitlab/background_migration|lib/ee/gitlab/background_migration)/}) end end context 'when level is background_migration' do it 'returns a regexp' do expect(subject.regexp(:background_migration)) - .to eq(%r{spec/(lib/gitlab/background_migration|lib/ee/gitlab/background_migration)}) + .to eq(%r{spec/(lib/gitlab/background_migration|lib/ee/gitlab/background_migration)/}) end end context 'when level is integration' do it 'returns a regexp' do expect(subject.regexp(:integration)) - .to eq(%r{spec/(commands|controllers|mailers|requests)}) + .to eq(%r{spec/(commands|controllers|mailers|requests)/}) end end context 'when level is system' do it 'returns a regexp' do expect(subject.regexp(:system)) - .to eq(%r{spec/(features)}) + .to eq(%r{spec/(features)/}) end end context 'with a prefix' do it 'returns a regexp' do expect(described_class.new('ee/').regexp(:system)) - .to eq(%r{(ee/)spec/(features)}) + .to eq(%r{(ee/)spec/(features)/}) end end context 'with several prefixes' do it 'returns a regexp' do expect(described_class.new(['', 'ee/', 'jh/']).regexp(:system)) - .to eq(%r{(|ee/|jh/)spec/(features)}) + .to eq(%r{(|ee/|jh/)spec/(features)/}) end end |