diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-07-20 15:26:25 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-07-20 15:26:25 +0300 |
commit | a09983ae35713f5a2bbb100981116d31ce99826e (patch) | |
tree | 2ee2af7bd104d57086db360a7e6d8c9d5d43667a /spec/finders/packages/conan | |
parent | 18c5ab32b738c0b6ecb4d0df3994000482f34bd8 (diff) |
Add latest changes from gitlab-org/gitlab@13-2-stable-ee
Diffstat (limited to 'spec/finders/packages/conan')
-rw-r--r-- | spec/finders/packages/conan/package_file_finder_spec.rb | 64 | ||||
-rw-r--r-- | spec/finders/packages/conan/package_finder_spec.rb | 22 |
2 files changed, 86 insertions, 0 deletions
diff --git a/spec/finders/packages/conan/package_file_finder_spec.rb b/spec/finders/packages/conan/package_file_finder_spec.rb new file mode 100644 index 00000000000..d0c9efa1418 --- /dev/null +++ b/spec/finders/packages/conan/package_file_finder_spec.rb @@ -0,0 +1,64 @@ +# frozen_string_literal: true +require 'spec_helper' + +RSpec.describe ::Packages::Conan::PackageFileFinder do + let_it_be(:package) { create(:conan_package) } + let_it_be(:package_file) { package.package_files.first } + let(:package_file_name) { package_file.file_name } + let(:params) { {} } + + RSpec.shared_examples 'package file finder examples' do + it { is_expected.to eq(package_file) } + + context 'with conan_file_type' do + # conan packages contain a conanmanifest.txt file for both conan_file_types + let(:package_file_name) { 'conanmanifest.txt' } + let(:params) { { conan_file_type: :recipe_file } } + + it { expect(subject.conan_file_type).to eq('recipe_file') } + end + + context 'with conan_package_reference' do + let_it_be(:other_package) { create(:conan_package) } + let_it_be(:package_file_name) { 'conan_package.tgz' } + let_it_be(:package_file) { package.package_files.find_by(file_name: package_file_name) } + + let(:params) do + { conan_package_reference: package_file.conan_file_metadatum.conan_package_reference } + end + + it { expect(subject).to eq(package_file) } + end + + context 'with file_name_like' do + let(:package_file_name) { package_file.file_name.upcase } + let(:params) { { with_file_name_like: true } } + + it { is_expected.to eq(package_file) } + end + end + + describe '#execute' do + subject { described_class.new(package, package_file_name, params).execute } + + it_behaves_like 'package file finder examples' + + context 'with unknown file_name' do + let(:package_file_name) { 'unknown.jpg' } + + it { expect(subject).to be_nil } + end + end + + describe '#execute!' do + subject { described_class.new(package, package_file_name, params).execute! } + + it_behaves_like 'package file finder examples' + + context 'with unknown file_name' do + let(:package_file_name) { 'unknown.jpg' } + + it { expect { subject }.to raise_error(ActiveRecord::RecordNotFound) } + end + end +end diff --git a/spec/finders/packages/conan/package_finder_spec.rb b/spec/finders/packages/conan/package_finder_spec.rb new file mode 100644 index 00000000000..936a0e5ff4b --- /dev/null +++ b/spec/finders/packages/conan/package_finder_spec.rb @@ -0,0 +1,22 @@ +# frozen_string_literal: true +require 'spec_helper' + +RSpec.describe ::Packages::Conan::PackageFinder do + let_it_be(:user) { create(:user) } + let_it_be(:project) { create(:project, :public) } + + describe '#execute' do + let!(:conan_package) { create(:conan_package, project: project) } + let!(:conan_package2) { create(:conan_package, project: project) } + + subject { described_class.new(user, query: query).execute } + + context 'packages that are not visible to user' do + 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]}%" } + + it { is_expected.to eq [conan_package, conan_package2] } + end + end +end |