debian-mirror-gitlab/spec/services/packages/debian/create_distribution_service_spec.rb

128 lines
4.5 KiB
Ruby
Raw Normal View History

2021-03-11 19:13:27 +05:30
# 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|
2021-09-04 01:27:46 +05:30
let_it_be(:container) { create(container_type) } # rubocop:disable Rails/SaveBang
2021-03-11 19:13:27 +05:30
it 'returns ServiceResponse', :aggregate_failures do
if expected_message.nil?
2021-09-04 01:27:46 +05:30
expect(::Packages::Debian::GenerateDistributionWorker).to receive(:perform_async).with(container_type, an_instance_of(Integer))
2021-03-11 19:13:27 +05:30
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
2021-09-04 01:27:46 +05:30
expect(::Packages::Debian::GenerateDistributionWorker).not_to receive(:perform_async)
2021-03-11 19:13:27 +05:30
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
2021-09-04 01:27:46 +05:30
let_it_be(:container_type) { :project }
2021-03-11 19:13:27 +05:30
it_behaves_like 'Debian Create Distribution Service'
end
context 'within a group' do
2021-09-04 01:27:46 +05:30
let_it_be(:container_type) { :group }
2021-03-11 19:13:27 +05:30
it_behaves_like 'Debian Create Distribution Service'
end
end