Commit bbe4e54f authored by Albert Salim's avatar Albert Salim

Include test files in test file result

parent 7f775275
# frozen_string_literal: true # frozen_string_literal: true
require 'ostruct' require 'ostruct'
require 'set'
module Quality module Quality
class TestFileFinder class TestFileFinder
...@@ -10,6 +11,7 @@ module Quality ...@@ -10,6 +11,7 @@ module Quality
def initialize(file, foss_test_only: false) def initialize(file, foss_test_only: false)
@file = file @file = file
@foss_test_only = foss_test_only @foss_test_only = foss_test_only
@result = Set.new
end end
def test_files def test_files
...@@ -17,18 +19,22 @@ module Quality ...@@ -17,18 +19,22 @@ module Quality
contexts.flat_map do |context| contexts.flat_map do |context|
match_test_files_for(context) match_test_files_for(context)
end end
result.to_a
end end
private private
attr_reader :file, :foss_test_only attr_reader :file, :foss_test_only, :result
def ee_context def ee_context
OpenStruct.new.tap do |ee| OpenStruct.new.tap do |ee|
ee.app = %r{^#{EE_PREFIX}app/(.+)\.rb$} unless foss_test_only ee.app = %r{^#{EE_PREFIX}app/(.+)\.rb$} unless foss_test_only
ee.lib = %r{^#{EE_PREFIX}lib/(.+)\.rb$} unless foss_test_only ee.lib = %r{^#{EE_PREFIX}lib/(.+)\.rb$} unless foss_test_only
ee.spec = %r{^#{EE_PREFIX}spec/(.+)_spec.rb$} unless foss_test_only
ee.spec_dir = "#{EE_PREFIX}spec" unless foss_test_only ee.spec_dir = "#{EE_PREFIX}spec" unless foss_test_only
ee.ee_modules = %r{^#{EE_PREFIX}(.*\/)ee/(.+)\.rb$} ee.ee_modules = %r{^#{EE_PREFIX}(?!spec)(.*\/)ee/(.+)\.rb$}
ee.ee_module_spec = %r{^#{EE_PREFIX}spec/(.*\/)ee/(.+)\.rb$}
ee.foss_spec_dir = 'spec' ee.foss_spec_dir = 'spec'
end end
end end
...@@ -37,26 +43,31 @@ module Quality ...@@ -37,26 +43,31 @@ module Quality
OpenStruct.new.tap do |foss| OpenStruct.new.tap do |foss|
foss.app = %r{^app/(.+)\.rb$} foss.app = %r{^app/(.+)\.rb$}
foss.lib = %r{^lib/(.+)\.rb$} foss.lib = %r{^lib/(.+)\.rb$}
foss.spec = %r{^spec/(.+)_spec.rb$}
foss.spec_dir = 'spec' foss.spec_dir = 'spec'
end end
end end
def match_test_files_for(context) def match_test_files_for(context)
test_files = []
if (match = context.app&.match(file)) if (match = context.app&.match(file))
test_files << "#{context.spec_dir}/#{match[1]}_spec.rb" result << "#{context.spec_dir}/#{match[1]}_spec.rb"
end end
if (match = context.lib&.match(file)) if (match = context.lib&.match(file))
test_files << "#{context.spec_dir}/lib/#{match[1]}_spec.rb" result << "#{context.spec_dir}/lib/#{match[1]}_spec.rb"
end
if context.spec&.match(file)
result << file
end end
if (match = context.ee_modules&.match(file)) if (match = context.ee_modules&.match(file))
test_files << "#{context.foss_spec_dir}/#{match[1]}#{match[2]}_spec.rb" result << "#{context.foss_spec_dir}/#{match[1]}#{match[2]}_spec.rb"
end end
test_files if (match = context.ee_module_spec&.match(file))
result << "#{context.foss_spec_dir}/#{match[1]}#{match[2]}.rb"
end
end end
end end
end end
...@@ -45,8 +45,9 @@ describe Quality::TestFileFinder do ...@@ -45,8 +45,9 @@ describe Quality::TestFileFinder do
context 'when given a test file' do context 'when given a test file' do
let(:file) { 'spec/lib/banzai/color_parser_spec.rb' } let(:file) { 'spec/lib/banzai/color_parser_spec.rb' }
let(:test_files) { ['spec/lib/banzai/color_parser_spec.rb'] }
it_behaves_like 'not finding a matching test file' it_behaves_like 'finding matching test files'
end end
context 'when given an ee app file' do context 'when given an ee app file' do
...@@ -71,9 +72,17 @@ describe Quality::TestFileFinder do ...@@ -71,9 +72,17 @@ describe Quality::TestFileFinder do
end end
context 'when given an ee test file' do context 'when given an ee test file' do
let(:file) { 'ee/spec/lib/banzai/color_parser_spec.rb' } let(:file) { 'ee/spec/models/container_registry/event_spec.rb' }
let(:test_files) { ['ee/spec/models/container_registry/event_spec.rb'] }
it_behaves_like 'not finding a matching test file' it_behaves_like 'finding matching test files'
end
context 'when given an ee module test file' do
let(:file) { 'ee/spec/models/ee/appearance_spec.rb' }
let(:test_files) { ['ee/spec/models/ee/appearance_spec.rb', 'spec/models/appearance_spec.rb'] }
it_behaves_like 'finding matching test files'
end end
context 'with foss_test_only: true' do context 'with foss_test_only: true' do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment