summaryrefslogtreecommitdiff
path: root/spec/services/packages/debian/destroy_distribution_service_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/services/packages/debian/destroy_distribution_service_spec.rb')
-rw-r--r--spec/services/packages/debian/destroy_distribution_service_spec.rb71
1 files changed, 71 insertions, 0 deletions
diff --git a/spec/services/packages/debian/destroy_distribution_service_spec.rb b/spec/services/packages/debian/destroy_distribution_service_spec.rb
new file mode 100644
index 00000000000..cbb112af86f
--- /dev/null
+++ b/spec/services/packages/debian/destroy_distribution_service_spec.rb
@@ -0,0 +1,71 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe Packages::Debian::DestroyDistributionService do
+ RSpec.shared_examples 'Destroy Debian Distribution' do |expected_message|
+ it 'returns ServiceResponse', :aggregate_failures do
+ if expected_message.nil?
+ expect { response }
+ .to change { container.debian_distributions.klass.all.count }
+ .from(1).to(0)
+ .and change { container.debian_distributions.count }
+ .from(1).to(0)
+ .and change { component1.class.all.count }
+ .from(2).to(0)
+ .and change { architecture1.class.all.count }
+ .from(3).to(0)
+ else
+ expect { response }
+ .to not_change { container.debian_distributions.klass.all.count }
+ .and not_change { container.debian_distributions.count }
+ .and not_change { component1.class.all.count }
+ .and not_change { architecture1.class.all.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)
+
+ if expected_message.nil?
+ expect(response.payload).to eq({})
+ else
+ expect(response.payload).to eq(distribution: distribution)
+ end
+ end
+ end
+
+ RSpec.shared_examples 'Debian Destroy Distribution Service' do |container_type, can_freeze|
+ context "with a Debian #{container_type} distribution" do
+ let_it_be(:container, freeze: can_freeze) { create(container_type) } # rubocop:disable Rails/SaveBang
+ let_it_be(:distribution, freeze: can_freeze) { create("debian_#{container_type}_distribution", container: container) }
+ let_it_be(:component1, freeze: can_freeze) { create("debian_#{container_type}_component", distribution: distribution, name: 'component1') }
+ let_it_be(:component2, freeze: can_freeze) { create("debian_#{container_type}_component", distribution: distribution, name: 'component2') }
+ let_it_be(:architecture0, freeze: true) { create("debian_#{container_type}_architecture", distribution: distribution, name: 'all') }
+ let_it_be(:architecture1, freeze: can_freeze) { create("debian_#{container_type}_architecture", distribution: distribution, name: 'architecture1') }
+ let_it_be(:architecture2, freeze: can_freeze) { create("debian_#{container_type}_architecture", distribution: distribution, name: 'architecture2') }
+
+ subject { described_class.new(distribution) }
+
+ let(:response) { subject.execute }
+
+ context 'with a distribution' do
+ it_behaves_like 'Destroy Debian Distribution'
+ end
+
+ context 'when destroy fails' do
+ let(:distribution) { create("debian_#{container_type}_distribution", container: container) }
+
+ before do
+ expect(distribution).to receive(:destroy).and_return(false)
+ end
+
+ it_behaves_like 'Destroy Debian Distribution', "Unable to destroy Debian #{container_type} distribution"
+ end
+ end
+ end
+
+ it_behaves_like 'Debian Destroy Distribution Service', :project, true
+ it_behaves_like 'Debian Destroy Distribution Service', :group, false
+end