Commit 708ebe38 authored by Michael Kozono's avatar Michael Kozono

Primary supports api/transfers/job_artifact/:id

parent 6e368017
module Gitlab
module Geo
class JobArtifactUploader < FileUploader
def execute
job_artifact = ::Ci::JobArtifact.find_by(id: object_db_id)
unless job_artifact.present?
return error('Job artifact not found')
end
unless job_artifact.file.present? && job_artifact.file.exists?
return error('Job artifact does not have a file')
end
success(job_artifact.file)
end
end
end
end
require 'spec_helper'
describe Gitlab::Geo::JobArtifactUploader, :geo do
context '#execute' do
subject { described_class.new(job_artifact.id, {}).execute }
context 'when the job artifact exists' do
before do
expect(::Ci::JobArtifact).to receive(:find_by).with(id: job_artifact.id).and_return(job_artifact)
end
context 'when the job artifact is an archive file_type and has a file' do
let(:job_artifact) { create(:ci_job_artifact, :archive) }
it 'returns the file in a success hash' do
expect(subject).to eq(code: :ok, message: 'Success', file: job_artifact.file)
end
end
context 'when the job artifact is an metadata file_type and has a file' do
let(:job_artifact) { create(:ci_job_artifact, :metadata) }
it 'returns the file in a success hash' do
expect(subject).to eq(code: :ok, message: 'Success', file: job_artifact.file)
end
end
context 'when the job artifact does not have a file' do
let(:job_artifact) { create(:ci_job_artifact) }
it 'returns an error hash' do
expect(subject).to eq(code: :not_found, message: "Job artifact does not have a file")
end
end
end
context 'when the job artifact does not exist' do
let(:job_artifact) { double(id: 10000) }
it 'returns an error hash' do
expect(subject).to eq(code: :not_found, message: "Job artifact not found")
end
end
end
end
......@@ -180,5 +180,28 @@ describe Geo::FileUploadService do
expect(service.execute).to be_nil
end
end
context 'job artifact' do
let(:job_artifact) { create(:ci_job_artifact, :with_file) }
let(:params) { { id: job_artifact.id, type: 'job_artifact' } }
let(:job_artifact_transfer) { Gitlab::Geo::JobArtifactTransfer.new(job_artifact) }
let(:transfer_request) { Gitlab::Geo::TransferRequest.new(job_artifact_transfer.request_data) }
let(:req_header) { transfer_request.headers['Authorization'] }
it 'sends job artifact file' do
service = described_class.new(params, req_header)
response = service.execute
expect(response[:code]).to eq(:ok)
expect(response[:file].path).to eq(job_artifact.file.path)
end
it 'returns nil if no authorization' do
service = described_class.new(params, nil)
expect(service.execute).to be_nil
end
end
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