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>2020-06-18 14:18:50 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2020-06-18 14:18:50 +0300
commit8c7f4e9d5f36cff46365a7f8c4b9c21578c1e781 (patch)
treea77e7fe7a93de11213032ed4ab1f33a3db51b738 /tooling/lib
parent00b35af3db1abfe813a778f643dad221aad51fca (diff)
Add latest changes from gitlab-org/gitlab@13-1-stable-ee
Diffstat (limited to 'tooling/lib')
-rw-r--r--tooling/lib/tooling/test_file_finder.rb78
1 files changed, 78 insertions, 0 deletions
diff --git a/tooling/lib/tooling/test_file_finder.rb b/tooling/lib/tooling/test_file_finder.rb
new file mode 100644
index 00000000000..4cf7ad35922
--- /dev/null
+++ b/tooling/lib/tooling/test_file_finder.rb
@@ -0,0 +1,78 @@
+# frozen_string_literal: true
+
+require 'set'
+
+module Tooling
+ class TestFileFinder
+ EE_PREFIX = 'ee/'
+
+ def initialize(file, foss_test_only: false)
+ @file = file
+ @foss_test_only = foss_test_only
+ end
+
+ def test_files
+ impacted_tests = ee_impact | non_ee_impact
+ impacted_tests.impact(@file)
+ end
+
+ private
+
+ attr_reader :file, :foss_test_only, :result
+
+ class ImpactedTestFile
+ attr_reader :pattern_matchers
+
+ def initialize
+ @pattern_matchers = {}
+
+ yield self if block_given?
+ end
+
+ def associate(pattern, &block)
+ @pattern_matchers[pattern] = block
+ end
+
+ def impact(file)
+ @pattern_matchers.each_with_object(Set.new) do |(pattern, block), result|
+ if (match = pattern.match(file))
+ result << block.call(match)
+ end
+ end.to_a
+ end
+
+ def |(other)
+ self.class.new do |combined_matcher|
+ self.pattern_matchers.each do |pattern, block|
+ combined_matcher.associate(pattern, &block)
+ end
+ other.pattern_matchers.each do |pattern, block|
+ combined_matcher.associate(pattern, &block)
+ end
+ end
+ end
+ end
+
+ def ee_impact
+ ImpactedTestFile.new do |impact|
+ unless foss_test_only
+ impact.associate(%r{^#{EE_PREFIX}app/(.+)\.rb$}) { |match| "#{EE_PREFIX}spec/#{match[1]}_spec.rb" }
+ impact.associate(%r{^#{EE_PREFIX}app/(.*/)ee/(.+)\.rb$}) { |match| "#{EE_PREFIX}spec/#{match[1]}#{match[2]}_spec.rb" }
+ impact.associate(%r{^#{EE_PREFIX}lib/(.+)\.rb$}) { |match| "#{EE_PREFIX}spec/lib/#{match[1]}_spec.rb" }
+ impact.associate(%r{^#{EE_PREFIX}spec/(.+)_spec.rb$}) { |match| match[0] }
+ end
+
+ impact.associate(%r{^#{EE_PREFIX}(?!spec)(.*/)ee/(.+)\.rb$}) { |match| "spec/#{match[1]}#{match[2]}_spec.rb" }
+ impact.associate(%r{^#{EE_PREFIX}spec/(.*/)ee/(.+)\.rb$}) { |match| "spec/#{match[1]}#{match[2]}.rb" }
+ end
+ end
+
+ def non_ee_impact
+ ImpactedTestFile.new do |impact|
+ impact.associate(%r{^app/(.+)\.rb$}) { |match| "spec/#{match[1]}_spec.rb" }
+ impact.associate(%r{^(tooling/)?lib/(.+)\.rb$}) { |match| "spec/#{match[1]}lib/#{match[2]}_spec.rb" }
+ impact.associate(%r{^spec/(.+)_spec.rb$}) { |match| match[0] }
+ end
+ end
+ end
+end