diff options
Diffstat (limited to 'spec/finders/packages')
-rw-r--r-- | spec/finders/packages/composer/packages_finder_spec.rb | 25 | ||||
-rw-r--r-- | spec/finders/packages/conan/package_finder_spec.rb | 3 | ||||
-rw-r--r-- | spec/finders/packages/generic/package_finder_spec.rb | 7 | ||||
-rw-r--r-- | spec/finders/packages/go/package_finder_spec.rb | 13 | ||||
-rw-r--r-- | spec/finders/packages/maven/package_finder_spec.rb | 12 | ||||
-rw-r--r-- | spec/finders/packages/npm/package_finder_spec.rb | 10 | ||||
-rw-r--r-- | spec/finders/packages/nuget/package_finder_spec.rb | 10 | ||||
-rw-r--r-- | spec/finders/packages/package_finder_spec.rb | 12 |
8 files changed, 86 insertions, 6 deletions
diff --git a/spec/finders/packages/composer/packages_finder_spec.rb b/spec/finders/packages/composer/packages_finder_spec.rb new file mode 100644 index 00000000000..d4328827de3 --- /dev/null +++ b/spec/finders/packages/composer/packages_finder_spec.rb @@ -0,0 +1,25 @@ +# frozen_string_literal: true +require 'spec_helper' + +RSpec.describe ::Packages::Composer::PackagesFinder do + let_it_be(:user) { create(:user) } + let_it_be(:group) { create(:group) } + let_it_be(:project) { create(:project, group: group) } + + let(:params) { {} } + + describe '#execute' do + let_it_be(:composer_package) { create(:composer_package, project: project) } + let_it_be(:composer_package2) { create(:composer_package, project: project) } + let_it_be(:error_package) { create(:composer_package, :error, project: project) } + let_it_be(:composer_package3) { create(:composer_package) } + + subject { described_class.new(user, group, params).execute } + + before do + project.add_developer(user) + end + + it { is_expected.to match_array([composer_package, composer_package2]) } + end +end diff --git a/spec/finders/packages/conan/package_finder_spec.rb b/spec/finders/packages/conan/package_finder_spec.rb index 936a0e5ff4b..b26f8900090 100644 --- a/spec/finders/packages/conan/package_finder_spec.rb +++ b/spec/finders/packages/conan/package_finder_spec.rb @@ -11,7 +11,8 @@ RSpec.describe ::Packages::Conan::PackageFinder do subject { described_class.new(user, query: query).execute } - context 'packages that are not visible to user' do + context 'packages that are not installable' do + let!(:conan_package3) { create(:conan_package, :error, project: project) } let!(:non_visible_project) { create(:project, :private) } let!(:non_visible_conan_package) { create(:conan_package, project: non_visible_project) } let(:query) { "#{conan_package.name.split('/').first[0, 3]}%" } diff --git a/spec/finders/packages/generic/package_finder_spec.rb b/spec/finders/packages/generic/package_finder_spec.rb index ed34268e7a9..707f943b285 100644 --- a/spec/finders/packages/generic/package_finder_spec.rb +++ b/spec/finders/packages/generic/package_finder_spec.rb @@ -23,6 +23,13 @@ RSpec.describe ::Packages::Generic::PackageFinder do expect(found_package).to eq(package) end + it 'does not find uninstallable packages' do + error_package = create(:generic_package, :error, project: project) + + expect { finder.execute!(error_package.name, error_package.version) } + .to raise_error(ActiveRecord::RecordNotFound) + end + it 'raises ActiveRecord::RecordNotFound if package is not found' do expect { finder.execute!(package.name, '3.1.4') } .to raise_error(ActiveRecord::RecordNotFound) diff --git a/spec/finders/packages/go/package_finder_spec.rb b/spec/finders/packages/go/package_finder_spec.rb index b6fad1e7061..dbcb8255d47 100644 --- a/spec/finders/packages/go/package_finder_spec.rb +++ b/spec/finders/packages/go/package_finder_spec.rb @@ -7,7 +7,7 @@ RSpec.describe Packages::Go::PackageFinder do let_it_be(:mod) { create :go_module, project: project } let_it_be(:version) { create :go_module_version, :tagged, mod: mod, name: 'v1.0.1' } - let_it_be(:package) { create :golang_package, project: project, name: mod.name, version: 'v1.0.1' } + let_it_be_with_refind(:package) { create :golang_package, project: project, name: mod.name, version: 'v1.0.1' } let(:finder) { described_class.new(project, mod_name, version_name) } @@ -54,6 +54,17 @@ RSpec.describe Packages::Go::PackageFinder do it { is_expected.to eq(package) } end + context 'with an uninstallable package' do + let(:mod_name) { mod.name } + let(:version_name) { version.name } + + before do + package.update_column(:status, 1) + end + + it { is_expected.to eq(nil) } + end + context 'with an invalid name' do let(:mod_name) { 'foo/bar' } let(:version_name) { 'baz' } diff --git a/spec/finders/packages/maven/package_finder_spec.rb b/spec/finders/packages/maven/package_finder_spec.rb index 9a6bb675248..d5f521ff895 100644 --- a/spec/finders/packages/maven/package_finder_spec.rb +++ b/spec/finders/packages/maven/package_finder_spec.rb @@ -6,7 +6,7 @@ RSpec.describe ::Packages::Maven::PackageFinder do let_it_be(:user) { create(:user) } let_it_be(:group) { create(:group) } let_it_be(:project) { create(:project, namespace: group) } - let_it_be(:package) { create(:maven_package, project: project) } + let_it_be_with_refind(:package) { create(:maven_package, project: project) } let(:param_path) { nil } let(:param_project) { nil } @@ -36,6 +36,16 @@ RSpec.describe ::Packages::Maven::PackageFinder do expect { subject }.to raise_error(ActiveRecord::RecordNotFound) end end + + context 'with an uninstallable package' do + let(:param_path) { package.maven_metadatum.path } + + before do + package.update_column(:status, 1) + end + + it { expect { subject }.to raise_error(ActiveRecord::RecordNotFound) } + end end context 'within the project' do diff --git a/spec/finders/packages/npm/package_finder_spec.rb b/spec/finders/packages/npm/package_finder_spec.rb index f021d800f31..a995f3b96c4 100644 --- a/spec/finders/packages/npm/package_finder_spec.rb +++ b/spec/finders/packages/npm/package_finder_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' RSpec.describe ::Packages::Npm::PackageFinder do let_it_be_with_reload(:project) { create(:project)} - let_it_be(:package) { create(:npm_package, project: project) } + let_it_be_with_refind(:package) { create(:npm_package, project: project) } let(:project) { package.project } let(:package_name) { package.name } @@ -46,6 +46,14 @@ RSpec.describe ::Packages::Npm::PackageFinder do it { is_expected.to be_empty } end + + context 'with an uninstallable package' do + before do + package.update_column(:status, 1) + end + + it { is_expected.to be_empty } + end end subject { finder.execute } diff --git a/spec/finders/packages/nuget/package_finder_spec.rb b/spec/finders/packages/nuget/package_finder_spec.rb index 10b5f6c8ec2..59cca2d06dc 100644 --- a/spec/finders/packages/nuget/package_finder_spec.rb +++ b/spec/finders/packages/nuget/package_finder_spec.rb @@ -6,7 +6,7 @@ RSpec.describe Packages::Nuget::PackageFinder do let_it_be(:group) { create(:group) } let_it_be(:subgroup) { create(:group, parent: group) } let_it_be(:project) { create(:project, namespace: subgroup) } - let_it_be(:package1) { create(:nuget_package, project: project) } + let_it_be_with_refind(:package1) { create(:nuget_package, project: project) } let_it_be(:package2) { create(:nuget_package, name: package1.name, version: '2.0.0', project: project) } let_it_be(:package3) { create(:nuget_package, name: 'Another.Dummy.Package', project: project) } let_it_be(:other_package_1) { create(:nuget_package, name: package1.name, version: package1.version) } @@ -33,6 +33,14 @@ RSpec.describe Packages::Nuget::PackageFinder do it { is_expected.to be_empty } end + context 'with an uninstallable package' do + before do + package1.update_column(:status, 1) + end + + it { is_expected.to contain_exactly(package2) } + end + context 'with valid version' do let(:package_version) { '2.0.0' } diff --git a/spec/finders/packages/package_finder_spec.rb b/spec/finders/packages/package_finder_spec.rb index e8c7404a612..6a1d857dad4 100644 --- a/spec/finders/packages/package_finder_spec.rb +++ b/spec/finders/packages/package_finder_spec.rb @@ -4,7 +4,7 @@ require 'spec_helper' RSpec.describe ::Packages::PackageFinder do let_it_be(:project) { create(:project) } - let_it_be(:maven_package) { create(:maven_package, project: project) } + let_it_be_with_refind(:maven_package) { create(:maven_package, project: project) } describe '#execute' do let(:package_id) { maven_package.id } @@ -13,6 +13,16 @@ RSpec.describe ::Packages::PackageFinder do it { is_expected.to eq(maven_package) } + context 'with non-displayable package' do + before do + maven_package.update_column(:status, 1) + end + + it 'raises an exception' do + expect { subject }.to raise_exception(ActiveRecord::RecordNotFound) + end + end + context 'processing packages' do let_it_be(:nuget_package) { create(:nuget_package, project: project, name: Packages::Nuget::TEMPORARY_PACKAGE_NAME) } let(:package_id) { nuget_package.id } |