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

local_and_remote_storage_migration_shared_examples.rb « gitlab « lib « shared_examples « support « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 27ca27a90354feb99a306573bbef00ad4d182b5d (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
# frozen_string_literal: true

RSpec.shared_examples 'local and remote storage migration' do
  let(:logger) { Logger.new("/dev/null") }
  let(:migrater) { described_class.new(logger) }

  using RSpec::Parameterized::TableSyntax

  where(:start_store, :end_store, :method) do
    ObjectStorage::Store::LOCAL  | ObjectStorage::Store::REMOTE | :migrate_to_remote_storage
    ObjectStorage::Store::REMOTE | ObjectStorage::Store::REMOTE | :migrate_to_remote_storage # rubocop:disable Lint/BinaryOperatorWithIdenticalOperands
    ObjectStorage::Store::REMOTE | ObjectStorage::Store::LOCAL  | :migrate_to_local_storage
    ObjectStorage::Store::LOCAL  | ObjectStorage::Store::LOCAL  | :migrate_to_local_storage # rubocop:disable Lint/BinaryOperatorWithIdenticalOperands
  end

  with_them do
    let(:storage_name) { end_store == ObjectStorage::Store::REMOTE ? 'object' : 'local' }

    it 'successfully migrates' do
      expect(logger).to receive(:info).with("Starting transfer to #{storage_name} storage")

      if start_store != end_store
        expect(logger).to receive(:info).with("Transferred #{item.class.name} ID #{item.id} with size #{item.size} to #{storage_name} storage")
      end

      expect(item.file_store).to eq(start_store)

      migrater.send(method)

      expect(item.reload.file_store).to eq(end_store)
    end
  end

  context 'when migration fails' do
    let(:start_store) { ObjectStorage::Store::LOCAL }

    it 'prints error' do
      expect_next_instance_of(item.file.class) do |file|
        expect(file).to receive(:migrate!).and_raise("error message")
      end

      expect(logger).to receive(:info).with("Starting transfer to object storage")

      expect(logger).to receive(:warn).with("Failed to transfer #{item.class.name} ID #{item.id} with error: error message")

      expect(item.file_store).to eq(start_store)

      migrater.migrate_to_remote_storage

      expect(item.reload.file_store).to eq(start_store)
    end
  end
end