Commit 7322476e authored by James Fargher's avatar James Fargher

Stop using BaseService

Refactor to use ServiceResponse
parent 79b62b32
# frozen_string_literal: true
module Projects
class UpdateRepositoryStorageService < BaseService
class UpdateRepositoryStorageService
Error = Class.new(StandardError)
SameFilesystemError = Class.new(Error)
attr_reader :repository_storage_move
delegate :destination_storage_name, to: :repository_storage_move
delegate :project, :destination_storage_name, to: :repository_storage_move
delegate :repository, to: :project
def initialize(repository_storage_move)
super(repository_storage_move.project)
@repository_storage_move = repository_storage_move
end
......@@ -31,7 +31,7 @@ module Projects
enqueue_housekeeping
success
ServiceResponse.success
rescue StandardError => e
project.transaction do
......@@ -41,7 +41,9 @@ module Projects
Gitlab::ErrorTracking.track_exception(e, project_path: project.full_path)
error(s_("UpdateRepositoryStorage|Error moving repository storage for %{project_full_path} - %{message}") % { project_full_path: project.full_path, message: e.message })
ServiceResponse.error(
message: s_("UpdateRepositoryStorage|Error moving repository storage for %{project_full_path} - %{message}") % { project_full_path: project.full_path, message: e.message }
)
end
private
......
......@@ -46,7 +46,7 @@ describe Projects::UpdateRepositoryStorageService do
result = subject.execute
expect(result[:status]).to eq(:success)
expect(result).to be_success
expect(project).not_to be_repository_read_only
expect(project.repository_storage).to eq('test_second_storage')
expect(gitlab_shell.repository_exists?('default', old_path)).to be(false)
......@@ -60,8 +60,8 @@ describe Projects::UpdateRepositoryStorageService do
it 'bails out and does nothing' do
result = subject.execute
expect(result[:status]).to eq(:error)
expect(result[:message]).to match(/SameFilesystemError/)
expect(result).to be_error
expect(result.message).to match(/SameFilesystemError/)
end
end
......@@ -79,7 +79,7 @@ describe Projects::UpdateRepositoryStorageService do
result = subject.execute
expect(result[:status]).to eq(:error)
expect(result).to be_error
expect(project).not_to be_repository_read_only
expect(project.repository_storage).to eq('default')
end
......@@ -100,7 +100,7 @@ describe Projects::UpdateRepositoryStorageService do
result = subject.execute
expect(result[:status]).to eq(:error)
expect(result).to be_error
expect(project).not_to be_repository_read_only
expect(project.repository_storage).to eq('default')
end
......@@ -122,7 +122,7 @@ describe Projects::UpdateRepositoryStorageService do
result = subject.execute
expect(result[:status]).to eq(:success)
expect(result).to be_success
expect(project.repository_storage).to eq('test_second_storage')
expect(project.reload_pool_repository).to be_nil
end
......
......@@ -49,7 +49,7 @@ RSpec.shared_examples 'moves repository to another storage' do |repository_type|
result = subject.execute
expect(result[:status]).to eq(:success)
expect(result).to be_success
expect(project).not_to be_repository_read_only
expect(project.repository_storage).to eq('test_second_storage')
expect(gitlab_shell.repository_exists?('default', old_project_repository_path)).to be(false)
......@@ -92,8 +92,8 @@ RSpec.shared_examples 'moves repository to another storage' do |repository_type|
it 'bails out and does nothing' do
result = subject.execute
expect(result[:status]).to eq(:error)
expect(result[:message]).to match(/SameFilesystemError/)
expect(result).to be_error
expect(result.message).to match(/SameFilesystemError/)
end
end
......@@ -118,7 +118,7 @@ RSpec.shared_examples 'moves repository to another storage' do |repository_type|
result = subject.execute
expect(result[:status]).to eq(:error)
expect(result).to be_error
expect(project).not_to be_repository_read_only
expect(project.repository_storage).to eq('default')
end
......@@ -146,7 +146,7 @@ RSpec.shared_examples 'moves repository to another storage' do |repository_type|
result = subject.execute
expect(result[:status]).to eq(:error)
expect(result).to be_error
expect(project).not_to be_repository_read_only
expect(project.repository_storage).to eq('default')
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment