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

lfs_object_importer_spec.rb « importers « bitbucket_import « gitlab « lib « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 4d56853032a9c054099063bc34c96f3015470348 (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
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Gitlab::BitbucketImport::Importers::LfsObjectImporter, feature_category: :importers do
  let_it_be(:project) { create(:project) }
  let(:oid) { 'a' * 64 }

  let(:lfs_attributes) do
    {
      'oid' => oid,
      'size' => 1,
      'link' => 'http://www.gitlab.com/lfs_objects/oid',
      'headers' => { 'X-Some-Header' => '456' }
    }
  end

  let(:importer) { described_class.new(project, lfs_attributes) }

  describe '#execute' do
    it 'calls the LfsDownloadService with the lfs object attributes' do
      expect_next_instance_of(
        Projects::LfsPointers::LfsDownloadService, project, have_attributes(lfs_attributes)
      ) do |service|
        expect(service).to receive(:execute).and_return(ServiceResponse.success)
      end

      importer.execute
    end

    context 'when the object is not valid' do
      let(:oid) { 'invalid' }

      it 'tracks the validation errors and does not continue' do
        expect(Gitlab::Import::ImportFailureService).to receive(:track).once

        expect(Projects::LfsPointers::LfsDownloadService).not_to receive(:new)

        importer.execute
      end
    end

    context 'when an error is raised' do
      let(:exception) { StandardError.new('messsage') }

      before do
        allow_next_instance_of(Projects::LfsPointers::LfsDownloadService) do |service|
          allow(service).to receive(:execute).and_raise(exception)
        end
      end

      it 'rescues and logs the exception' do
        expect(Gitlab::Import::ImportFailureService)
          .to receive(:track)
          .with(hash_including(exception: exception))

        importer.execute
      end
    end

    it 'logs its progress' do
      allow_next_instance_of(Projects::LfsPointers::LfsDownloadService) do |service|
        allow(service).to receive(:execute).and_return(ServiceResponse.success)
      end

      common_log_message = {
        oid: oid,
        import_stage: 'import_lfs_object',
        class: described_class.name,
        project_id: project.id,
        project_path: project.full_path
      }

      expect(Gitlab::BitbucketImport::Logger)
        .to receive(:info).with(common_log_message.merge(message: 'starting')).and_call_original
      expect(Gitlab::BitbucketImport::Logger)
        .to receive(:info).with(common_log_message.merge(message: 'finished')).and_call_original

      importer.execute
    end
  end
end