2020-07-28 23:09:34 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
RSpec.describe Packages::Nuget::PackageFinder do
|
2021-03-08 18:12:59 +05:30
|
|
|
let_it_be(:user) { create(:user) }
|
|
|
|
let_it_be(:group) { create(:group) }
|
|
|
|
let_it_be(:subgroup) { create(:group, parent: group) }
|
|
|
|
let_it_be(:project) { create(:project, namespace: subgroup) }
|
2021-06-08 01:23:25 +05:30
|
|
|
let_it_be_with_refind(:package1) { create(:nuget_package, project: project) }
|
2022-11-25 23:54:43 +05:30
|
|
|
let_it_be(:package2) { create(:nuget_package, name: package1.name, version: '2.0.0-ABC', project: project) }
|
2020-07-28 23:09:34 +05:30
|
|
|
let_it_be(:package3) { create(:nuget_package, name: 'Another.Dummy.Package', project: project) }
|
2021-03-08 18:12:59 +05:30
|
|
|
let_it_be(:other_package_1) { create(:nuget_package, name: package1.name, version: package1.version) }
|
|
|
|
let_it_be(:other_package_2) { create(:nuget_package, name: package1.name, version: package2.version) }
|
2021-09-30 23:02:18 +05:30
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
let(:package_name) { package1.name }
|
|
|
|
let(:package_version) { nil }
|
|
|
|
let(:limit) { 50 }
|
|
|
|
|
|
|
|
describe '#execute!' do
|
2021-03-08 18:12:59 +05:30
|
|
|
subject { described_class.new(user, target, package_name: package_name, package_version: package_version, limit: limit).execute }
|
2020-07-28 23:09:34 +05:30
|
|
|
|
2021-03-08 18:12:59 +05:30
|
|
|
shared_examples 'handling all the conditions' do
|
|
|
|
it { is_expected.to match_array([package1, package2]) }
|
2020-07-28 23:09:34 +05:30
|
|
|
|
2021-03-08 18:12:59 +05:30
|
|
|
context 'with lower case package name' do
|
|
|
|
let(:package_name) { package1.name.downcase }
|
2020-07-28 23:09:34 +05:30
|
|
|
|
2021-03-08 18:12:59 +05:30
|
|
|
it { is_expected.to match_array([package1, package2]) }
|
|
|
|
end
|
2020-07-28 23:09:34 +05:30
|
|
|
|
2021-03-08 18:12:59 +05:30
|
|
|
context 'with unknown package name' do
|
|
|
|
let(:package_name) { 'foobar' }
|
2020-07-28 23:09:34 +05:30
|
|
|
|
2021-03-08 18:12:59 +05:30
|
|
|
it { is_expected.to be_empty }
|
|
|
|
end
|
2020-07-28 23:09:34 +05:30
|
|
|
|
2021-06-08 01:23:25 +05:30
|
|
|
context 'with an uninstallable package' do
|
|
|
|
before do
|
2022-03-02 08:16:31 +05:30
|
|
|
package1.update_column(:status, :error)
|
2021-06-08 01:23:25 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it { is_expected.to contain_exactly(package2) }
|
|
|
|
end
|
|
|
|
|
2021-03-08 18:12:59 +05:30
|
|
|
context 'with valid version' do
|
2022-11-25 23:54:43 +05:30
|
|
|
let(:package_version) { '2.0.0-ABC' }
|
|
|
|
|
|
|
|
it { is_expected.to match_array([package2]) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with varying case version' do
|
|
|
|
let(:package_version) { '2.0.0-abC' }
|
2020-07-28 23:09:34 +05:30
|
|
|
|
2021-03-08 18:12:59 +05:30
|
|
|
it { is_expected.to match_array([package2]) }
|
|
|
|
end
|
2020-07-28 23:09:34 +05:30
|
|
|
|
2021-03-08 18:12:59 +05:30
|
|
|
context 'with unknown version' do
|
|
|
|
let(:package_version) { 'foobar' }
|
2020-07-28 23:09:34 +05:30
|
|
|
|
2021-03-08 18:12:59 +05:30
|
|
|
it { is_expected.to be_empty }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with limit hit' do
|
|
|
|
let_it_be(:package4) { create(:nuget_package, name: package1.name, project: project) }
|
|
|
|
let_it_be(:package5) { create(:nuget_package, name: package1.name, project: project) }
|
|
|
|
let_it_be(:package6) { create(:nuget_package, name: package1.name, project: project) }
|
2021-09-30 23:02:18 +05:30
|
|
|
|
2021-03-08 18:12:59 +05:30
|
|
|
let(:limit) { 2 }
|
|
|
|
|
|
|
|
it { is_expected.to match_array([package5, package6]) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with downcase package name' do
|
|
|
|
let(:package_name) { package1.name.downcase }
|
|
|
|
|
|
|
|
it { is_expected.to match_array([package1, package2]) }
|
|
|
|
end
|
2020-07-28 23:09:34 +05:30
|
|
|
|
2021-03-08 18:12:59 +05:30
|
|
|
context 'with prefix wildcard' do
|
2022-01-26 12:08:38 +05:30
|
|
|
let(:package_name) { "%#{package1.name[3..]}" }
|
2020-07-28 23:09:34 +05:30
|
|
|
|
2021-03-08 18:12:59 +05:30
|
|
|
it { is_expected.to match_array([package1, package2]) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with suffix wildcard' do
|
|
|
|
let(:package_name) { "#{package1.name[0..-3]}%" }
|
|
|
|
|
|
|
|
it { is_expected.to match_array([package1, package2]) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with surrounding wildcards' do
|
|
|
|
let(:package_name) { "%#{package1.name[3..-3]}%" }
|
|
|
|
|
|
|
|
it { is_expected.to match_array([package1, package2]) }
|
|
|
|
end
|
2020-07-28 23:09:34 +05:30
|
|
|
end
|
|
|
|
|
2021-03-08 18:12:59 +05:30
|
|
|
context 'with a project' do
|
|
|
|
let(:target) { project }
|
2020-07-28 23:09:34 +05:30
|
|
|
|
2021-03-08 18:12:59 +05:30
|
|
|
before do
|
|
|
|
project.add_developer(user)
|
|
|
|
end
|
|
|
|
|
|
|
|
it_behaves_like 'handling all the conditions'
|
2020-07-28 23:09:34 +05:30
|
|
|
end
|
|
|
|
|
2021-03-08 18:12:59 +05:30
|
|
|
context 'with a subgroup' do
|
|
|
|
let(:target) { subgroup }
|
2020-07-28 23:09:34 +05:30
|
|
|
|
2021-03-08 18:12:59 +05:30
|
|
|
before do
|
|
|
|
subgroup.add_developer(user)
|
|
|
|
end
|
|
|
|
|
|
|
|
it_behaves_like 'handling all the conditions'
|
2020-07-28 23:09:34 +05:30
|
|
|
end
|
|
|
|
|
2021-03-08 18:12:59 +05:30
|
|
|
context 'with a group' do
|
|
|
|
let(:target) { group }
|
2020-07-28 23:09:34 +05:30
|
|
|
|
2021-03-08 18:12:59 +05:30
|
|
|
before do
|
|
|
|
group.add_developer(user)
|
|
|
|
end
|
|
|
|
|
|
|
|
it_behaves_like 'handling all the conditions'
|
2020-07-28 23:09:34 +05:30
|
|
|
end
|
|
|
|
|
2021-03-08 18:12:59 +05:30
|
|
|
context 'with nil' do
|
|
|
|
let(:target) { nil }
|
2020-07-28 23:09:34 +05:30
|
|
|
|
2021-03-08 18:12:59 +05:30
|
|
|
it { is_expected.to be_empty }
|
2020-07-28 23:09:34 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|