2019-03-30 07:15:48 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-03-30 15:45:59 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-24 15:08:50 +00:00
|
|
|
RSpec.describe ProjectExportWorker do
|
2018-03-30 15:45:59 +00:00
|
|
|
let!(:user) { create(:user) }
|
|
|
|
let!(:project) { create(:project) }
|
|
|
|
|
|
|
|
subject { described_class.new }
|
|
|
|
|
|
|
|
describe '#perform' do
|
2020-03-12 09:09:55 +00:00
|
|
|
before do
|
|
|
|
allow_next_instance_of(described_class) do |job|
|
|
|
|
allow(job).to receive(:jid).and_return(SecureRandom.hex(8))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-03-30 15:45:59 +00:00
|
|
|
context 'when it succeeds' do
|
|
|
|
it 'calls the ExportService' do
|
2020-04-30 15:09:46 +00:00
|
|
|
expect_next_instance_of(::Projects::ImportExport::ExportService) do |service|
|
|
|
|
expect(service).to receive(:execute)
|
|
|
|
end
|
2018-03-30 15:45:59 +00:00
|
|
|
|
|
|
|
subject.perform(user.id, project.id, { 'klass' => 'Gitlab::ImportExport::AfterExportStrategies::DownloadNotificationStrategy' })
|
|
|
|
end
|
2020-03-12 09:09:55 +00:00
|
|
|
|
|
|
|
context 'export job' do
|
|
|
|
before do
|
2020-04-30 15:09:46 +00:00
|
|
|
allow_next_instance_of(::Projects::ImportExport::ExportService) do |service|
|
|
|
|
allow(service).to receive(:execute)
|
|
|
|
end
|
2020-03-12 09:09:55 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'creates an export job record for the project' do
|
|
|
|
expect { subject.perform(user.id, project.id, {}) }.to change { project.export_jobs.count }.from(0).to(1)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'sets the export job status to started' do
|
|
|
|
expect_next_instance_of(ProjectExportJob) do |job|
|
|
|
|
expect(job).to receive(:start)
|
|
|
|
end
|
|
|
|
|
|
|
|
subject.perform(user.id, project.id, {})
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'sets the export job status to finished' do
|
|
|
|
expect_next_instance_of(ProjectExportJob) do |job|
|
|
|
|
expect(job).to receive(:finish)
|
|
|
|
end
|
|
|
|
|
|
|
|
subject.perform(user.id, project.id, {})
|
|
|
|
end
|
|
|
|
end
|
2018-03-30 15:45:59 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'when it fails' do
|
2020-03-12 09:09:55 +00:00
|
|
|
it 'does not raise an exception when strategy is invalid' do
|
2020-05-13 12:07:54 +00:00
|
|
|
expect(::Projects::ImportExport::ExportService).not_to receive(:new)
|
2018-03-30 15:45:59 +00:00
|
|
|
|
2020-03-12 09:09:55 +00:00
|
|
|
expect { subject.perform(user.id, project.id, { 'klass' => 'Whatever' }) }.not_to raise_error
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not raise error when project cannot be found' do
|
2020-04-01 15:07:45 +00:00
|
|
|
expect { subject.perform(user.id, non_existing_record_id, {}) }.not_to raise_error
|
2020-03-12 09:09:55 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not raise error when user cannot be found' do
|
2020-04-01 15:07:45 +00:00
|
|
|
expect { subject.perform(non_existing_record_id, project.id, {}) }.not_to raise_error
|
2018-03-30 15:45:59 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2020-07-01 15:08:45 +00:00
|
|
|
|
|
|
|
describe 'sidekiq options' do
|
|
|
|
it 'disables retry' do
|
|
|
|
expect(described_class.sidekiq_options['retry']).to eq(false)
|
|
|
|
end
|
|
|
|
|
2020-10-16 03:08:29 +00:00
|
|
|
it 'disables dead' do
|
|
|
|
expect(described_class.sidekiq_options['dead']).to eq(false)
|
|
|
|
end
|
|
|
|
|
2020-07-01 15:08:45 +00:00
|
|
|
it 'sets default status expiration' do
|
|
|
|
expect(described_class.sidekiq_options['status_expiration']).to eq(StuckExportJobsWorker::EXPORT_JOBS_EXPIRATION)
|
|
|
|
end
|
|
|
|
end
|
2018-03-30 15:45:59 +00:00
|
|
|
end
|