diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-05-19 10:33:21 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-05-19 10:33:21 +0300 |
commit | 36a59d088eca61b834191dacea009677a96c052f (patch) | |
tree | e4f33972dab5d8ef79e3944a9f403035fceea43f /spec/finders/packages/build_infos_finder_spec.rb | |
parent | a1761f15ec2cae7c7f7bbda39a75494add0dfd6f (diff) |
Add latest changes from gitlab-org/gitlab@15-0-stable-eev15.0.0-rc42
Diffstat (limited to 'spec/finders/packages/build_infos_finder_spec.rb')
-rw-r--r-- | spec/finders/packages/build_infos_finder_spec.rb | 120 |
1 files changed, 96 insertions, 24 deletions
diff --git a/spec/finders/packages/build_infos_finder_spec.rb b/spec/finders/packages/build_infos_finder_spec.rb index 23425de4316..6e7f0623030 100644 --- a/spec/finders/packages/build_infos_finder_spec.rb +++ b/spec/finders/packages/build_infos_finder_spec.rb @@ -9,7 +9,20 @@ RSpec.describe ::Packages::BuildInfosFinder do let_it_be(:build_infos) { create_list(:package_build_info, 5, :with_pipeline, package: package) } let_it_be(:build_info_with_empty_pipeline) { create(:package_build_info, package: package) } - let(:finder) { described_class.new(package, params) } + let_it_be(:other_package) { create(:package) } + let_it_be(:other_build_infos) { create_list(:package_build_info, 5, :with_pipeline, package: other_package) } + let_it_be(:other_build_info_with_empty_pipeline) { create(:package_build_info, package: other_package) } + + let_it_be(:all_build_infos) { build_infos + other_build_infos } + + let(:finder) { described_class.new(packages, params) } + let(:packages) { nil } + let(:first) { nil } + let(:last) { nil } + let(:after) { nil } + let(:before) { nil } + let(:max_page_size) { nil } + let(:support_next_page) { false } let(:params) do { first: first, @@ -24,41 +37,100 @@ RSpec.describe ::Packages::BuildInfosFinder do describe '#execute' do subject { finder.execute } - where(:first, :last, :after_index, :before_index, :max_page_size, :support_next_page, :expected_build_infos_indexes) do - # F L AI BI MPS SNP - nil | nil | nil | nil | nil | false | [4, 3, 2, 1, 0] - nil | nil | nil | nil | 10 | false | [4, 3, 2, 1, 0] - nil | nil | nil | nil | 2 | false | [4, 3] - 2 | nil | nil | nil | nil | false | [4, 3] - 2 | nil | nil | nil | nil | true | [4, 3, 2] - 2 | nil | 3 | nil | nil | false | [2, 1] - 2 | nil | 3 | nil | nil | true | [2, 1, 0] - 3 | nil | 4 | nil | 2 | false | [3, 2] - 3 | nil | 4 | nil | 2 | true | [3, 2, 1] - nil | 2 | nil | nil | nil | false | [0, 1] - nil | 2 | nil | nil | nil | true | [0, 1, 2] - nil | 2 | nil | 1 | nil | false | [2, 3] - nil | 2 | nil | 1 | nil | true | [2, 3, 4] - nil | 3 | nil | 0 | 2 | false | [1, 2] - nil | 3 | nil | 0 | 2 | true | [1, 2, 3] - end - - with_them do + shared_examples 'returning the expected build infos' do let(:expected_build_infos) do expected_build_infos_indexes.map do |idx| - build_infos[idx] + all_build_infos[idx] end end let(:after) do - build_infos[after_index].pipeline_id if after_index + all_build_infos[after_index].pipeline_id if after_index end let(:before) do - build_infos[before_index].pipeline_id if before_index + all_build_infos[before_index].pipeline_id if before_index end it { is_expected.to eq(expected_build_infos) } end + + context 'with nil packages' do + let(:packages) { nil } + + it { is_expected.to be_empty } + end + + context 'with [] packages' do + let(:packages) { [] } + + it { is_expected.to be_empty } + end + + context 'with empy scope packages' do + let(:packages) { Packages::Package.none } + + it { is_expected.to be_empty } + end + + context 'with a single package' do + let(:packages) { package.id } + + # rubocop: disable Layout/LineLength + where(:first, :last, :after_index, :before_index, :max_page_size, :support_next_page, :expected_build_infos_indexes) do + # F L AI BI MPS SNP + nil | nil | nil | nil | nil | false | [4, 3, 2, 1, 0] + nil | nil | nil | nil | 10 | false | [4, 3, 2, 1, 0] + nil | nil | nil | nil | 2 | false | [4, 3] + 2 | nil | nil | nil | nil | false | [4, 3] + 2 | nil | nil | nil | nil | true | [4, 3, 2] + 2 | nil | 3 | nil | nil | false | [2, 1] + 2 | nil | 3 | nil | nil | true | [2, 1, 0] + 3 | nil | 4 | nil | 2 | false | [3, 2] + 3 | nil | 4 | nil | 2 | true | [3, 2, 1] + nil | 2 | nil | nil | nil | false | [1, 0] + nil | 2 | nil | nil | nil | true | [2, 1, 0] + nil | 2 | nil | 1 | nil | false | [3, 2] + nil | 2 | nil | 1 | nil | true | [4, 3, 2] + nil | 3 | nil | 0 | 2 | false | [2, 1] + nil | 3 | nil | 0 | 2 | true | [3, 2, 1] + end + # rubocop: enable Layout/LineLength + + with_them do + it_behaves_like 'returning the expected build infos' + end + end + + context 'with many packages' do + let(:packages) { [package.id, other_package.id] } + + # using after_index/before_index when receiving multiple packages doesn't + # make sense but we still verify here that the behavior is coherent. + # rubocop: disable Layout/LineLength + where(:first, :last, :after_index, :before_index, :max_page_size, :support_next_page, :expected_build_infos_indexes) do + # F L AI BI MPS SNP + nil | nil | nil | nil | nil | false | [9, 8, 7, 6, 5, 4, 3, 2, 1, 0] + nil | nil | nil | nil | 10 | false | [9, 8, 7, 6, 5, 4, 3, 2, 1, 0] + nil | nil | nil | nil | 2 | false | [9, 8, 4, 3] + 2 | nil | nil | nil | nil | false | [9, 8, 4, 3] + 2 | nil | nil | nil | nil | true | [9, 8, 7, 4, 3, 2] + 2 | nil | 3 | nil | nil | false | [2, 1] + 2 | nil | 3 | nil | nil | true | [2, 1, 0] + 3 | nil | 4 | nil | 2 | false | [3, 2] + 3 | nil | 4 | nil | 2 | true | [3, 2, 1] + nil | 2 | nil | nil | nil | false | [6, 5, 1, 0] + nil | 2 | nil | nil | nil | true | [7, 6, 5, 2, 1, 0] + nil | 2 | nil | 1 | nil | false | [6, 5, 3, 2] + nil | 2 | nil | 1 | nil | true | [7, 6, 5, 4, 3, 2] + nil | 3 | nil | 0 | 2 | false | [6, 5, 2, 1] + nil | 3 | nil | 0 | 2 | true | [7, 6, 5, 3, 2, 1] + end + + with_them do + it_behaves_like 'returning the expected build infos' + end + # rubocop: enable Layout/LineLength + end end end |