diff options
Diffstat (limited to 'spec/requests/api/runner_spec.rb')
-rw-r--r-- | spec/requests/api/runner_spec.rb | 272 |
1 files changed, 171 insertions, 101 deletions
diff --git a/spec/requests/api/runner_spec.rb b/spec/requests/api/runner_spec.rb index 339a57a1f20..95c23726a79 100644 --- a/spec/requests/api/runner_spec.rb +++ b/spec/requests/api/runner_spec.rb @@ -8,6 +8,7 @@ describe API::Runner do before do stub_gitlab_calls stub_application_setting(runners_registration_token: registration_token) + allow_any_instance_of(Ci::Runner).to receive(:cache_attributes) end describe '/api/v4/runners' do @@ -16,7 +17,7 @@ describe API::Runner do it 'returns 400 error' do post api('/runners') - expect(response).to have_http_status 400 + expect(response).to have_gitlab_http_status 400 end end @@ -24,7 +25,7 @@ describe API::Runner do it 'returns 403 error' do post api('/runners'), token: 'invalid' - expect(response).to have_http_status 403 + expect(response).to have_gitlab_http_status 403 end end @@ -34,7 +35,7 @@ describe API::Runner do runner = Ci::Runner.first - expect(response).to have_http_status 201 + expect(response).to have_gitlab_http_status 201 expect(json_response['id']).to eq(runner.id) expect(json_response['token']).to eq(runner.token) expect(runner.run_untagged).to be true @@ -42,12 +43,12 @@ describe API::Runner do end context 'when project token is used' do - let(:project) { create(:empty_project) } + let(:project) { create(:project) } it 'creates runner' do post api('/runners'), token: project.runners_token - expect(response).to have_http_status 201 + expect(response).to have_gitlab_http_status 201 expect(project.runners.size).to eq(1) expect(Ci::Runner.first.token).not_to eq(registration_token) expect(Ci::Runner.first.token).not_to eq(project.runners_token) @@ -60,7 +61,7 @@ describe API::Runner do post api('/runners'), token: registration_token, description: 'server.hostname' - expect(response).to have_http_status 201 + expect(response).to have_gitlab_http_status 201 expect(Ci::Runner.first.description).to eq('server.hostname') end end @@ -70,7 +71,7 @@ describe API::Runner do post api('/runners'), token: registration_token, tag_list: 'tag1, tag2' - expect(response).to have_http_status 201 + expect(response).to have_gitlab_http_status 201 expect(Ci::Runner.first.tag_list.sort).to eq(%w(tag1 tag2)) end end @@ -82,7 +83,7 @@ describe API::Runner do run_untagged: false, tag_list: ['tag'] - expect(response).to have_http_status 201 + expect(response).to have_gitlab_http_status 201 expect(Ci::Runner.first.run_untagged).to be false expect(Ci::Runner.first.tag_list.sort).to eq(['tag']) end @@ -93,7 +94,7 @@ describe API::Runner do post api('/runners'), token: registration_token, run_untagged: false - expect(response).to have_http_status 404 + expect(response).to have_gitlab_http_status 404 end end end @@ -103,7 +104,7 @@ describe API::Runner do post api('/runners'), token: registration_token, locked: true - expect(response).to have_http_status 201 + expect(response).to have_gitlab_http_status 201 expect(Ci::Runner.first.locked).to be true end end @@ -116,11 +117,20 @@ describe API::Runner do post api('/runners'), token: registration_token, info: { param => value } - expect(response).to have_http_status 201 + expect(response).to have_gitlab_http_status 201 expect(Ci::Runner.first.read_attribute(param.to_sym)).to eq(value) end end end + + it "sets the runner's ip_address" do + post api('/runners'), + { token: registration_token }, + { 'REMOTE_ADDR' => '123.111.123.111' } + + expect(response).to have_gitlab_http_status 201 + expect(Ci::Runner.first.ip_address).to eq('123.111.123.111') + end end describe 'DELETE /api/v4/runners' do @@ -128,7 +138,7 @@ describe API::Runner do it 'returns 400 error' do delete api('/runners') - expect(response).to have_http_status 400 + expect(response).to have_gitlab_http_status 400 end end @@ -136,7 +146,7 @@ describe API::Runner do it 'returns 403 error' do delete api('/runners'), token: 'invalid' - expect(response).to have_http_status 403 + expect(response).to have_gitlab_http_status 403 end end @@ -146,9 +156,14 @@ describe API::Runner do it 'deletes Runner' do delete api('/runners'), token: runner.token - expect(response).to have_http_status 204 + expect(response).to have_gitlab_http_status 204 expect(Ci::Runner.count).to eq(0) end + + it_behaves_like '412 response' do + let(:request) { api('/runners') } + let(:params) { { token: runner.token } } + end end end @@ -159,7 +174,7 @@ describe API::Runner do it 'returns 400 error' do post api('/runners/verify') - expect(response).to have_http_status :bad_request + expect(response).to have_gitlab_http_status :bad_request end end @@ -167,7 +182,7 @@ describe API::Runner do it 'returns 403 error' do post api('/runners/verify'), token: 'invalid-token' - expect(response).to have_http_status 403 + expect(response).to have_gitlab_http_status 403 end end @@ -175,14 +190,14 @@ describe API::Runner do it 'verifies Runner credentials' do post api('/runners/verify'), token: runner.token - expect(response).to have_http_status 200 + expect(response).to have_gitlab_http_status 200 end end end end describe '/api/v4/jobs' do - let(:project) { create(:empty_project, shared_runners_enabled: false) } + let(:project) { create(:project, shared_runners_enabled: false) } let(:pipeline) { create(:ci_pipeline_without_jobs, project: project, ref: 'master') } let(:runner) { create(:ci_runner) } let!(:job) do @@ -211,7 +226,7 @@ describe API::Runner do context 'when runner sends version in User-Agent' do context 'for stable version' do it 'gives 204 and set X-GitLab-Last-Update' do - expect(response).to have_http_status(204) + expect(response).to have_gitlab_http_status(204) expect(response.header).to have_key('X-GitLab-Last-Update') end end @@ -220,7 +235,7 @@ describe API::Runner do let(:last_update) { runner.ensure_runner_queue_value } it 'gives 204 and set the same X-GitLab-Last-Update' do - expect(response).to have_http_status(204) + expect(response).to have_gitlab_http_status(204) expect(response.header['X-GitLab-Last-Update']).to eq(last_update) end end @@ -230,7 +245,7 @@ describe API::Runner do let(:new_update) { runner.tick_runner_queue } it 'gives 204 and set a new X-GitLab-Last-Update' do - expect(response).to have_http_status(204) + expect(response).to have_gitlab_http_status(204) expect(response.header['X-GitLab-Last-Update']).to eq(new_update) end end @@ -238,19 +253,19 @@ describe API::Runner do context 'when beta version is sent' do let(:user_agent) { 'gitlab-runner 9.0.0~beta.167.g2b2bacc (master; go1.7.4; linux/amd64)' } - it { expect(response).to have_http_status(204) } + it { expect(response).to have_gitlab_http_status(204) } end context 'when pre-9-0 version is sent' do let(:user_agent) { 'gitlab-ci-multi-runner 1.6.0 (1-6-stable; go1.6.3; linux/amd64)' } - it { expect(response).to have_http_status(204) } + it { expect(response).to have_gitlab_http_status(204) } end context 'when pre-9-0 beta version is sent' do let(:user_agent) { 'gitlab-ci-multi-runner 1.6.0~beta.167.g2b2bacc (master; go1.6.3; linux/amd64)' } - it { expect(response).to have_http_status(204) } + it { expect(response).to have_gitlab_http_status(204) } end end end @@ -259,7 +274,7 @@ describe API::Runner do it 'returns 400 error' do post api('/jobs/request') - expect(response).to have_http_status 400 + expect(response).to have_gitlab_http_status 400 end end @@ -267,7 +282,7 @@ describe API::Runner do it 'returns 403 error' do post api('/jobs/request'), token: 'invalid' - expect(response).to have_http_status 403 + expect(response).to have_gitlab_http_status 403 end end @@ -278,7 +293,7 @@ describe API::Runner do it 'returns 204 error' do request_job - expect(response).to have_http_status 204 + expect(response).to have_gitlab_http_status 204 end end @@ -351,13 +366,16 @@ describe API::Runner do let(:expected_cache) do [{ 'key' => 'cache_key', 'untracked' => false, - 'paths' => ['vendor/*'] }] + 'paths' => ['vendor/*'], + 'policy' => 'pull-push' }] end + let(:expected_features) { { 'trace_sections' => true } } + it 'picks a job' do request_job info: { platform: :darwin } - expect(response).to have_http_status(201) + expect(response).to have_gitlab_http_status(201) expect(response.headers).not_to have_key('X-GitLab-Last-Update') expect(runner.reload.platform).to eq('darwin') expect(json_response['id']).to eq(job.id) @@ -373,15 +391,16 @@ describe API::Runner do expect(json_response['artifacts']).to eq(expected_artifacts) expect(json_response['cache']).to eq(expected_cache) expect(json_response['variables']).to include(*expected_variables) + expect(json_response['features']).to eq(expected_features) end context 'when job is made for tag' do - let!(:job) { create(:ci_build_tag, pipeline: pipeline, name: 'spinach', stage: 'test', stage_idx: 0) } + let!(:job) { create(:ci_build, :tag, pipeline: pipeline, name: 'spinach', stage: 'test', stage_idx: 0) } it 'sets branch as ref_type' do request_job - expect(response).to have_http_status(201) + expect(response).to have_gitlab_http_status(201) expect(json_response['git_info']['ref_type']).to eq('tag') end end @@ -390,7 +409,7 @@ describe API::Runner do it 'sets tag as ref_type' do request_job - expect(response).to have_http_status(201) + expect(response).to have_gitlab_http_status(201) expect(json_response['git_info']['ref_type']).to eq('branch') end end @@ -399,19 +418,28 @@ describe API::Runner do expect { request_job }.to change { runner.reload.contacted_at } end - %w(name version revision platform architecture).each do |param| + %w(version revision platform architecture).each do |param| context "when info parameter '#{param}' is present" do let(:value) { "#{param}_value" } it "updates provided Runner's parameter" do request_job info: { param => value } - expect(response).to have_http_status(201) + expect(response).to have_gitlab_http_status(201) expect(runner.reload.read_attribute(param.to_sym)).to eq(value) end end end + it "sets the runner's ip_address" do + post api('/jobs/request'), + { token: runner.token }, + { 'User-Agent' => user_agent, 'REMOTE_ADDR' => '123.222.123.222' } + + expect(response).to have_gitlab_http_status 201 + expect(runner.reload.ip_address).to eq('123.222.123.222') + end + context 'when concurrently updating a job' do before do expect_any_instance_of(Ci::Build).to receive(:run!) @@ -421,14 +449,14 @@ describe API::Runner do it 'returns a conflict' do request_job - expect(response).to have_http_status(409) + expect(response).to have_gitlab_http_status(409) expect(response.headers).not_to have_key('X-GitLab-Last-Update') end end context 'when project and pipeline have multiple jobs' do - let!(:job) { create(:ci_build_tag, pipeline: pipeline, name: 'spinach', stage: 'test', stage_idx: 0) } - let!(:job2) { create(:ci_build_tag, pipeline: pipeline, name: 'rubocop', stage: 'test', stage_idx: 0) } + let!(:job) { create(:ci_build, :tag, pipeline: pipeline, name: 'spinach', stage: 'test', stage_idx: 0) } + let!(:job2) { create(:ci_build, :tag, pipeline: pipeline, name: 'rubocop', stage: 'test', stage_idx: 0) } let!(:test_job) { create(:ci_build, pipeline: pipeline, name: 'deploy', stage: 'deploy', stage_idx: 1) } before do @@ -439,7 +467,7 @@ describe API::Runner do it 'returns dependent jobs' do request_job - expect(response).to have_http_status(201) + expect(response).to have_gitlab_http_status(201) expect(json_response['id']).to eq(test_job.id) expect(json_response['dependencies'].count).to eq(2) expect(json_response['dependencies']).to include( @@ -449,7 +477,7 @@ describe API::Runner do end context 'when pipeline have jobs with artifacts' do - let!(:job) { create(:ci_build_tag, :artifacts, pipeline: pipeline, name: 'spinach', stage: 'test', stage_idx: 0) } + let!(:job) { create(:ci_build, :tag, :artifacts, pipeline: pipeline, name: 'spinach', stage: 'test', stage_idx: 0) } let!(:test_job) { create(:ci_build, pipeline: pipeline, name: 'deploy', stage: 'deploy', stage_idx: 1) } before do @@ -459,7 +487,7 @@ describe API::Runner do it 'returns dependent jobs' do request_job - expect(response).to have_http_status(201) + expect(response).to have_gitlab_http_status(201) expect(json_response['id']).to eq(test_job.id) expect(json_response['dependencies'].count).to eq(1) expect(json_response['dependencies']).to include( @@ -469,8 +497,8 @@ describe API::Runner do end context 'when explicit dependencies are defined' do - let!(:job) { create(:ci_build_tag, pipeline: pipeline, name: 'spinach', stage: 'test', stage_idx: 0) } - let!(:job2) { create(:ci_build_tag, pipeline: pipeline, name: 'rubocop', stage: 'test', stage_idx: 0) } + let!(:job) { create(:ci_build, :tag, pipeline: pipeline, name: 'spinach', stage: 'test', stage_idx: 0) } + let!(:job2) { create(:ci_build, :tag, pipeline: pipeline, name: 'rubocop', stage: 'test', stage_idx: 0) } let!(:test_job) do create(:ci_build, pipeline: pipeline, token: 'test-job-token', name: 'deploy', stage: 'deploy', stage_idx: 1, @@ -485,7 +513,7 @@ describe API::Runner do it 'returns dependent jobs' do request_job - expect(response).to have_http_status(201) + expect(response).to have_gitlab_http_status(201) expect(json_response['id']).to eq(test_job.id) expect(json_response['dependencies'].count).to eq(1) expect(json_response['dependencies'][0]).to include('id' => job2.id, 'name' => job2.name, 'token' => job2.token) @@ -493,8 +521,8 @@ describe API::Runner do end context 'when dependencies is an empty array' do - let!(:job) { create(:ci_build_tag, pipeline: pipeline, name: 'spinach', stage: 'test', stage_idx: 0) } - let!(:job2) { create(:ci_build_tag, pipeline: pipeline, name: 'rubocop', stage: 'test', stage_idx: 0) } + let!(:job) { create(:ci_build, :tag, pipeline: pipeline, name: 'spinach', stage: 'test', stage_idx: 0) } + let!(:job2) { create(:ci_build, :tag, pipeline: pipeline, name: 'rubocop', stage: 'test', stage_idx: 0) } let!(:empty_dependencies_job) do create(:ci_build, pipeline: pipeline, token: 'test-job-token', name: 'empty_dependencies_job', stage: 'deploy', stage_idx: 1, @@ -509,7 +537,7 @@ describe API::Runner do it 'returns an empty array' do request_job - expect(response).to have_http_status(201) + expect(response).to have_gitlab_http_status(201) expect(json_response['id']).to eq(empty_dependencies_job.id) expect(json_response['dependencies'].count).to eq(0) end @@ -528,7 +556,7 @@ describe API::Runner do it 'picks job' do request_job - expect(response).to have_http_status 201 + expect(response).to have_gitlab_http_status 201 end end @@ -551,17 +579,36 @@ describe API::Runner do { 'key' => 'TRIGGER_KEY_1', 'value' => 'TRIGGER_VALUE_1', 'public' => false }] end + let(:trigger) { create(:ci_trigger, project: project) } + let!(:trigger_request) { create(:ci_trigger_request, pipeline: pipeline, builds: [job], trigger: trigger) } + before do - trigger = create(:ci_trigger, project: project) - create(:ci_trigger_request_with_variables, pipeline: pipeline, builds: [job], trigger: trigger) project.variables << Ci::Variable.new(key: 'SECRET_KEY', value: 'secret_value') end - it 'returns variables for triggers' do - request_job + shared_examples 'expected variables behavior' do + it 'returns variables for triggers' do + request_job + + expect(response).to have_gitlab_http_status(201) + expect(json_response['variables']).to include(*expected_variables) + end + end + + context 'when variables are stored in trigger_request' do + before do + trigger_request.update_attribute(:variables, { TRIGGER_KEY_1: 'TRIGGER_VALUE_1' } ) + end + + it_behaves_like 'expected variables behavior' + end + + context 'when variables are stored in pipeline_variables' do + before do + create(:ci_pipeline_variable, pipeline: pipeline, key: :TRIGGER_KEY_1, value: 'TRIGGER_VALUE_1') + end - expect(response).to have_http_status(201) - expect(json_response['variables']).to include(*expected_variables) + it_behaves_like 'expected variables behavior' end end @@ -610,7 +657,7 @@ describe API::Runner do end describe 'PUT /api/v4/jobs/:id' do - let(:job) { create(:ci_build, :pending, :trace, pipeline: pipeline, runner_id: runner.id) } + let(:job) { create(:ci_build, :pending, :trace_live, pipeline: pipeline, runner_id: runner.id) } before do job.run! @@ -620,22 +667,49 @@ describe API::Runner do it 'mark job as succeeded' do update_job(state: 'success') - expect(job.reload.status).to eq 'success' + job.reload + expect(job).to be_success end it 'mark job as failed' do update_job(state: 'failed') - expect(job.reload.status).to eq 'failed' + job.reload + expect(job).to be_failed + expect(job).to be_unknown_failure + end + + context 'when failure_reason is script_failure' do + before do + update_job(state: 'failed', failure_reason: 'script_failure') + job.reload + end + + it { expect(job).to be_script_failure } + end + + context 'when failure_reason is runner_system_failure' do + before do + update_job(state: 'failed', failure_reason: 'runner_system_failure') + job.reload + end + + it { expect(job).to be_runner_system_failure } end end - context 'when tace is given' do - it 'updates a running build' do - update_job(trace: 'BUILD TRACE UPDATED') + context 'when trace is given' do + it 'creates a trace artifact' do + allow(BuildFinishedWorker).to receive(:perform_async).with(job.id) do + ArchiveTraceWorker.new.perform(job.id) + end + + update_job(state: 'success', trace: 'BUILD TRACE UPDATED') - expect(response).to have_http_status(200) - expect(job.reload.trace.raw).to eq 'BUILD TRACE UPDATED' + job.reload + expect(response).to have_gitlab_http_status(200) + expect(job.trace.raw).to eq 'BUILD TRACE UPDATED' + expect(job.job_artifacts_trace.open.read).to eq 'BUILD TRACE UPDATED' end end @@ -653,7 +727,7 @@ describe API::Runner do it 'responds with forbidden' do update_job - expect(response).to have_http_status(403) + expect(response).to have_gitlab_http_status(403) end end @@ -664,7 +738,7 @@ describe API::Runner do end describe 'PATCH /api/v4/jobs/:id/trace' do - let(:job) { create(:ci_build, :running, :trace, runner_id: runner.id, pipeline: pipeline) } + let(:job) { create(:ci_build, :running, :trace_live, runner_id: runner.id, pipeline: pipeline) } let(:headers) { { API::Helpers::Runner::JOB_TOKEN_HEADER => job.token, 'Content-Type' => 'text/plain' } } let(:headers_with_range) { headers.merge({ 'Content-Range' => '11-20' }) } let(:update_interval) { 10.seconds.to_i } @@ -682,7 +756,7 @@ describe API::Runner do end context 'when job has been updated recently' do - it { expect{ patch_the_trace }.not_to change { job.updated_at }} + it { expect { patch_the_trace }.not_to change { job.updated_at }} it "changes the job's trace" do patch_the_trace @@ -691,7 +765,7 @@ describe API::Runner do end context 'when Runner makes a force-patch' do - it { expect{ force_patch_the_trace }.not_to change { job.updated_at }} + it { expect { force_patch_the_trace }.not_to change { job.updated_at }} it "doesn't change the build.trace" do force_patch_the_trace @@ -725,7 +799,7 @@ describe API::Runner do context 'when project for the build has been deleted' do let(:job) do - create(:ci_build, :running, :trace, runner_id: runner.id, pipeline: pipeline) do |job| + create(:ci_build, :running, :trace_live, runner_id: runner.id, pipeline: pipeline) do |job| job.project.update(pending_delete: true) end end @@ -822,7 +896,7 @@ describe API::Runner do it 'authorizes posting artifacts to running job' do authorize_artifacts_with_token_in_params - expect(response).to have_http_status(200) + expect(response).to have_gitlab_http_status(200) expect(response.content_type.to_s).to eq(Gitlab::Workhorse::INTERNAL_API_CONTENT_TYPE) expect(json_response['TempPath']).not_to be_nil end @@ -832,7 +906,7 @@ describe API::Runner do authorize_artifacts_with_token_in_params(filesize: 100) - expect(response).to have_http_status(413) + expect(response).to have_gitlab_http_status(413) end end @@ -840,7 +914,7 @@ describe API::Runner do it 'authorizes posting artifacts to running job' do authorize_artifacts_with_token_in_headers - expect(response).to have_http_status(200) + expect(response).to have_gitlab_http_status(200) expect(response.content_type.to_s).to eq(Gitlab::Workhorse::INTERNAL_API_CONTENT_TYPE) expect(json_response['TempPath']).not_to be_nil end @@ -850,7 +924,7 @@ describe API::Runner do authorize_artifacts_with_token_in_headers(filesize: 100) - expect(response).to have_http_status(413) + expect(response).to have_gitlab_http_status(413) end end @@ -858,7 +932,7 @@ describe API::Runner do it 'fails to authorize artifacts posting' do authorize_artifacts(token: job.project.runners_token) - expect(response).to have_http_status(403) + expect(response).to have_gitlab_http_status(403) end end @@ -867,14 +941,14 @@ describe API::Runner do authorize_artifacts - expect(response).to have_http_status(500) + expect(response).to have_gitlab_http_status(500) end context 'authorization token is invalid' do it 'responds with forbidden' do authorize_artifacts(token: 'invalid', filesize: 100 ) - expect(response).to have_http_status(403) + expect(response).to have_gitlab_http_status(403) end end @@ -896,7 +970,7 @@ describe API::Runner do context 'when artifacts are being stored inside of tmp path' do before do # by configuring this path we allow to pass temp file from any path - allow(ArtifactUploader).to receive(:artifacts_upload_path).and_return('/') + allow(JobArtifactUploader).to receive(:workhorse_upload_path).and_return('/') end context 'when job has been erased' do @@ -909,14 +983,14 @@ describe API::Runner do it 'responds with forbidden' do upload_artifacts(file_upload, headers_with_token) - expect(response).to have_http_status(403) + expect(response).to have_gitlab_http_status(403) end end context 'when job is running' do shared_examples 'successful artifacts upload' do it 'updates successfully' do - expect(response).to have_http_status(201) + expect(response).to have_gitlab_http_status(201) end end @@ -936,20 +1010,11 @@ describe API::Runner do it_behaves_like 'successful artifacts upload' end - context 'when updates artifact' do - before do - upload_artifacts(file_upload2, headers_with_token) - upload_artifacts(file_upload, headers_with_token) - end - - it_behaves_like 'successful artifacts upload' - end - context 'when using runners token' do it 'responds with forbidden' do upload_artifacts(file_upload, headers.merge(API::Helpers::Runner::JOB_TOKEN_HEADER => job.project.runners_token)) - expect(response).to have_http_status(403) + expect(response).to have_gitlab_http_status(403) end end end @@ -960,7 +1025,7 @@ describe API::Runner do upload_artifacts(file_upload, headers_with_token) - expect(response).to have_http_status(413) + expect(response).to have_gitlab_http_status(413) end end @@ -968,7 +1033,7 @@ describe API::Runner do it 'fails to post artifacts without file' do post api("/jobs/#{job.id}/artifacts"), {}, headers_with_token - expect(response).to have_http_status(400) + expect(response).to have_gitlab_http_status(400) end end @@ -976,7 +1041,7 @@ describe API::Runner do it 'fails to post artifacts without GitLab-Workhorse' do post api("/jobs/#{job.id}/artifacts"), { token: job.token }, {} - expect(response).to have_http_status(403) + expect(response).to have_gitlab_http_status(403) end end @@ -998,7 +1063,7 @@ describe API::Runner do let(:expire_in) { '7 days' } it 'updates when specified' do - expect(response).to have_http_status(201) + expect(response).to have_gitlab_http_status(201) expect(job.reload.artifacts_expire_at).to be_within(5.minutes).of(7.days.from_now) end end @@ -1007,7 +1072,7 @@ describe API::Runner do let(:expire_in) { nil } it 'ignores if not specified' do - expect(response).to have_http_status(201) + expect(response).to have_gitlab_http_status(201) expect(job.reload.artifacts_expire_at).to be_nil end @@ -1016,7 +1081,7 @@ describe API::Runner do let(:default_artifacts_expire_in) { '5 days' } it 'sets to application default' do - expect(response).to have_http_status(201) + expect(response).to have_gitlab_http_status(201) expect(job.reload.artifacts_expire_at).to be_within(5.minutes).of(5.days.from_now) end end @@ -1025,7 +1090,7 @@ describe API::Runner do let(:default_artifacts_expire_in) { '0' } it 'does not set expire_in' do - expect(response).to have_http_status(201) + expect(response).to have_gitlab_http_status(201) expect(job.reload.artifacts_expire_at).to be_nil end end @@ -1035,11 +1100,13 @@ describe API::Runner do context 'posts artifacts file and metadata file' do let!(:artifacts) { file_upload } + let!(:artifacts_sha256) { Digest::SHA256.file(artifacts.path).hexdigest } let!(:metadata) { file_upload2 } let(:stored_artifacts_file) { job.reload.artifacts_file.file } let(:stored_metadata_file) { job.reload.artifacts_metadata.file } let(:stored_artifacts_size) { job.reload.artifacts_size } + let(:stored_artifacts_sha256) { job.reload.job_artifacts_archive.file_sha256 } before do post(api("/jobs/#{job.id}/artifacts"), post_data, headers_with_token) @@ -1049,15 +1116,17 @@ describe API::Runner do let(:post_data) do { 'file.path' => artifacts.path, 'file.name' => artifacts.original_filename, + 'file.sha256' => artifacts_sha256, 'metadata.path' => metadata.path, 'metadata.name' => metadata.original_filename } end it 'stores artifacts and artifacts metadata' do - expect(response).to have_http_status(201) + expect(response).to have_gitlab_http_status(201) expect(stored_artifacts_file.original_filename).to eq(artifacts.original_filename) expect(stored_metadata_file.original_filename).to eq(metadata.original_filename) - expect(stored_artifacts_size).to eq(71759) + expect(stored_artifacts_size).to eq(72821) + expect(stored_artifacts_sha256).to eq(artifacts_sha256) end end @@ -1067,7 +1136,7 @@ describe API::Runner do end it 'is expected to respond with bad request' do - expect(response).to have_http_status(400) + expect(response).to have_gitlab_http_status(400) end it 'does not store metadata' do @@ -1082,7 +1151,7 @@ describe API::Runner do # by configuring this path we allow to pass file from @tmpdir only # but all temporary files are stored in system tmp directory @tmpdir = Dir.mktmpdir - allow(ArtifactUploader).to receive(:artifacts_upload_path).and_return(@tmpdir) + allow(JobArtifactUploader).to receive(:workhorse_upload_path).and_return(@tmpdir) end after do @@ -1092,7 +1161,7 @@ describe API::Runner do it' "fails to post artifacts for outside of tmp path"' do upload_artifacts(file_upload, headers_with_token) - expect(response).to have_http_status(400) + expect(response).to have_gitlab_http_status(400) end end @@ -1102,6 +1171,7 @@ describe API::Runner do else { 'file' => file } end + post api("/jobs/#{job.id}/artifacts"), params, headers end end @@ -1122,7 +1192,7 @@ describe API::Runner do context 'when using job token' do it 'download artifacts' do - expect(response).to have_http_status(200) + expect(response).to have_gitlab_http_status(200) expect(response.headers).to include download_headers end end @@ -1131,14 +1201,14 @@ describe API::Runner do let(:token) { job.project.runners_token } it 'responds with forbidden' do - expect(response).to have_http_status(403) + expect(response).to have_gitlab_http_status(403) end end end context 'when job does not has artifacts' do it 'responds with not found' do - expect(response).to have_http_status(404) + expect(response).to have_gitlab_http_status(404) end end |