diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-11-19 08:27:35 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-11-19 08:27:35 +0000 |
commit | 7e9c479f7de77702622631cff2628a9c8dcbc627 (patch) | |
tree | c8f718a08e110ad7e1894510980d2155a6549197 /spec/tooling | |
parent | e852b0ae16db4052c1c567d9efa4facc81146e88 (diff) | |
download | gitlab-ce-7e9c479f7de77702622631cff2628a9c8dcbc627.tar.gz |
Add latest changes from gitlab-org/gitlab@13-6-stable-eev13.6.0-rc42
Diffstat (limited to 'spec/tooling')
5 files changed, 244 insertions, 8 deletions
diff --git a/spec/tooling/lib/tooling/crystalball/coverage_lines_execution_detector_spec.rb b/spec/tooling/lib/tooling/crystalball/coverage_lines_execution_detector_spec.rb new file mode 100644 index 00000000000..6b7373cb3c7 --- /dev/null +++ b/spec/tooling/lib/tooling/crystalball/coverage_lines_execution_detector_spec.rb @@ -0,0 +1,42 @@ +# frozen_string_literal: true + +require_relative '../../../../../tooling/lib/tooling/crystalball/coverage_lines_execution_detector' + +RSpec.describe Tooling::Crystalball::CoverageLinesExecutionDetector do + subject(:detector) { described_class.new(root, exclude_prefixes: %w[vendor/ruby]) } + + let(:root) { '/tmp' } + let(:before_map) { { path => { lines: [0, 2, nil] } } } + let(:after_map) { { path => { lines: [0, 3, nil] } } } + let(:path) { '/tmp/file.rb' } + + describe '#detect' do + subject { detector.detect(before_map, after_map) } + + it { is_expected.to eq(%w[file.rb]) } + + context 'with no changes' do + let(:after_map) { { path => { lines: [0, 2, nil] } } } + + it { is_expected.to eq([]) } + end + + context 'with previously uncovered file' do + let(:before_map) { {} } + + it { is_expected.to eq(%w[file.rb]) } + end + + context 'with path outside of root' do + let(:path) { '/abc/file.rb' } + + it { is_expected.to eq([]) } + end + + context 'with path in excluded prefix' do + let(:path) { '/tmp/vendor/ruby/dependency.rb' } + + it { is_expected.to eq([]) } + end + end +end diff --git a/spec/tooling/lib/tooling/crystalball/coverage_lines_strategy_spec.rb b/spec/tooling/lib/tooling/crystalball/coverage_lines_strategy_spec.rb new file mode 100644 index 00000000000..fd8fc4114a1 --- /dev/null +++ b/spec/tooling/lib/tooling/crystalball/coverage_lines_strategy_spec.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +require_relative '../../../../../tooling/lib/tooling/crystalball/coverage_lines_strategy' + +RSpec.describe Tooling::Crystalball::CoverageLinesStrategy do + subject { described_class.new(execution_detector) } + + let(:execution_detector) { instance_double('Tooling::Crystalball::CoverageLinesExecutionDetector') } + + describe '#after_register' do + it 'starts coverage' do + expect(Coverage).to receive(:start).with(lines: true) + subject.after_register + end + end +end diff --git a/spec/tooling/lib/tooling/test_file_finder_spec.rb b/spec/tooling/lib/tooling/test_file_finder_spec.rb index 64b55b9b1d6..683bc647b8a 100644 --- a/spec/tooling/lib/tooling/test_file_finder_spec.rb +++ b/spec/tooling/lib/tooling/test_file_finder_spec.rb @@ -63,14 +63,6 @@ RSpec.describe Tooling::TestFileFinder do end end - context 'when given a lib file in ee/' do - let(:file) { 'ee/lib/flipper_session.rb' } - - it 'returns the matching ee/ lib test file' do - expect(subject.test_files).to contain_exactly('ee/spec/lib/flipper_session_spec.rb') - end - end - context 'when given a test file in ee/' do let(:file) { 'ee/spec/models/container_registry/event_spec.rb' } diff --git a/spec/tooling/lib/tooling/test_map_generator_spec.rb b/spec/tooling/lib/tooling/test_map_generator_spec.rb new file mode 100644 index 00000000000..7f3b2807162 --- /dev/null +++ b/spec/tooling/lib/tooling/test_map_generator_spec.rb @@ -0,0 +1,109 @@ +# frozen_string_literal: true + +require_relative '../../../../tooling/lib/tooling/test_map_generator' + +RSpec.describe Tooling::TestMapGenerator do + subject { described_class.new } + + describe '#parse' do + let(:yaml1) do + <<~YAML + --- + :type: Crystalball::ExecutionMap + :commit: a7d57d333042f3b0334b2f8a282354eef7365976 + :timestamp: 1602668405 + :version: + --- + "./spec/factories_spec.rb[1]": + - lib/gitlab/current_settings.rb + - lib/feature.rb + - lib/gitlab/marginalia.rb + YAML + end + + let(:yaml2) do + <<~YAML + --- + :type: Crystalball::ExecutionMap + :commit: 74056e8d9cf3773f43faa1cf5416f8779c8284c8 + :timestamp: 1602671965 + :version: + --- + "./spec/models/project_spec.rb[1]": + - lib/gitlab/current_settings.rb + - lib/feature.rb + - lib/gitlab/marginalia.rb + YAML + end + + 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) + end + + context 'with single yaml' do + let(:expected_mapping) do + { + 'lib/gitlab/current_settings.rb' => [ + './spec/factories_spec.rb' + ], + 'lib/feature.rb' => [ + './spec/factories_spec.rb' + ], + 'lib/gitlab/marginalia.rb' => [ + './spec/factories_spec.rb' + ] + } + end + + it 'parses crystalball data into test mapping' do + subject.parse('yaml1.yml') + + expect(subject.mapping.keys).to match_array(expected_mapping.keys) + end + + it 'stores test files without example uid' do + subject.parse('yaml1.yml') + + expected_mapping.each do |file, tests| + expect(subject.mapping[file]).to match_array(tests) + end + end + end + + context 'with multiple yamls' do + let(:expected_mapping) do + { + 'lib/gitlab/current_settings.rb' => [ + './spec/factories_spec.rb', + './spec/models/project_spec.rb' + ], + 'lib/feature.rb' => [ + './spec/factories_spec.rb', + './spec/models/project_spec.rb' + ], + 'lib/gitlab/marginalia.rb' => [ + './spec/factories_spec.rb', + './spec/models/project_spec.rb' + ] + } + end + + it 'parses crystalball data into test mapping' do + subject.parse(%w[yaml1.yml yaml2.yml]) + + expect(subject.mapping.keys).to match_array(expected_mapping.keys) + end + + it 'stores test files without example uid' do + subject.parse(%w[yaml1.yml yaml2.yml]) + + expected_mapping.each do |file, tests| + expect(subject.mapping[file]).to match_array(tests) + end + end + end + end +end diff --git a/spec/tooling/lib/tooling/test_map_packer_spec.rb b/spec/tooling/lib/tooling/test_map_packer_spec.rb new file mode 100644 index 00000000000..233134d2524 --- /dev/null +++ b/spec/tooling/lib/tooling/test_map_packer_spec.rb @@ -0,0 +1,77 @@ +# frozen_string_literal: true + +require_relative '../../../../tooling/lib/tooling/test_map_packer' + +RSpec.describe Tooling::TestMapPacker do + subject { described_class.new } + + let(:map) do + { + 'file1.rb' => [ + './a/b/c/test_1.rb', + './a/b/test_2.rb', + './a/b/test_3.rb', + './a/test_4.rb', + './test_5.rb' + ], + 'file2.rb' => [ + './a/b/c/test_1.rb', + './a/test_4.rb', + './test_5.rb' + ] + } + end + + let(:compact_map) do + { + 'file1.rb' => { + '.' => { + 'a' => { + 'b' => { + 'c' => { + 'test_1.rb' => 1 + }, + 'test_2.rb' => 1, + 'test_3.rb' => 1 + }, + 'test_4.rb' => 1 + }, + 'test_5.rb' => 1 + } + }, + 'file2.rb' => { + '.' => { + 'a' => { + 'b' => { + 'c' => { + 'test_1.rb' => 1 + } + }, + 'test_4.rb' => 1 + }, + 'test_5.rb' => 1 + } + } + } + end + + describe '#pack' do + it 'compacts list of test files into a prefix tree' do + expect(subject.pack(map)).to eq(compact_map) + end + + it 'does nothing to empty hash' do + expect(subject.pack({})).to eq({}) + end + end + + describe '#unpack' do + it 'unpack prefix tree into list of test files' do + expect(subject.unpack(compact_map)).to eq(map) + end + + it 'does nothing to empty hash' do + expect(subject.unpack({})).to eq({}) + end + end +end |