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

Stop using BaseService

Refactor to use ServiceResponse
parent 79b62b32
# frozen_string_literal: true # frozen_string_literal: true
module Projects module Projects
class UpdateRepositoryStorageService < BaseService class UpdateRepositoryStorageService
Error = Class.new(StandardError) Error = Class.new(StandardError)
SameFilesystemError = Class.new(Error) SameFilesystemError = Class.new(Error)
attr_reader :repository_storage_move 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) def initialize(repository_storage_move)
super(repository_storage_move.project)
@repository_storage_move = repository_storage_move @repository_storage_move = repository_storage_move
end end
...@@ -31,7 +31,7 @@ module Projects ...@@ -31,7 +31,7 @@ module Projects
enqueue_housekeeping enqueue_housekeeping
success ServiceResponse.success
rescue StandardError => e rescue StandardError => e
project.transaction do project.transaction do
...@@ -41,7 +41,9 @@ module Projects ...@@ -41,7 +41,9 @@ module Projects
Gitlab::ErrorTracking.track_exception(e, project_path: project.full_path) 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 end
private private
......
...@@ -46,7 +46,7 @@ describe Projects::UpdateRepositoryStorageService do ...@@ -46,7 +46,7 @@ describe Projects::UpdateRepositoryStorageService do
result = subject.execute result = subject.execute
expect(result[:status]).to eq(:success) expect(result).to be_success
expect(project).not_to be_repository_read_only expect(project).not_to be_repository_read_only
expect(project.repository_storage).to eq('test_second_storage') expect(project.repository_storage).to eq('test_second_storage')
expect(gitlab_shell.repository_exists?('default', old_path)).to be(false) expect(gitlab_shell.repository_exists?('default', old_path)).to be(false)
...@@ -60,8 +60,8 @@ describe Projects::UpdateRepositoryStorageService do ...@@ -60,8 +60,8 @@ describe Projects::UpdateRepositoryStorageService do
it 'bails out and does nothing' do it 'bails out and does nothing' do
result = subject.execute result = subject.execute
expect(result[:status]).to eq(:error) expect(result).to be_error
expect(result[:message]).to match(/SameFilesystemError/) expect(result.message).to match(/SameFilesystemError/)
end end
end end
...@@ -79,7 +79,7 @@ describe Projects::UpdateRepositoryStorageService do ...@@ -79,7 +79,7 @@ describe Projects::UpdateRepositoryStorageService do
result = subject.execute result = subject.execute
expect(result[:status]).to eq(:error) expect(result).to be_error
expect(project).not_to be_repository_read_only expect(project).not_to be_repository_read_only
expect(project.repository_storage).to eq('default') expect(project.repository_storage).to eq('default')
end end
...@@ -100,7 +100,7 @@ describe Projects::UpdateRepositoryStorageService do ...@@ -100,7 +100,7 @@ describe Projects::UpdateRepositoryStorageService do
result = subject.execute result = subject.execute
expect(result[:status]).to eq(:error) expect(result).to be_error
expect(project).not_to be_repository_read_only expect(project).not_to be_repository_read_only
expect(project.repository_storage).to eq('default') expect(project.repository_storage).to eq('default')
end end
...@@ -122,7 +122,7 @@ describe Projects::UpdateRepositoryStorageService do ...@@ -122,7 +122,7 @@ describe Projects::UpdateRepositoryStorageService do
result = subject.execute 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.repository_storage).to eq('test_second_storage')
expect(project.reload_pool_repository).to be_nil expect(project.reload_pool_repository).to be_nil
end end
......
...@@ -49,7 +49,7 @@ RSpec.shared_examples 'moves repository to another storage' do |repository_type| ...@@ -49,7 +49,7 @@ RSpec.shared_examples 'moves repository to another storage' do |repository_type|
result = subject.execute result = subject.execute
expect(result[:status]).to eq(:success) expect(result).to be_success
expect(project).not_to be_repository_read_only expect(project).not_to be_repository_read_only
expect(project.repository_storage).to eq('test_second_storage') expect(project.repository_storage).to eq('test_second_storage')
expect(gitlab_shell.repository_exists?('default', old_project_repository_path)).to be(false) 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| ...@@ -92,8 +92,8 @@ RSpec.shared_examples 'moves repository to another storage' do |repository_type|
it 'bails out and does nothing' do it 'bails out and does nothing' do
result = subject.execute result = subject.execute
expect(result[:status]).to eq(:error) expect(result).to be_error
expect(result[:message]).to match(/SameFilesystemError/) expect(result.message).to match(/SameFilesystemError/)
end end
end end
...@@ -118,7 +118,7 @@ RSpec.shared_examples 'moves repository to another storage' do |repository_type| ...@@ -118,7 +118,7 @@ RSpec.shared_examples 'moves repository to another storage' do |repository_type|
result = subject.execute result = subject.execute
expect(result[:status]).to eq(:error) expect(result).to be_error
expect(project).not_to be_repository_read_only expect(project).not_to be_repository_read_only
expect(project.repository_storage).to eq('default') expect(project.repository_storage).to eq('default')
end end
...@@ -146,7 +146,7 @@ RSpec.shared_examples 'moves repository to another storage' do |repository_type| ...@@ -146,7 +146,7 @@ RSpec.shared_examples 'moves repository to another storage' do |repository_type|
result = subject.execute result = subject.execute
expect(result[:status]).to eq(:error) expect(result).to be_error
expect(project).not_to be_repository_read_only expect(project).not_to be_repository_read_only
expect(project.repository_storage).to eq('default') expect(project.repository_storage).to eq('default')
end 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