diff options
author | Grzegorz Bizon <grzegorz@gitlab.com> | 2017-06-08 08:29:35 +0300 |
---|---|---|
committer | Kamil TrzciĆski <ayufan@ayufan.eu> | 2018-02-28 22:00:27 +0300 |
commit | 52c3b8f31264230814d2ffa79d0987c1491676b3 (patch) | |
tree | d5827bc9bd891c1dd602eb3cdd4e4062d2e85589 /spec/requests/api/jobs_spec.rb | |
parent | 64701b51aeacf4f4f932f205a2d831880b757a43 (diff) |
Merge branch 'zj-object-store-artifacts' into 'master'
Object store for artifacts
Closes gitlab-ce#29203
See merge request !1762
Diffstat (limited to 'spec/requests/api/jobs_spec.rb')
-rw-r--r-- | spec/requests/api/jobs_spec.rb | 68 |
1 files changed, 46 insertions, 22 deletions
diff --git a/spec/requests/api/jobs_spec.rb b/spec/requests/api/jobs_spec.rb index 8d647eb1c7e..548b612b5b0 100644 --- a/spec/requests/api/jobs_spec.rb +++ b/spec/requests/api/jobs_spec.rb @@ -1,17 +1,17 @@ require 'spec_helper' describe API::Jobs, :api do - let!(:project) do + let(:project) do create(:project, :repository, public_builds: false) end - let!(:pipeline) do + let(:pipeline) do create(:ci_empty_pipeline, project: project, sha: project.commit.id, ref: project.default_branch) end - let!(:job) { create(:ci_build, pipeline: pipeline) } + let(:job) { create(:ci_build, pipeline: pipeline) } let(:user) { create(:user) } let(:api_user) { user } @@ -26,6 +26,7 @@ describe API::Jobs, :api do let(:query) { Hash.new } before do + job get api("/projects/#{project.id}/jobs", api_user), query end @@ -89,6 +90,7 @@ describe API::Jobs, :api do let(:query) { Hash.new } before do + job get api("/projects/#{project.id}/pipelines/#{pipeline.id}/jobs", api_user), query end @@ -190,30 +192,41 @@ describe API::Jobs, :api do describe 'GET /projects/:id/jobs/:job_id/artifacts' do before do + stub_artifacts_object_storage get api("/projects/#{project.id}/jobs/#{job.id}/artifacts", api_user) end context 'job with artifacts' do - let(:job) { create(:ci_build, :artifacts, pipeline: pipeline) } + context 'when artifacts are stored locally' do + let(:job) { create(:ci_build, :artifacts, pipeline: pipeline) } - context 'authorized user' do - let(:download_headers) do - { 'Content-Transfer-Encoding' => 'binary', - 'Content-Disposition' => 'attachment; filename=ci_build_artifacts.zip' } + context 'authorized user' do + let(:download_headers) do + { 'Content-Transfer-Encoding' => 'binary', + 'Content-Disposition' => 'attachment; filename=ci_build_artifacts.zip' } + end + + it 'returns specific job artifacts' do + expect(response).to have_http_status(200) + expect(response.headers).to include(download_headers) + expect(response.body).to match_file(job.artifacts_file.file.file) + end end - it 'returns specific job artifacts' do - expect(response).to have_http_status(200) - expect(response.headers).to include(download_headers) - expect(response.body).to match_file(job.artifacts_file.file.file) + context 'unauthorized user' do + let(:api_user) { nil } + + it 'does not return specific job artifacts' do + expect(response).to have_http_status(401) + end end end - context 'unauthorized user' do - let(:api_user) { nil } + context 'when artifacts are stored remotely' do + let(:job) { create(:ci_build, :artifacts, :remote_store, pipeline: pipeline) } - it 'does not return specific job artifacts' do - expect(response).to have_http_status(401) + it 'returns location redirect' do + expect(response).to have_http_status(302) end end end @@ -228,6 +241,7 @@ describe API::Jobs, :api do let(:job) { create(:ci_build, :artifacts, pipeline: pipeline) } before do + stub_artifacts_object_storage job.success end @@ -283,14 +297,24 @@ describe API::Jobs, :api do context 'find proper job' do shared_examples 'a valid file' do - let(:download_headers) do - { 'Content-Transfer-Encoding' => 'binary', - 'Content-Disposition' => - "attachment; filename=#{job.artifacts_file.filename}" } + context 'when artifacts are stored locally' do + let(:download_headers) do + { 'Content-Transfer-Encoding' => 'binary', + 'Content-Disposition' => + "attachment; filename=#{job.artifacts_file.filename}" } + end + + it { expect(response).to have_http_status(200) } + it { expect(response.headers).to include(download_headers) } end - it { expect(response).to have_http_status(200) } - it { expect(response.headers).to include(download_headers) } + context 'when artifacts are stored remotely' do + let(:job) { create(:ci_build, :artifacts, :remote_store, pipeline: pipeline) } + + it 'returns location redirect' do + expect(response).to have_http_status(302) + end + end end context 'with regular branch' do |