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

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2021-07-06 16:14:47 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2021-07-06 16:14:47 +0300
commit7ab0cadbbdf42fdd316941b3260e294577d649f4 (patch)
tree26ed9d750eb7706174afddb43a9e6fab210f2176 /spec/support
parent3aad3a0b6ffb1a0fe36db41f81e8bbd3728e5f80 (diff)
Add latest changes from gitlab-org/gitlab@14-0-stable-ee
Diffstat (limited to 'spec/support')
-rw-r--r--spec/support/shared_examples/lib/gitlab/local_and_remote_storage_migration_shared_examples.rb53
1 files changed, 53 insertions, 0 deletions
diff --git a/spec/support/shared_examples/lib/gitlab/local_and_remote_storage_migration_shared_examples.rb b/spec/support/shared_examples/lib/gitlab/local_and_remote_storage_migration_shared_examples.rb
new file mode 100644
index 00000000000..27ca27a9035
--- /dev/null
+++ b/spec/support/shared_examples/lib/gitlab/local_and_remote_storage_migration_shared_examples.rb
@@ -0,0 +1,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