debian-mirror-gitlab/spec/finders/packages/conan/package_finder_spec.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

74 lines
2.4 KiB
Ruby
Raw Normal View History

2020-07-28 23:09:34 +05:30
# frozen_string_literal: true
require 'spec_helper'
2023-07-09 08:55:56 +05:30
RSpec.describe ::Packages::Conan::PackageFinder, feature_category: :package_registry do
2022-07-01 11:34:44 +05:30
using RSpec::Parameterized::TableSyntax
let_it_be_with_reload(:project) { create(:project) }
2020-07-28 23:09:34 +05:30
let_it_be(:user) { create(:user) }
2022-07-01 11:34:44 +05:30
let_it_be(:private_project) { create(:project, :private) }
let_it_be(:conan_package) { create(:conan_package, project: project) }
let_it_be(:conan_package2) { create(:conan_package, project: project) }
let_it_be(:errored_package) { create(:conan_package, :error, project: project) }
let_it_be(:private_package) { create(:conan_package, project: private_project) }
2020-07-28 23:09:34 +05:30
describe '#execute' do
2022-07-01 11:34:44 +05:30
let(:query) { "#{conan_package.name.split('/').first[0, 3]}%" }
2023-07-09 08:55:56 +05:30
let(:finder) { described_class.new(user, params) }
let(:params) { { query: query } }
2022-07-01 11:34:44 +05:30
subject { finder.execute }
where(:visibility, :role, :packages_visible) do
:private | :maintainer | true
:private | :developer | true
:private | :reporter | true
:private | :guest | false
:private | :anonymous | false
:internal | :maintainer | true
:internal | :developer | true
:internal | :reporter | true
:internal | :guest | true
:internal | :anonymous | false
:public | :maintainer | true
:public | :developer | true
:public | :reporter | true
:public | :guest | true
:public | :anonymous | true
end
2020-07-28 23:09:34 +05:30
2022-07-01 11:34:44 +05:30
with_them do
2023-07-09 08:55:56 +05:30
let(:expected_packages) { packages_visible ? [conan_package2, conan_package] : [] }
2022-07-01 11:34:44 +05:30
let(:user) { role == :anonymous ? nil : super() }
2020-07-28 23:09:34 +05:30
2022-07-01 11:34:44 +05:30
before do
project.update_column(:visibility_level, Gitlab::VisibilityLevel.string_options[visibility.to_s])
2022-08-13 15:12:31 +05:30
project.add_member(user, role) unless role == :anonymous
2022-07-01 11:34:44 +05:30
end
2020-07-28 23:09:34 +05:30
2022-07-01 11:34:44 +05:30
it { is_expected.to eq(expected_packages) }
2020-07-28 23:09:34 +05:30
end
2023-07-09 08:55:56 +05:30
context 'with project' do
subject { described_class.new(user, params, project: project).execute }
it { is_expected.to match_array([conan_package2, conan_package]) }
it 'respects the limit' do
stub_const("#{described_class}::MAX_PACKAGES_COUNT", 1)
expect(subject).to match_array([conan_package2])
end
context 'with a different project' do
let_it_be(:project) { private_project }
it { is_expected.to match_array([private_package]) }
end
end
2020-07-28 23:09:34 +05:30
end
end