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

process_changes_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: 98b531bde1050c2e5962b6ab57906dc9bb025eee (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
# frozen_string_literal: true
require 'spec_helper'

RSpec.describe Packages::Debian::ProcessChangesService do
  describe '#execute' do
    let_it_be(:user) { create(:user) }
    let_it_be_with_reload(:distribution) { create(:debian_project_distribution, :with_file, codename: 'unstable') }
    let_it_be(:incoming) { create(:debian_incoming, project: distribution.project) }

    let(:package_file) { incoming.package_files.last }

    subject { described_class.new(package_file, user) }

    context 'with valid package file' do
      it 'updates package and package file', :aggregate_failures do
        expect { subject.execute }
          .to change { Packages::Package.count }.from(1).to(2)
          .and not_change { Packages::PackageFile.count }
          .and change { incoming.package_files.count }.from(7).to(0)

        created_package = Packages::Package.last
        expect(created_package.name).to eq 'sample'
        expect(created_package.version).to eq '1.2.3~alpha2'
        expect(created_package.creator).to eq user
      end
    end

    context 'with invalid package file' do
      let(:package_file) { incoming.package_files.first }

      it 'raise ExtractionError', :aggregate_failures do
        expect { subject.execute }
          .to not_change { Packages::Package.count }
          .and not_change { Packages::PackageFile.count }
          .and not_change { incoming.package_files.count }
          .and not_change { distribution.reload.needs_update? }
          .and raise_error(Packages::Debian::ExtractChangesMetadataService::ExtractionError, 'is not a changes file')
      end
    end

    context 'when creating package fails' do
      before do
        allow_next_instance_of(::Packages::Debian::FindOrCreatePackageService) do |find_or_create_package_service|
          expect(find_or_create_package_service).to receive(:execute).and_raise(ActiveRecord::ConnectionTimeoutError, 'connect timeout')
        end
      end

      it 'remove the package file', :aggregate_failures do
        expect { subject.execute }
          .to not_change { Packages::Package.count }
          .and not_change { Packages::PackageFile.count }
          .and not_change { incoming.package_files.count }
          .and not_change { distribution.reload.needs_update? }
          .and raise_error(ActiveRecord::ConnectionTimeoutError, 'connect timeout')
      end
    end
  end
end