debian-mirror-gitlab/spec/presenters/packages/conan/package_presenter_spec.rb

212 lines
7.4 KiB
Ruby
Raw Normal View History

2020-07-28 23:09:34 +05:30
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe ::Packages::Conan::PackagePresenter do
let_it_be(:user) { create(:user) }
2020-11-24 15:15:51 +05:30
let_it_be(:package) { create(:conan_package) }
let_it_be(:project) { package.project }
2020-07-28 23:09:34 +05:30
let_it_be(:conan_package_reference) { '123456789'}
2021-06-08 01:23:25 +05:30
2020-11-24 15:15:51 +05:30
let(:params) { { package_scope: :instance } }
2020-07-28 23:09:34 +05:30
2020-11-24 15:15:51 +05:30
shared_examples 'no existing package' do
context 'when package does not exist' do
let(:package) { nil }
2020-07-28 23:09:34 +05:30
it { is_expected.to be_empty }
end
end
2020-11-24 15:15:51 +05:30
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
2020-07-28 23:09:34 +05:30
it { is_expected.to be_empty }
end
2020-11-24 15:15:51 +05:30
end
2020-07-28 23:09:34 +05:30
2020-11-24 15:15:51 +05:30
describe '#recipe_urls' do
subject { described_class.new(package, user, project, params).recipe_urls }
2020-07-28 23:09:34 +05:30
2020-11-24 15:15:51 +05:30
it_behaves_like 'no existing package'
it_behaves_like 'conan_file_metadatum is not found'
2020-07-28 23:09:34 +05:30
2020-11-24 15:15:51 +05:30
context 'existing package' do
2020-07-28 23:09:34 +05:30
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",
"conanmanifest.txt" => "#{Settings.build_base_gitlab_url}/api/v4/packages/conan/v1/files/#{package.conan_recipe_path}/0/export/conanmanifest.txt"
}
end
it { is_expected.to eq(expected_result) }
2020-11-24 15:15:51 +05:30
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
2020-07-28 23:09:34 +05:30
2020-11-24 15:15:51 +05:30
context 'with package_scope of project' do
# #recipe_file_url checks for params[:id]
let(:params) { { id: project.id } }
2020-07-28 23:09:34 +05:30
2020-11-24 15:15:51 +05:30
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
2020-07-28 23:09:34 +05:30
end
2020-11-24 15:15:51 +05:30
end
2020-07-28 23:09:34 +05:30
2020-11-24 15:15:51 +05:30
describe '#recipe_snapshot' do
subject { described_class.new(package, user, project).recipe_snapshot }
2020-07-28 23:09:34 +05:30
2020-11-24 15:15:51 +05:30
it_behaves_like 'no existing package'
it_behaves_like 'conan_file_metadatum is not found'
2020-07-28 23:09:34 +05:30
2020-11-24 15:15:51 +05:30
context 'existing package' do
2020-07-28 23:09:34 +05:30
let(:expected_result) do
{
"conanfile.py" => '12345abcde',
"conanmanifest.txt" => '12345abcde'
}
end
it { is_expected.to eq(expected_result) }
end
end
describe '#package_urls' do
let(:reference) { conan_package_reference }
2020-11-24 15:15:51 +05:30
let(:params) do
{
conan_package_reference: reference,
package_scope: :instance
}
end
2020-07-28 23:09:34 +05:30
subject do
described_class.new(
2020-11-24 15:15:51 +05:30
package, user, project, params
2020-07-28 23:09:34 +05:30
).package_urls
end
2020-11-24 15:15:51 +05:30
it_behaves_like 'no existing package'
it_behaves_like 'conan_file_metadatum is not found'
2020-07-28 23:09:34 +05:30
context 'existing package' do
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",
"conanmanifest.txt" => "#{Settings.build_base_gitlab_url}/api/v4/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/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) }
2020-11-24 15:15:51 +05:30
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
2020-07-28 23:09:34 +05:30
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) }
let(:package_file) { create(:conan_package_file, :conan_package, package: package) }
let(:alternative_reference) { 'abcdefghi' }
before do
[info_file, manifest_file, package_file].each do |file|
file.conan_file_metadatum.conan_package_reference = alternative_reference
2021-04-29 21:17:54 +05:30
file.save!
2020-07-28 23:09:34 +05:30
end
end
it { is_expected.to eq(expected_result) }
context 'requesting the alternative reference' do
let(:reference) { alternative_reference }
let(:expected_result) do
{
"conaninfo.txt" => "#{Settings.build_base_gitlab_url}/api/v4/packages/conan/v1/files/#{package.conan_recipe_path}/0/package/#{alternative_reference}/0/conaninfo.txt",
"conanmanifest.txt" => "#{Settings.build_base_gitlab_url}/api/v4/packages/conan/v1/files/#{package.conan_recipe_path}/0/package/#{alternative_reference}/0/conanmanifest.txt",
"conan_package.tgz" => "#{Settings.build_base_gitlab_url}/api/v4/packages/conan/v1/files/#{package.conan_recipe_path}/0/package/#{alternative_reference}/0/conan_package.tgz"
}
end
it { is_expected.to eq(expected_result) }
end
it 'returns empty if the reference does not exist' do
result = described_class.new(
2020-11-24 15:15:51 +05:30
package, user, project, conan_package_reference: 'doesnotexist'
2020-07-28 23:09:34 +05:30
).package_urls
expect(result).to eq({})
end
end
end
end
describe '#package_snapshot' do
let(:reference) { conan_package_reference }
subject do
described_class.new(
2020-11-24 15:15:51 +05:30
package, user, project, conan_package_reference: reference
2020-07-28 23:09:34 +05:30
).package_snapshot
end
2020-11-24 15:15:51 +05:30
it_behaves_like 'no existing package'
it_behaves_like 'conan_file_metadatum is not found'
2020-07-28 23:09:34 +05:30
context 'existing package' do
let(:expected_result) do
{
"conaninfo.txt" => '12345abcde',
"conanmanifest.txt" => '12345abcde',
"conan_package.tgz" => '12345abcde'
}
end
it { is_expected.to eq(expected_result) }
context 'when requested with invalid reference' do
let(:reference) { 'invalid' }
it { is_expected.to eq({}) }
end
end
end
end