Welcome to mirror list, hosted at ThFree Co, Russian Federation.

create_distribution_service_spec.rb « debian « packages « services « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: ecf82c6a1dbcaa49124441b1e23045266d6f9558 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# 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|
    let_it_be(:container) { create(container_type) } # rubocop:disable Rails/SaveBang

    it 'returns ServiceResponse', :aggregate_failures do
      if expected_message.nil?
        expect(::Packages::Debian::GenerateDistributionWorker).to receive(:perform_async).with(container_type, an_instance_of(Integer))

        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(::Packages::Debian::GenerateDistributionWorker).not_to receive(:perform_async)
        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_type) { :project }

    it_behaves_like 'Debian Create Distribution Service'
  end

  context 'within a group' do
    let_it_be(:container_type) { :group }

    it_behaves_like 'Debian Create Distribution Service'
  end
end