Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2022-05-19 10:33:21 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2022-05-19 10:33:21 +0300
commit36a59d088eca61b834191dacea009677a96c052f (patch)
treee4f33972dab5d8ef79e3944a9f403035fceea43f /spec/tooling
parenta1761f15ec2cae7c7f7bbda39a75494add0dfd6f (diff)
Add latest changes from gitlab-org/gitlab@15-0-stable-eev15.0.0-rc42
Diffstat (limited to 'spec/tooling')
-rw-r--r--spec/tooling/danger/project_helper_spec.rb9
-rw-r--r--spec/tooling/danger/specs_spec.rb5
-rw-r--r--spec/tooling/fixtures/find_codeowners/dir0/dir1/dir2/file20
-rw-r--r--spec/tooling/fixtures/find_codeowners/dir0/dir1/file10
-rw-r--r--spec/tooling/fixtures/find_codeowners/dir0/file00
-rw-r--r--spec/tooling/fixtures/find_codeowners/file0
-rw-r--r--spec/tooling/lib/tooling/find_codeowners_spec.rb199
-rw-r--r--spec/tooling/quality/test_level_spec.rb14
8 files changed, 211 insertions, 16 deletions
diff --git a/spec/tooling/danger/project_helper_spec.rb b/spec/tooling/danger/project_helper_spec.rb
index b3fb592c2e3..78e9c8e9c62 100644
--- a/spec/tooling/danger/project_helper_spec.rb
+++ b/spec/tooling/danger/project_helper_spec.rb
@@ -101,6 +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/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]
+
'Dangerfile' | [:tooling]
'danger/bundle_size/Dangerfile' | [:tooling]
'ee/danger/bundle_size/Dangerfile' | [:tooling]
diff --git a/spec/tooling/danger/specs_spec.rb b/spec/tooling/danger/specs_spec.rb
index b2454960a7b..6c1fbbb903d 100644
--- a/spec/tooling/danger/specs_spec.rb
+++ b/spec/tooling/danger/specs_spec.rb
@@ -118,7 +118,8 @@ RSpec.describe Tooling::Danger::Specs do
"- expect(foo).to match(['bar'])",
"- expect(foo).to match ['bar']",
"- expect(foo).to eq(['bar'])",
- "- expect(foo).to eq ['bar']"
+ "- expect(foo).to eq ['bar']",
+ "+ expect(foo).to eq([])"
] + matching_lines
end
@@ -126,7 +127,7 @@ RSpec.describe Tooling::Danger::Specs do
allow(specs.helper).to receive(:changed_lines).with(filename).and_return(changed_lines)
end
- it 'returns added, modified, and renamed_after files by default' do
+ it 'returns all lines using an array equality matcher' do
expect(specs.added_line_matching_match_with_array(filename)).to match_array(matching_lines)
end
end
diff --git a/spec/tooling/fixtures/find_codeowners/dir0/dir1/dir2/file2 b/spec/tooling/fixtures/find_codeowners/dir0/dir1/dir2/file2
new file mode 100644
index 00000000000..e69de29bb2d
--- /dev/null
+++ b/spec/tooling/fixtures/find_codeowners/dir0/dir1/dir2/file2
diff --git a/spec/tooling/fixtures/find_codeowners/dir0/dir1/file1 b/spec/tooling/fixtures/find_codeowners/dir0/dir1/file1
new file mode 100644
index 00000000000..e69de29bb2d
--- /dev/null
+++ b/spec/tooling/fixtures/find_codeowners/dir0/dir1/file1
diff --git a/spec/tooling/fixtures/find_codeowners/dir0/file0 b/spec/tooling/fixtures/find_codeowners/dir0/file0
new file mode 100644
index 00000000000..e69de29bb2d
--- /dev/null
+++ b/spec/tooling/fixtures/find_codeowners/dir0/file0
diff --git a/spec/tooling/fixtures/find_codeowners/file b/spec/tooling/fixtures/find_codeowners/file
new file mode 100644
index 00000000000..e69de29bb2d
--- /dev/null
+++ b/spec/tooling/fixtures/find_codeowners/file
diff --git a/spec/tooling/lib/tooling/find_codeowners_spec.rb b/spec/tooling/lib/tooling/find_codeowners_spec.rb
new file mode 100644
index 00000000000..b29c5f35ec9
--- /dev/null
+++ b/spec/tooling/lib/tooling/find_codeowners_spec.rb
@@ -0,0 +1,199 @@
+# frozen_string_literal: true
+
+require_relative '../../../../tooling/lib/tooling/find_codeowners'
+
+RSpec.describe Tooling::FindCodeowners do
+ let(:subject) { described_class.new }
+ let(:root) { File.expand_path('../../fixtures/find_codeowners', __dir__) }
+
+ describe '#execute' do
+ before do
+ allow(subject).to receive(:load_config).and_return(
+ '[Section name]': {
+ '@group': {
+ allow: {
+ keywords: %w[dir0 file],
+ patterns: ['/%{keyword}/**/*', '/%{keyword}']
+ },
+ deny: {
+ keywords: %w[file0],
+ patterns: ['**/%{keyword}']
+ }
+ }
+ }
+ )
+ end
+
+ it 'prints CODEOWNERS as configured' do
+ expect do
+ Dir.chdir(root) do
+ subject.execute
+ end
+ end.to output(<<~CODEOWNERS).to_stdout
+ [Section name]
+ /dir0/dir1 @group
+ /file @group
+ CODEOWNERS
+ end
+ end
+
+ describe '#load_definitions' do
+ 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|
+ expect(definitions[:allow]).to be_an(Array)
+ expect(definitions[:deny]).to be_an(Array)
+ end
+ end
+ end
+
+ it 'expands the auth group' do
+ auth = subject.load_definitions.dig(
+ :'[Authentication and Authorization]',
+ :'@gitlab-org/manage/authentication-and-authorization')
+
+ 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*{/**/*,}
+ ],
+ 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*{/**/*,}
+ ]
+ )
+ end
+ end
+
+ describe '#load_config' do
+ it 'loads the config with symbolized keys' do
+ config = subject.load_config
+
+ expect_hash_keys_to_be_symbols(config)
+ end
+
+ context 'when YAML has safe_load_file' do
+ before do
+ allow(YAML).to receive(:respond_to?).with(:safe_load_file).and_return(true)
+ end
+
+ it 'calls safe_load_file' do
+ expect(YAML).to receive(:safe_load_file)
+
+ subject.load_config
+ end
+ end
+
+ context 'when YAML does not have safe_load_file' do
+ before do
+ allow(YAML).to receive(:respond_to?).with(:safe_load_file).and_return(false)
+ end
+
+ it 'calls load_file' do
+ expect(YAML).to receive(:safe_load)
+
+ subject.load_config
+ end
+ end
+
+ def expect_hash_keys_to_be_symbols(object)
+ if object.is_a?(Hash)
+ object.each do |key, value|
+ expect(key).to be_a(Symbol)
+
+ expect_hash_keys_to_be_symbols(value)
+ end
+ end
+ end
+ end
+
+ describe '#path_matches?' do
+ let(:pattern) { 'pattern' }
+ let(:path) { 'path' }
+
+ it 'passes flags we are expecting to File.fnmatch?' do
+ expected_flags =
+ ::File::FNM_DOTMATCH | ::File::FNM_PATHNAME | ::File::FNM_EXTGLOB
+
+ expect(File).to receive(:fnmatch?).with(pattern, path, expected_flags)
+
+ subject.path_matches?(pattern, path)
+ end
+ end
+
+ describe '#consolidate_paths' do
+ before do
+ allow(subject).to receive(:find_dir_maxdepth_1).and_return(<<~LINES)
+ dir
+ dir/0
+ dir/2
+ dir/3
+ dir/1
+ LINES
+ end
+
+ context 'when the directory has the same number of entries' do
+ let(:input_paths) { %W[dir/0\n dir/1\n dir/2\n dir/3\n] }
+
+ it 'consolidates into the directory' do
+ paths = subject.consolidate_paths(input_paths)
+
+ expect(paths).to eq(["dir\n"])
+ end
+ end
+
+ context 'when the directory has different number of entries' do
+ let(:input_paths) { %W[dir/0\n dir/1\n dir/2\n] }
+
+ it 'returns the original paths' do
+ paths = subject.consolidate_paths(input_paths)
+
+ expect(paths).to eq(input_paths)
+ end
+ end
+ end
+end
diff --git a/spec/tooling/quality/test_level_spec.rb b/spec/tooling/quality/test_level_spec.rb
index c72e90dc713..98034eb4b0a 100644
--- a/spec/tooling/quality/test_level_spec.rb
+++ b/spec/tooling/quality/test_level_spec.rb
@@ -11,13 +11,6 @@ RSpec.describe Quality::TestLevel do
end
end
- context 'when level is geo' do
- it 'returns a pattern' do
- expect(subject.pattern(:geo))
- .to eq("spec/**{,/**/}*_spec.rb")
- end
- end
-
context 'when level is frontend_fixture' do
it 'returns a pattern' do
expect(subject.pattern(:frontend_fixture))
@@ -93,13 +86,6 @@ RSpec.describe Quality::TestLevel do
end
end
- context 'when level is geo' do
- it 'returns a regexp' do
- expect(subject.regexp(:geo))
- .to eq(%r{spec/})
- end
- end
-
context 'when level is frontend_fixture' do
it 'returns a regexp' do
expect(subject.regexp(:frontend_fixture))