gitlab-org--gitlab-foss/spec/services/packages/debian/create_distribution_service_spec.rb

122 lines
4.2 KiB
Ruby

# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Packages::Debian::CreateDistributionService do
RSpec.shared_examples 'Create Debian Distribution' do |expected_message, expected_components, expected_architectures|
it 'returns ServiceResponse', :aggregate_failures do
if expected_message.nil?
expect { response }
.to change { container.debian_distributions.klass.all.count }
.from(0).to(1)
.and change { container.debian_distributions.count }
.from(0).to(1)
.and change { container.debian_distributions.first&.components&.count }
.from(nil).to(expected_components.count)
.and change { container.debian_distributions.first&.architectures&.count }
.from(nil).to(expected_architectures.count)
.and not_change { Packages::Debian::ProjectComponentFile.count }
.and not_change { Packages::Debian::GroupComponentFile.count }
else
expect { response }
.to not_change { container.debian_distributions.klass.all.count }
.and not_change { container.debian_distributions.count }
.and not_change { Packages::Debian::ProjectComponent.count }
.and not_change { Packages::Debian::GroupComponent.count }
.and not_change { Packages::Debian::ProjectArchitecture.count }
.and not_change { Packages::Debian::GroupArchitecture.count }
.and not_change { Packages::Debian::ProjectComponentFile.count }
.and not_change { Packages::Debian::GroupComponentFile.count }
end
expect(response).to be_a(ServiceResponse)
expect(response.success?).to eq(expected_message.nil?)
expect(response.error?).to eq(!expected_message.nil?)
expect(response.message).to eq(expected_message)
distribution = response.payload[:distribution]
expect(distribution.persisted?).to eq(expected_message.nil?)
expect(distribution.container).to eq(container)
expect(distribution.creator).to eq(user)
params.each_pair do |name, value|
expect(distribution.send(name)).to eq(value)
end
expect(distribution.components.map(&:name)).to contain_exactly(*expected_components)
expect(distribution.architectures.map(&:name)).to contain_exactly(*expected_architectures)
end
end
shared_examples 'Debian Create Distribution Service' do
context 'with only the codename param' do
let(:params) { { codename: 'my-codename' } }
it_behaves_like 'Create Debian Distribution', nil, %w[main], %w[all amd64]
end
context 'with codename, components and architectures' do
let(:params) do
{
codename: 'my-codename',
components: %w[contrib non-free],
architectures: %w[arm64]
}
end
it_behaves_like 'Create Debian Distribution', nil, %w[contrib non-free], %w[all arm64]
end
context 'with invalid suite' do
let(:params) do
{
codename: 'my-codename',
suite: 'erroné'
}
end
it_behaves_like 'Create Debian Distribution', 'Suite is invalid', %w[], %w[]
end
context 'with invalid component name' do
let(:params) do
{
codename: 'my-codename',
components: %w[before erroné after],
architectures: %w[arm64]
}
end
it_behaves_like 'Create Debian Distribution', 'Component Name is invalid', %w[before erroné], %w[]
end
context 'with invalid architecture name' do
let(:params) do
{
codename: 'my-codename',
components: %w[contrib non-free],
architectures: %w[before erroné after']
}
end
it_behaves_like 'Create Debian Distribution', 'Architecture Name is invalid', %w[contrib non-free], %w[before erroné]
end
end
let_it_be(:user) { create(:user) }
subject { described_class.new(container, user, params) }
let(:response) { subject.execute }
context 'within a projet' do
let_it_be(:container) { create(:project) }
it_behaves_like 'Debian Create Distribution Service'
end
context 'within a group' do
let_it_be(:container) { create(:group) }
it_behaves_like 'Debian Create Distribution Service'
end
end