diff options
Diffstat (limited to 'spec/presenters/packages/conan')
-rw-r--r-- | spec/presenters/packages/conan/package_presenter_spec.rb | 127 |
1 files changed, 78 insertions, 49 deletions
diff --git a/spec/presenters/packages/conan/package_presenter_spec.rb b/spec/presenters/packages/conan/package_presenter_spec.rb index 3bc649c5da4..4e8af752f3e 100644 --- a/spec/presenters/packages/conan/package_presenter_spec.rb +++ b/spec/presenters/packages/conan/package_presenter_spec.rb @@ -4,34 +4,39 @@ require 'spec_helper' RSpec.describe ::Packages::Conan::PackagePresenter do let_it_be(:user) { create(:user) } - let_it_be(:project) { create(:project) } + let_it_be(:package) { create(:conan_package) } + let_it_be(:project) { package.project } let_it_be(:conan_package_reference) { '123456789'} + let(:params) { { package_scope: :instance } } - RSpec.shared_examples 'not selecting a package with the wrong type' do - context 'with a nuget package with same name and version' do - let_it_be(:wrong_package) { create(:nuget_package, name: 'wrong', version: '1.0.0', project: project) } - - let(:recipe) { "#{wrong_package.name}/#{wrong_package.version}" } + shared_examples 'no existing package' do + context 'when package does not exist' do + let(:package) { nil } it { is_expected.to be_empty } end end - describe '#recipe_urls' do - subject { described_class.new(recipe, user, project).recipe_urls } - - context 'no existing package' do - let(:recipe) { "my-pkg/v1.0.0/#{project.full_path}/stable" } + shared_examples 'conan_file_metadatum is not found' do + context 'when no conan_file_metadatum exists' do + before do + package.package_files.each do |file| + file.conan_file_metadatum.delete + file.reload + end + end it { is_expected.to be_empty } end + end - it_behaves_like 'not selecting a package with the wrong type' + describe '#recipe_urls' do + subject { described_class.new(package, user, project, params).recipe_urls } - context 'existing package' do - let(:package) { create(:conan_package, project: project) } - let(:recipe) { package.conan_recipe } + it_behaves_like 'no existing package' + it_behaves_like 'conan_file_metadatum is not found' + context 'existing package' do let(:expected_result) do { "conanfile.py" => "#{Settings.build_base_gitlab_url}/api/v4/packages/conan/v1/files/#{package.conan_recipe_path}/0/export/conanfile.py", @@ -40,24 +45,37 @@ RSpec.describe ::Packages::Conan::PackagePresenter do end it { is_expected.to eq(expected_result) } - end - end - describe '#recipe_snapshot' do - subject { described_class.new(recipe, user, project).recipe_snapshot } + context 'when there are multiple channels for the same package' do + let(:conan_metadatum) { create(:conan_metadatum, package_channel: 'newest' ) } + let!(:newest_package) { create(:conan_package, name: package.name, version: package.version, project: project, conan_metadatum: conan_metadatum) } + + it { is_expected.to eq(expected_result) } + end - context 'no existing package' do - let(:recipe) { "my-pkg/v1.0.0/#{project.full_path}/stable" } + context 'with package_scope of project' do + # #recipe_file_url checks for params[:id] + let(:params) { { id: project.id } } - it { is_expected.to be_empty } + let(:expected_result) do + { + "conanfile.py" => "#{Settings.build_base_gitlab_url}/api/v4/projects/#{project.id}/packages/conan/v1/files/#{package.conan_recipe_path}/0/export/conanfile.py", + "conanmanifest.txt" => "#{Settings.build_base_gitlab_url}/api/v4/projects/#{project.id}/packages/conan/v1/files/#{package.conan_recipe_path}/0/export/conanmanifest.txt" + } + end + + it { is_expected.to eq(expected_result) } + end end + end - it_behaves_like 'not selecting a package with the wrong type' + describe '#recipe_snapshot' do + subject { described_class.new(package, user, project).recipe_snapshot } - context 'existing package' do - let(:package) { create(:conan_package, project: project) } - let(:recipe) { package.conan_recipe } + it_behaves_like 'no existing package' + it_behaves_like 'conan_file_metadatum is not found' + context 'existing package' do let(:expected_result) do { "conanfile.py" => '12345abcde', @@ -72,24 +90,23 @@ RSpec.describe ::Packages::Conan::PackagePresenter do describe '#package_urls' do let(:reference) { conan_package_reference } + let(:params) do + { + conan_package_reference: reference, + package_scope: :instance + } + end + subject do described_class.new( - recipe, user, project, conan_package_reference: reference + package, user, project, params ).package_urls end - context 'no existing package' do - let(:recipe) { "my-pkg/v1.0.0/#{project.full_path}/stable" } - - it { is_expected.to be_empty } - end - - it_behaves_like 'not selecting a package with the wrong type' + it_behaves_like 'no existing package' + it_behaves_like 'conan_file_metadatum is not found' context 'existing package' do - let(:package) { create(:conan_package, project: project) } - let(:recipe) { package.conan_recipe } - let(:expected_result) do { "conaninfo.txt" => "#{Settings.build_base_gitlab_url}/api/v4/packages/conan/v1/files/#{package.conan_recipe_path}/0/package/#{conan_package_reference}/0/conaninfo.txt", @@ -100,6 +117,26 @@ RSpec.describe ::Packages::Conan::PackagePresenter do it { is_expected.to eq(expected_result) } + context 'with package_scope of project' do + # #package_file_url checks for params[:id] + let(:params) do + { + conan_package_reference: reference, + id: project.id + } + end + + let(:expected_result) do + { + "conaninfo.txt" => "#{Settings.build_base_gitlab_url}/api/v4/projects/#{project.id}/packages/conan/v1/files/#{package.conan_recipe_path}/0/package/#{conan_package_reference}/0/conaninfo.txt", + "conanmanifest.txt" => "#{Settings.build_base_gitlab_url}/api/v4/projects/#{project.id}/packages/conan/v1/files/#{package.conan_recipe_path}/0/package/#{conan_package_reference}/0/conanmanifest.txt", + "conan_package.tgz" => "#{Settings.build_base_gitlab_url}/api/v4/projects/#{project.id}/packages/conan/v1/files/#{package.conan_recipe_path}/0/package/#{conan_package_reference}/0/conan_package.tgz" + } + end + + it { is_expected.to eq(expected_result) } + end + context 'multiple packages with different references' do let(:info_file) { create(:conan_package_file, :conan_package_info, package: package) } let(:manifest_file) { create(:conan_package_file, :conan_package_manifest, package: package) } @@ -131,7 +168,7 @@ RSpec.describe ::Packages::Conan::PackagePresenter do it 'returns empty if the reference does not exist' do result = described_class.new( - recipe, user, project, conan_package_reference: 'doesnotexist' + package, user, project, conan_package_reference: 'doesnotexist' ).package_urls expect(result).to eq({}) @@ -145,22 +182,14 @@ RSpec.describe ::Packages::Conan::PackagePresenter do subject do described_class.new( - recipe, user, project, conan_package_reference: reference + package, user, project, conan_package_reference: reference ).package_snapshot end - context 'no existing package' do - let(:recipe) { "my-pkg/v1.0.0/#{project.full_path}/stable" } - - it { is_expected.to be_empty } - end - - it_behaves_like 'not selecting a package with the wrong type' + it_behaves_like 'no existing package' + it_behaves_like 'conan_file_metadatum is not found' context 'existing package' do - let(:package) { create(:conan_package, project: project) } - let(:recipe) { package.conan_recipe } - let(:expected_result) do { "conaninfo.txt" => '12345abcde', |