diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-12-17 11:59:07 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-12-17 11:59:07 +0000 |
commit | 8b573c94895dc0ac0e1d9d59cf3e8745e8b539ca (patch) | |
tree | 544930fb309b30317ae9797a9683768705d664c4 /spec/tooling | |
parent | 4b1de649d0168371549608993deac953eb692019 (diff) | |
download | gitlab-ce-8b573c94895dc0ac0e1d9d59cf3e8745e8b539ca.tar.gz |
Add latest changes from gitlab-org/gitlab@13-7-stable-eev13.7.0-rc42
Diffstat (limited to 'spec/tooling')
-rw-r--r-- | spec/tooling/lib/tooling/parallel_rspec_runner_spec.rb | 92 | ||||
-rw-r--r-- | spec/tooling/lib/tooling/test_map_generator_spec.rb | 25 |
2 files changed, 106 insertions, 11 deletions
diff --git a/spec/tooling/lib/tooling/parallel_rspec_runner_spec.rb b/spec/tooling/lib/tooling/parallel_rspec_runner_spec.rb new file mode 100644 index 00000000000..4b44d991d89 --- /dev/null +++ b/spec/tooling/lib/tooling/parallel_rspec_runner_spec.rb @@ -0,0 +1,92 @@ +# frozen_string_literal: true + +require_relative '../../../../tooling/lib/tooling/parallel_rspec_runner' + +RSpec.describe Tooling::ParallelRSpecRunner do # rubocop:disable RSpec/FilePath + describe '#run' do + let(:allocator) { instance_double(Knapsack::Allocator) } + let(:rspec_args) { '--seed 123' } + let(:filter_tests_file) { 'tests.txt' } + let(:node_tests) { %w[01_spec.rb 03_spec.rb 05_spec.rb] } + let(:filter_tests) { '01_spec.rb 02_spec.rb 03_spec.rb' } + let(:test_dir) { 'spec' } + + before do + allow(Knapsack.logger).to receive(:info) + allow(allocator).to receive(:node_tests).and_return(node_tests) + allow(allocator).to receive(:test_dir).and_return(test_dir) + allow(File).to receive(:exist?).with(filter_tests_file).and_return(true) + allow(File).to receive(:read).and_call_original + allow(File).to receive(:read).with(filter_tests_file).and_return(filter_tests) + allow(subject).to receive(:exec) + end + + subject { described_class.new(allocator: allocator, filter_tests_file: filter_tests_file, rspec_args: rspec_args) } + + shared_examples 'runs node tests' do + it 'runs rspec with tests allocated for this node' do + expect_command(%w[bundle exec rspec --seed 123 --default-path spec -- 01_spec.rb 03_spec.rb 05_spec.rb]) + + subject.run + end + end + + context 'given filter tests' do + it 'reads filter tests file for list of tests' do + expect(File).to receive(:read).with(filter_tests_file) + + subject.run + end + + it 'runs rspec filter tests that are allocated for this node' do + expect_command(%w[bundle exec rspec --seed 123 --default-path spec -- 01_spec.rb 03_spec.rb]) + + subject.run + end + + context 'when there is no intersect between allocated tests and filtered tests' do + let(:filter_tests) { '99_spec.rb' } + + it 'does not run rspec' do + expect(subject).not_to receive(:exec) + + subject.run + end + end + end + + context 'with empty filter tests file' do + let(:filter_tests) { '' } + + it_behaves_like 'runs node tests' + end + + context 'without filter_tests_file option' do + let(:filter_tests_file) { nil } + + it_behaves_like 'runs node tests' + end + + context 'if filter_tests_file does not exist' do + before do + allow(File).to receive(:exist?).with(filter_tests_file).and_return(false) + end + + it_behaves_like 'runs node tests' + end + + context 'without rspec args' do + let(:rspec_args) { nil } + + it 'runs rspec with without extra arguments' do + expect_command(%w[bundle exec rspec --default-path spec -- 01_spec.rb 03_spec.rb]) + + subject.run + end + end + + def expect_command(cmd) + expect(subject).to receive(:exec).with(*cmd) + end + end +end diff --git a/spec/tooling/lib/tooling/test_map_generator_spec.rb b/spec/tooling/lib/tooling/test_map_generator_spec.rb index 7f3b2807162..eb49b1db20e 100644 --- a/spec/tooling/lib/tooling/test_map_generator_spec.rb +++ b/spec/tooling/lib/tooling/test_map_generator_spec.rb @@ -1,8 +1,11 @@ # frozen_string_literal: true require_relative '../../../../tooling/lib/tooling/test_map_generator' +require_relative '../../../support/helpers/file_read_helpers' RSpec.describe Tooling::TestMapGenerator do + include FileReadHelpers + subject { described_class.new } describe '#parse' do @@ -39,21 +42,21 @@ RSpec.describe Tooling::TestMapGenerator do let(:pathname) { instance_double(Pathname) } before do - allow(File).to receive(:read).with('yaml1.yml').and_return(yaml1) - allow(File).to receive(:read).with('yaml2.yml').and_return(yaml2) + stub_file_read('yaml1.yml', content: yaml1) + stub_file_read('yaml2.yml', content: yaml2) end context 'with single yaml' do let(:expected_mapping) do { 'lib/gitlab/current_settings.rb' => [ - './spec/factories_spec.rb' + 'spec/factories_spec.rb' ], 'lib/feature.rb' => [ - './spec/factories_spec.rb' + 'spec/factories_spec.rb' ], 'lib/gitlab/marginalia.rb' => [ - './spec/factories_spec.rb' + 'spec/factories_spec.rb' ] } end @@ -77,16 +80,16 @@ RSpec.describe Tooling::TestMapGenerator do let(:expected_mapping) do { 'lib/gitlab/current_settings.rb' => [ - './spec/factories_spec.rb', - './spec/models/project_spec.rb' + 'spec/factories_spec.rb', + 'spec/models/project_spec.rb' ], 'lib/feature.rb' => [ - './spec/factories_spec.rb', - './spec/models/project_spec.rb' + 'spec/factories_spec.rb', + 'spec/models/project_spec.rb' ], 'lib/gitlab/marginalia.rb' => [ - './spec/factories_spec.rb', - './spec/models/project_spec.rb' + 'spec/factories_spec.rb', + 'spec/models/project_spec.rb' ] } end |