Commit 94ab3594 authored by Shubham Kumar's avatar Shubham Kumar

Added error classes for specific backup rake task

Add error class for backup rake tasks

Changelog: added
parent a9244ed8
...@@ -2,4 +2,43 @@ ...@@ -2,4 +2,43 @@
module Backup module Backup
Error = Class.new(StandardError) Error = Class.new(StandardError)
class FileBackupError < Backup::Error
attr_reader :app_files_dir, :backup_tarball
def initialize(app_files_dir, backup_tarball)
@app_files_dir = app_files_dir
@backup_tarball = backup_tarball
end
def message
"Failed to create compressed file '#{backup_tarball}' when trying to backup the following paths: '#{app_files_dir}'"
end
end
class RepositoryBackupError < Backup::Error
attr_reader :container, :backup_repos_path
def initialize(container, backup_repos_path)
@container = container
@backup_repos_path = backup_repos_path
end
def message
"Failed to create compressed file '#{backup_repos_path}' when trying to backup the following paths: '#{container.disk_path}'"
end
end
class DatabaseBackupError < Backup::Error
attr_reader :config, :db_file_name
def initialize(config, db_file_name)
@config = config
@db_file_name = db_file_name
end
def message
"Failed to create compressed file '#{db_file_name}' when trying to backup the main database:\n - host: '#{config[:host]}'\n - port: '#{config[:port]}'\n - database: '#{config[:database]}'"
end
end
end end
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Backup::DatabaseBackupError do
let(:config) do
{
host: 'localhost',
port: 5432,
database: 'gitlabhq_test'
}
end
let(:db_file_name) { File.join(Gitlab.config.backup.path, 'db', 'database.sql.gz') }
subject { described_class.new(config, db_file_name) }
it { is_expected.to respond_to :config }
it { is_expected.to respond_to :db_file_name }
it 'expects exception message to include database file' do
expect(subject.message).to include("#{db_file_name}")
end
it 'expects exception message to include database paths being back-up' do
expect(subject.message).to include("#{config[:host]}")
expect(subject.message).to include("#{config[:port]}")
expect(subject.message).to include("#{config[:database]}")
end
end
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Backup::FileBackupError do
let_it_be(:lfs) { create(:lfs_object) }
let_it_be(:upload) { create(:upload) }
let(:backup_tarball) { '/tmp/backup/uploads' }
shared_examples 'includes backup path' do
it { is_expected.to respond_to :app_files_dir }
it { is_expected.to respond_to :backup_tarball }
it 'expects exception message to include file backup path location' do
expect(subject.message).to include("#{subject.backup_tarball}")
end
it 'expects exception message to include file being back-up' do
expect(subject.message).to include("#{subject.app_files_dir}")
end
end
context 'with lfs file' do
subject { described_class.new(lfs, backup_tarball) }
it_behaves_like 'includes backup path'
end
context 'with uploads file' do
subject { described_class.new(upload, backup_tarball) }
it_behaves_like 'includes backup path'
end
end
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Backup::RepositoryBackupError do
let_it_be(:snippet) { create(:snippet, content: 'foo', file_name: 'foo') }
let_it_be(:project) { create(:project, :repository) }
let_it_be(:wiki) { ProjectWiki.new(project, nil ) }
let(:backup_repos_path) { '/tmp/backup/repositories' }
shared_examples 'includes backup path' do
it { is_expected.to respond_to :container }
it { is_expected.to respond_to :backup_repos_path }
it 'expects exception message to include repo backup path location' do
expect(subject.message).to include("#{subject.backup_repos_path}")
end
it 'expects exception message to include container being back-up' do
expect(subject.message).to include("#{subject.container.disk_path}")
end
end
context 'with snippet repository' do
subject { described_class.new(snippet, backup_repos_path) }
it_behaves_like 'includes backup path'
end
context 'with project repository' do
subject { described_class.new(project, backup_repos_path) }
it_behaves_like 'includes backup path'
end
context 'with wiki repository' do
subject { described_class.new(wiki, backup_repos_path) }
it_behaves_like 'includes backup path'
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