2015-12-29 22:12:36 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2017-07-10 14:24:02 +00:00
|
|
|
describe API::Jobs do
|
2017-05-02 08:29:09 +00:00
|
|
|
let!(:project) do
|
|
|
|
create(:project, :repository, public_builds: false)
|
|
|
|
end
|
|
|
|
|
|
|
|
let!(:pipeline) do
|
|
|
|
create(:ci_empty_pipeline, project: project,
|
|
|
|
sha: project.commit.id,
|
|
|
|
ref: project.default_branch)
|
|
|
|
end
|
|
|
|
|
2017-06-06 14:21:39 +00:00
|
|
|
let!(:job) { create(:ci_build, pipeline: pipeline) }
|
2015-12-29 22:12:36 +00:00
|
|
|
|
|
|
|
let(:user) { create(:user) }
|
2016-02-19 17:06:53 +00:00
|
|
|
let(:api_user) { user }
|
2017-05-02 08:29:09 +00:00
|
|
|
let(:reporter) { create(:project_member, :reporter, project: project).user }
|
|
|
|
let(:guest) { create(:project_member, :guest, project: project).user }
|
|
|
|
|
|
|
|
before do
|
|
|
|
project.add_developer(user)
|
|
|
|
end
|
2015-12-29 22:12:36 +00:00
|
|
|
|
2017-02-22 10:13:59 +00:00
|
|
|
describe 'GET /projects/:id/jobs' do
|
|
|
|
let(:query) { Hash.new }
|
2016-02-19 17:06:53 +00:00
|
|
|
|
2016-07-14 16:53:27 +00:00
|
|
|
before do
|
2017-02-22 10:13:59 +00:00
|
|
|
get api("/projects/#{project.id}/jobs", api_user), query
|
2016-07-14 16:53:27 +00:00
|
|
|
end
|
2016-02-19 17:06:53 +00:00
|
|
|
|
2015-12-29 22:12:36 +00:00
|
|
|
context 'authorized user' do
|
2017-02-22 10:13:59 +00:00
|
|
|
it 'returns project jobs' do
|
2016-06-27 18:10:42 +00:00
|
|
|
expect(response).to have_http_status(200)
|
2017-01-24 20:49:10 +00:00
|
|
|
expect(response).to include_pagination_headers
|
2016-01-08 13:01:31 +00:00
|
|
|
expect(json_response).to be_an Array
|
|
|
|
end
|
|
|
|
|
2016-06-21 12:26:57 +00:00
|
|
|
it 'returns correct values' do
|
|
|
|
expect(json_response).not_to be_empty
|
|
|
|
expect(json_response.first['commit']['id']).to eq project.commit.id
|
|
|
|
end
|
|
|
|
|
2016-09-23 23:43:57 +00:00
|
|
|
it 'returns pipeline data' do
|
2017-06-06 14:21:39 +00:00
|
|
|
json_job = json_response.first
|
2017-02-22 10:13:59 +00:00
|
|
|
|
2017-06-06 14:21:39 +00:00
|
|
|
expect(json_job['pipeline']).not_to be_empty
|
|
|
|
expect(json_job['pipeline']['id']).to eq job.pipeline.id
|
|
|
|
expect(json_job['pipeline']['ref']).to eq job.pipeline.ref
|
|
|
|
expect(json_job['pipeline']['sha']).to eq job.pipeline.sha
|
|
|
|
expect(json_job['pipeline']['status']).to eq job.pipeline.status
|
2016-09-23 23:43:57 +00:00
|
|
|
end
|
|
|
|
|
2016-02-19 17:06:53 +00:00
|
|
|
context 'filter project with one scope element' do
|
2017-02-22 10:13:59 +00:00
|
|
|
let(:query) { { 'scope' => 'pending' } }
|
2016-01-08 13:01:31 +00:00
|
|
|
|
2016-02-19 17:06:53 +00:00
|
|
|
it do
|
2016-06-27 18:10:42 +00:00
|
|
|
expect(response).to have_http_status(200)
|
2016-02-19 17:06:53 +00:00
|
|
|
expect(json_response).to be_an Array
|
|
|
|
end
|
2016-01-08 13:01:31 +00:00
|
|
|
end
|
|
|
|
|
2016-02-19 17:06:53 +00:00
|
|
|
context 'filter project with array of scope elements' do
|
2017-03-07 19:54:39 +00:00
|
|
|
let(:query) { { scope: %w(pending running) } }
|
2016-01-08 13:01:31 +00:00
|
|
|
|
2016-02-19 17:06:53 +00:00
|
|
|
it do
|
2016-06-27 18:10:42 +00:00
|
|
|
expect(response).to have_http_status(200)
|
2016-02-19 17:06:53 +00:00
|
|
|
expect(json_response).to be_an Array
|
|
|
|
end
|
2015-12-29 22:12:36 +00:00
|
|
|
end
|
2016-01-13 14:17:59 +00:00
|
|
|
|
2016-02-19 17:06:53 +00:00
|
|
|
context 'respond 400 when scope contains invalid state' do
|
2017-03-07 19:54:39 +00:00
|
|
|
let(:query) { { scope: %w(unknown running) } }
|
2016-01-13 14:17:59 +00:00
|
|
|
|
2016-06-27 18:10:42 +00:00
|
|
|
it { expect(response).to have_http_status(400) }
|
2016-01-13 14:17:59 +00:00
|
|
|
end
|
2015-12-29 22:12:36 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'unauthorized user' do
|
2016-02-19 17:06:53 +00:00
|
|
|
let(:api_user) { nil }
|
2015-12-29 22:12:36 +00:00
|
|
|
|
2017-06-06 14:21:39 +00:00
|
|
|
it 'does not return project jobs' do
|
2016-06-27 18:10:42 +00:00
|
|
|
expect(response).to have_http_status(401)
|
2015-12-29 22:12:36 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-03-06 15:56:05 +00:00
|
|
|
describe 'GET /projects/:id/pipelines/:pipeline_id/jobs' do
|
|
|
|
let(:query) { Hash.new }
|
|
|
|
|
|
|
|
before do
|
|
|
|
get api("/projects/#{project.id}/pipelines/#{pipeline.id}/jobs", api_user), query
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'authorized user' do
|
|
|
|
it 'returns pipeline jobs' do
|
|
|
|
expect(response).to have_http_status(200)
|
|
|
|
expect(response).to include_pagination_headers
|
|
|
|
expect(json_response).to be_an Array
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns correct values' do
|
|
|
|
expect(json_response).not_to be_empty
|
|
|
|
expect(json_response.first['commit']['id']).to eq project.commit.id
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns pipeline data' do
|
2017-06-06 14:21:39 +00:00
|
|
|
json_job = json_response.first
|
2017-03-06 15:56:05 +00:00
|
|
|
|
2017-06-06 14:21:39 +00:00
|
|
|
expect(json_job['pipeline']).not_to be_empty
|
|
|
|
expect(json_job['pipeline']['id']).to eq job.pipeline.id
|
|
|
|
expect(json_job['pipeline']['ref']).to eq job.pipeline.ref
|
|
|
|
expect(json_job['pipeline']['sha']).to eq job.pipeline.sha
|
|
|
|
expect(json_job['pipeline']['status']).to eq job.pipeline.status
|
2017-03-06 15:56:05 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'filter jobs with one scope element' do
|
|
|
|
let(:query) { { 'scope' => 'pending' } }
|
|
|
|
|
|
|
|
it do
|
|
|
|
expect(response).to have_http_status(200)
|
|
|
|
expect(json_response).to be_an Array
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'filter jobs with array of scope elements' do
|
2017-03-07 19:54:39 +00:00
|
|
|
let(:query) { { scope: %w(pending running) } }
|
2017-03-06 15:56:05 +00:00
|
|
|
|
|
|
|
it do
|
|
|
|
expect(response).to have_http_status(200)
|
|
|
|
expect(json_response).to be_an Array
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'respond 400 when scope contains invalid state' do
|
2017-03-07 19:54:39 +00:00
|
|
|
let(:query) { { scope: %w(unknown running) } }
|
2017-03-06 15:56:05 +00:00
|
|
|
|
|
|
|
it { expect(response).to have_http_status(400) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'jobs in different pipelines' do
|
|
|
|
let!(:pipeline2) { create(:ci_empty_pipeline, project: project) }
|
2017-06-06 14:21:39 +00:00
|
|
|
let!(:job2) { create(:ci_build, pipeline: pipeline2) }
|
2017-03-06 15:56:05 +00:00
|
|
|
|
|
|
|
it 'excludes jobs from other pipelines' do
|
|
|
|
json_response.each { |job| expect(job['pipeline']['id']).to eq(pipeline.id) }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'unauthorized user' do
|
|
|
|
let(:api_user) { nil }
|
|
|
|
|
|
|
|
it 'does not return jobs' do
|
|
|
|
expect(response).to have_http_status(401)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-02-22 10:13:59 +00:00
|
|
|
describe 'GET /projects/:id/jobs/:job_id' do
|
2016-07-14 16:53:27 +00:00
|
|
|
before do
|
2017-06-06 14:21:39 +00:00
|
|
|
get api("/projects/#{project.id}/jobs/#{job.id}", api_user)
|
2016-07-14 16:53:27 +00:00
|
|
|
end
|
2016-02-19 17:06:53 +00:00
|
|
|
|
2015-12-30 14:12:07 +00:00
|
|
|
context 'authorized user' do
|
2017-01-26 11:52:58 +00:00
|
|
|
it 'returns specific job data' do
|
2016-06-27 18:10:42 +00:00
|
|
|
expect(response).to have_http_status(200)
|
2015-12-30 14:12:07 +00:00
|
|
|
expect(json_response['name']).to eq('test')
|
|
|
|
end
|
2016-09-23 23:43:57 +00:00
|
|
|
|
|
|
|
it 'returns pipeline data' do
|
2017-06-06 14:21:39 +00:00
|
|
|
json_job = json_response
|
|
|
|
|
|
|
|
expect(json_job['pipeline']).not_to be_empty
|
|
|
|
expect(json_job['pipeline']['id']).to eq job.pipeline.id
|
|
|
|
expect(json_job['pipeline']['ref']).to eq job.pipeline.ref
|
|
|
|
expect(json_job['pipeline']['sha']).to eq job.pipeline.sha
|
|
|
|
expect(json_job['pipeline']['status']).to eq job.pipeline.status
|
2016-09-23 23:43:57 +00:00
|
|
|
end
|
2016-01-13 17:30:49 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'unauthorized user' do
|
2016-02-19 17:06:53 +00:00
|
|
|
let(:api_user) { nil }
|
2015-12-30 14:12:07 +00:00
|
|
|
|
2017-01-26 11:52:58 +00:00
|
|
|
it 'does not return specific job data' do
|
2016-06-27 18:10:42 +00:00
|
|
|
expect(response).to have_http_status(401)
|
2016-01-13 17:30:49 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-02-22 10:13:59 +00:00
|
|
|
describe 'GET /projects/:id/jobs/:job_id/artifacts' do
|
2016-07-14 16:53:27 +00:00
|
|
|
before do
|
2017-06-06 14:21:39 +00:00
|
|
|
get api("/projects/#{project.id}/jobs/#{job.id}/artifacts", api_user)
|
2016-07-14 16:53:27 +00:00
|
|
|
end
|
2016-02-08 21:32:36 +00:00
|
|
|
|
2017-01-26 11:52:58 +00:00
|
|
|
context 'job with artifacts' do
|
2017-06-06 14:21:39 +00:00
|
|
|
let(:job) { create(:ci_build, :artifacts, pipeline: pipeline) }
|
2016-02-08 21:32:36 +00:00
|
|
|
|
2016-02-19 17:06:53 +00:00
|
|
|
context 'authorized user' do
|
|
|
|
let(:download_headers) do
|
2016-05-11 02:58:06 +00:00
|
|
|
{ 'Content-Transfer-Encoding' => 'binary',
|
|
|
|
'Content-Disposition' => 'attachment; filename=ci_build_artifacts.zip' }
|
2016-02-19 17:06:53 +00:00
|
|
|
end
|
2016-02-08 21:32:36 +00:00
|
|
|
|
2017-01-26 11:52:58 +00:00
|
|
|
it 'returns specific job artifacts' do
|
2016-06-27 18:10:42 +00:00
|
|
|
expect(response).to have_http_status(200)
|
2016-02-19 17:06:53 +00:00
|
|
|
expect(response.headers).to include(download_headers)
|
2017-06-06 14:21:39 +00:00
|
|
|
expect(response.body).to match_file(job.artifacts_file.file.file)
|
2016-02-19 17:06:53 +00:00
|
|
|
end
|
2016-02-08 21:32:36 +00:00
|
|
|
end
|
|
|
|
|
2016-02-19 17:06:53 +00:00
|
|
|
context 'unauthorized user' do
|
|
|
|
let(:api_user) { nil }
|
2016-02-08 21:32:36 +00:00
|
|
|
|
2017-01-26 11:52:58 +00:00
|
|
|
it 'does not return specific job artifacts' do
|
2016-06-27 18:10:42 +00:00
|
|
|
expect(response).to have_http_status(401)
|
2016-02-19 17:06:53 +00:00
|
|
|
end
|
2016-02-08 21:32:36 +00:00
|
|
|
end
|
|
|
|
end
|
2016-02-19 17:06:53 +00:00
|
|
|
|
2017-01-26 11:52:58 +00:00
|
|
|
it 'does not return job artifacts if not uploaded' do
|
2016-06-27 18:10:42 +00:00
|
|
|
expect(response).to have_http_status(404)
|
2016-02-19 17:06:53 +00:00
|
|
|
end
|
2016-02-08 21:32:36 +00:00
|
|
|
end
|
|
|
|
|
2016-07-14 18:01:10 +00:00
|
|
|
describe 'GET /projects/:id/artifacts/:ref_name/download?job=name' do
|
2017-05-02 08:29:09 +00:00
|
|
|
let(:api_user) { reporter }
|
2017-06-06 14:21:39 +00:00
|
|
|
let(:job) { create(:ci_build, :artifacts, pipeline: pipeline) }
|
2016-08-11 20:54:25 +00:00
|
|
|
|
|
|
|
before do
|
2017-06-06 14:21:39 +00:00
|
|
|
job.success
|
2016-08-11 20:54:25 +00:00
|
|
|
end
|
2016-07-14 17:07:41 +00:00
|
|
|
|
2017-06-06 14:21:39 +00:00
|
|
|
def get_for_ref(ref = pipeline.ref, job_name = job.name)
|
|
|
|
get api("/projects/#{project.id}/jobs/artifacts/#{ref}/download", api_user), job: job_name
|
2016-07-14 17:07:41 +00:00
|
|
|
end
|
|
|
|
|
2016-07-20 15:19:35 +00:00
|
|
|
context 'when not logged in' do
|
2016-07-19 17:24:59 +00:00
|
|
|
let(:api_user) { nil }
|
2016-07-14 17:07:41 +00:00
|
|
|
|
|
|
|
before do
|
2017-02-22 10:13:59 +00:00
|
|
|
get_for_ref
|
2016-07-14 17:07:41 +00:00
|
|
|
end
|
|
|
|
|
2016-07-20 14:02:42 +00:00
|
|
|
it 'gives 401' do
|
2016-07-14 17:07:41 +00:00
|
|
|
expect(response).to have_http_status(401)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-07-20 15:17:49 +00:00
|
|
|
context 'when logging as guest' do
|
2017-05-02 08:29:09 +00:00
|
|
|
let(:api_user) { guest }
|
2016-07-20 14:40:49 +00:00
|
|
|
|
|
|
|
before do
|
2017-02-22 10:13:59 +00:00
|
|
|
get_for_ref
|
2016-07-20 14:40:49 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'gives 403' do
|
|
|
|
expect(response).to have_http_status(403)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-01-26 11:52:58 +00:00
|
|
|
context 'non-existing job' do
|
2016-07-20 09:38:49 +00:00
|
|
|
shared_examples 'not found' do
|
|
|
|
it { expect(response).to have_http_status(:not_found) }
|
2016-07-14 17:07:41 +00:00
|
|
|
end
|
|
|
|
|
2016-07-19 12:59:38 +00:00
|
|
|
context 'has no such ref' do
|
|
|
|
before do
|
2017-02-22 10:13:59 +00:00
|
|
|
get_for_ref('TAIL')
|
2016-07-19 12:59:38 +00:00
|
|
|
end
|
|
|
|
|
2016-07-20 09:38:49 +00:00
|
|
|
it_behaves_like 'not found'
|
2016-07-19 12:59:38 +00:00
|
|
|
end
|
|
|
|
|
2017-01-26 11:52:58 +00:00
|
|
|
context 'has no such job' do
|
2016-07-19 12:59:38 +00:00
|
|
|
before do
|
2017-02-22 10:13:59 +00:00
|
|
|
get_for_ref(pipeline.ref, 'NOBUILD')
|
2016-07-19 12:59:38 +00:00
|
|
|
end
|
|
|
|
|
2016-07-20 09:38:49 +00:00
|
|
|
it_behaves_like 'not found'
|
2016-07-19 12:59:38 +00:00
|
|
|
end
|
2016-07-14 17:07:41 +00:00
|
|
|
end
|
|
|
|
|
2017-01-26 11:52:58 +00:00
|
|
|
context 'find proper job' do
|
2016-07-20 09:30:34 +00:00
|
|
|
shared_examples 'a valid file' do
|
2016-07-20 12:09:29 +00:00
|
|
|
let(:download_headers) do
|
2016-07-14 17:07:41 +00:00
|
|
|
{ 'Content-Transfer-Encoding' => 'binary',
|
|
|
|
'Content-Disposition' =>
|
2017-06-06 14:21:39 +00:00
|
|
|
"attachment; filename=#{job.artifacts_file.filename}" }
|
2016-07-20 12:09:29 +00:00
|
|
|
end
|
2016-07-14 17:07:41 +00:00
|
|
|
|
2016-07-20 09:30:34 +00:00
|
|
|
it { expect(response).to have_http_status(200) }
|
|
|
|
it { expect(response.headers).to include(download_headers) }
|
2016-07-19 12:59:38 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'with regular branch' do
|
|
|
|
before do
|
2016-10-26 09:34:40 +00:00
|
|
|
pipeline.reload
|
2016-07-19 12:59:38 +00:00
|
|
|
pipeline.update(ref: 'master',
|
|
|
|
sha: project.commit('master').sha)
|
|
|
|
|
2017-02-22 10:13:59 +00:00
|
|
|
get_for_ref('master')
|
2016-07-19 12:59:38 +00:00
|
|
|
end
|
|
|
|
|
2016-07-20 09:30:34 +00:00
|
|
|
it_behaves_like 'a valid file'
|
2016-07-14 17:07:41 +00:00
|
|
|
end
|
|
|
|
|
2016-07-19 12:59:38 +00:00
|
|
|
context 'with branch name containing slash' do
|
|
|
|
before do
|
2016-10-26 09:34:40 +00:00
|
|
|
pipeline.reload
|
2016-07-19 12:59:38 +00:00
|
|
|
pipeline.update(ref: 'improve/awesome',
|
|
|
|
sha: project.commit('improve/awesome').sha)
|
|
|
|
end
|
|
|
|
|
|
|
|
before do
|
2017-02-22 10:13:59 +00:00
|
|
|
get_for_ref('improve/awesome')
|
2016-07-19 12:59:38 +00:00
|
|
|
end
|
|
|
|
|
2016-07-20 09:30:34 +00:00
|
|
|
it_behaves_like 'a valid file'
|
2016-07-19 12:59:38 +00:00
|
|
|
end
|
2016-07-14 17:07:41 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-02-22 10:13:59 +00:00
|
|
|
describe 'GET /projects/:id/jobs/:job_id/trace' do
|
2017-06-06 14:21:39 +00:00
|
|
|
let(:job) { create(:ci_build, :trace, pipeline: pipeline) }
|
2016-06-21 12:26:57 +00:00
|
|
|
|
2016-07-14 16:53:27 +00:00
|
|
|
before do
|
2017-06-06 14:21:39 +00:00
|
|
|
get api("/projects/#{project.id}/jobs/#{job.id}/trace", api_user)
|
2016-07-14 16:53:27 +00:00
|
|
|
end
|
2016-02-19 17:06:53 +00:00
|
|
|
|
2016-01-13 17:30:49 +00:00
|
|
|
context 'authorized user' do
|
2017-01-26 11:52:58 +00:00
|
|
|
it 'returns specific job trace' do
|
2016-06-27 18:10:42 +00:00
|
|
|
expect(response).to have_http_status(200)
|
2017-06-06 14:21:39 +00:00
|
|
|
expect(response.body).to eq(job.trace.raw)
|
2015-12-30 14:12:07 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'unauthorized user' do
|
2016-02-19 17:06:53 +00:00
|
|
|
let(:api_user) { nil }
|
2015-12-30 14:12:07 +00:00
|
|
|
|
2017-01-26 11:52:58 +00:00
|
|
|
it 'does not return specific job trace' do
|
2016-06-27 18:10:42 +00:00
|
|
|
expect(response).to have_http_status(401)
|
2015-12-30 14:12:07 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2015-12-30 15:37:47 +00:00
|
|
|
|
2017-02-22 10:13:59 +00:00
|
|
|
describe 'POST /projects/:id/jobs/:job_id/cancel' do
|
2016-07-14 16:53:27 +00:00
|
|
|
before do
|
2017-06-06 14:21:39 +00:00
|
|
|
post api("/projects/#{project.id}/jobs/#{job.id}/cancel", api_user)
|
2016-07-14 16:53:27 +00:00
|
|
|
end
|
2016-02-19 17:06:53 +00:00
|
|
|
|
2015-12-30 15:37:47 +00:00
|
|
|
context 'authorized user' do
|
2016-02-01 22:58:04 +00:00
|
|
|
context 'user with :update_build persmission' do
|
2017-01-26 11:52:58 +00:00
|
|
|
it 'cancels running or pending job' do
|
2016-06-27 18:10:42 +00:00
|
|
|
expect(response).to have_http_status(201)
|
2015-12-30 15:37:47 +00:00
|
|
|
expect(project.builds.first.status).to eq('canceled')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-02-01 22:58:04 +00:00
|
|
|
context 'user without :update_build permission' do
|
2017-05-02 08:29:09 +00:00
|
|
|
let(:api_user) { reporter }
|
2015-12-30 15:37:47 +00:00
|
|
|
|
2017-01-26 11:52:58 +00:00
|
|
|
it 'does not cancel job' do
|
2016-06-27 18:10:42 +00:00
|
|
|
expect(response).to have_http_status(403)
|
2015-12-30 15:37:47 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'unauthorized user' do
|
2016-02-19 17:06:53 +00:00
|
|
|
let(:api_user) { nil }
|
2015-12-30 15:37:47 +00:00
|
|
|
|
2017-01-26 11:52:58 +00:00
|
|
|
it 'does not cancel job' do
|
2016-06-27 18:10:42 +00:00
|
|
|
expect(response).to have_http_status(401)
|
2015-12-30 15:37:47 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-02-22 10:13:59 +00:00
|
|
|
describe 'POST /projects/:id/jobs/:job_id/retry' do
|
2017-06-06 14:21:39 +00:00
|
|
|
let(:job) { create(:ci_build, :canceled, pipeline: pipeline) }
|
2016-02-19 17:06:53 +00:00
|
|
|
|
2016-07-14 16:53:27 +00:00
|
|
|
before do
|
2017-06-06 14:21:39 +00:00
|
|
|
post api("/projects/#{project.id}/jobs/#{job.id}/retry", api_user)
|
2016-07-14 16:53:27 +00:00
|
|
|
end
|
2016-02-19 17:06:53 +00:00
|
|
|
|
2015-12-30 15:37:47 +00:00
|
|
|
context 'authorized user' do
|
2016-02-19 17:06:53 +00:00
|
|
|
context 'user with :update_build permission' do
|
2017-01-26 11:52:58 +00:00
|
|
|
it 'retries non-running job' do
|
2016-06-27 18:10:42 +00:00
|
|
|
expect(response).to have_http_status(201)
|
2015-12-30 15:37:47 +00:00
|
|
|
expect(project.builds.first.status).to eq('canceled')
|
|
|
|
expect(json_response['status']).to eq('pending')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-02-01 22:58:04 +00:00
|
|
|
context 'user without :update_build permission' do
|
2017-05-02 08:29:09 +00:00
|
|
|
let(:api_user) { reporter }
|
2015-12-30 15:37:47 +00:00
|
|
|
|
2017-01-26 11:52:58 +00:00
|
|
|
it 'does not retry job' do
|
2016-06-27 18:10:42 +00:00
|
|
|
expect(response).to have_http_status(403)
|
2015-12-30 15:37:47 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'unauthorized user' do
|
2016-02-19 17:06:53 +00:00
|
|
|
let(:api_user) { nil }
|
2015-12-30 15:37:47 +00:00
|
|
|
|
2017-01-26 11:52:58 +00:00
|
|
|
it 'does not retry job' do
|
2016-06-27 18:10:42 +00:00
|
|
|
expect(response).to have_http_status(401)
|
2015-12-30 15:37:47 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2016-02-03 13:12:33 +00:00
|
|
|
|
2017-02-22 10:13:59 +00:00
|
|
|
describe 'POST /projects/:id/jobs/:job_id/erase' do
|
2016-02-03 13:12:33 +00:00
|
|
|
before do
|
2017-06-06 14:21:39 +00:00
|
|
|
post api("/projects/#{project.id}/jobs/#{job.id}/erase", user)
|
2016-02-03 13:12:33 +00:00
|
|
|
end
|
|
|
|
|
2017-01-26 11:52:58 +00:00
|
|
|
context 'job is erasable' do
|
2017-06-06 14:21:39 +00:00
|
|
|
let(:job) { create(:ci_build, :trace, :artifacts, :success, project: project, pipeline: pipeline) }
|
2016-02-03 13:12:33 +00:00
|
|
|
|
2017-01-26 11:52:58 +00:00
|
|
|
it 'erases job content' do
|
2017-02-22 10:13:59 +00:00
|
|
|
expect(response).to have_http_status(201)
|
2017-06-06 14:21:39 +00:00
|
|
|
expect(job).not_to have_trace
|
|
|
|
expect(job.artifacts_file.exists?).to be_falsy
|
|
|
|
expect(job.artifacts_metadata.exists?).to be_falsy
|
2016-02-03 13:12:33 +00:00
|
|
|
end
|
2016-02-16 12:06:52 +00:00
|
|
|
|
2017-01-26 11:52:58 +00:00
|
|
|
it 'updates job' do
|
2017-06-06 14:21:39 +00:00
|
|
|
job.reload
|
|
|
|
|
|
|
|
expect(job.erased_at).to be_truthy
|
|
|
|
expect(job.erased_by).to eq(user)
|
2016-02-16 12:06:52 +00:00
|
|
|
end
|
2016-02-03 13:12:33 +00:00
|
|
|
end
|
|
|
|
|
2017-01-26 11:52:58 +00:00
|
|
|
context 'job is not erasable' do
|
2017-06-06 14:21:39 +00:00
|
|
|
let(:job) { create(:ci_build, :trace, project: project, pipeline: pipeline) }
|
2016-02-03 13:12:33 +00:00
|
|
|
|
2016-08-01 15:00:44 +00:00
|
|
|
it 'responds with forbidden' do
|
2017-02-22 10:13:59 +00:00
|
|
|
expect(response).to have_http_status(403)
|
2016-02-03 13:12:33 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2016-06-10 15:11:27 +00:00
|
|
|
|
2017-06-06 14:21:39 +00:00
|
|
|
describe 'POST /projects/:id/jobs/:job_id/artifacts/keep' do
|
2016-06-10 15:11:27 +00:00
|
|
|
before do
|
2017-06-06 14:21:39 +00:00
|
|
|
post api("/projects/#{project.id}/jobs/#{job.id}/artifacts/keep", user)
|
2016-06-10 15:11:27 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'artifacts did not expire' do
|
2017-06-06 14:21:39 +00:00
|
|
|
let(:job) do
|
2016-06-10 15:11:27 +00:00
|
|
|
create(:ci_build, :trace, :artifacts, :success,
|
|
|
|
project: project, pipeline: pipeline, artifacts_expire_at: Time.now + 7.days)
|
|
|
|
end
|
|
|
|
|
2016-06-10 19:45:06 +00:00
|
|
|
it 'keeps artifacts' do
|
2017-02-22 10:13:59 +00:00
|
|
|
expect(response).to have_http_status(200)
|
2017-06-06 14:21:39 +00:00
|
|
|
expect(job.reload.artifacts_expire_at).to be_nil
|
2016-06-10 15:11:27 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'no artifacts' do
|
2017-06-06 14:21:39 +00:00
|
|
|
let(:job) { create(:ci_build, project: project, pipeline: pipeline) }
|
2016-06-10 15:11:27 +00:00
|
|
|
|
2016-06-10 19:45:06 +00:00
|
|
|
it 'responds with not found' do
|
2017-02-22 10:13:59 +00:00
|
|
|
expect(response).to have_http_status(404)
|
2016-06-10 15:11:27 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2016-08-15 13:58:22 +00:00
|
|
|
|
2017-02-22 10:13:59 +00:00
|
|
|
describe 'POST /projects/:id/jobs/:job_id/play' do
|
2016-08-15 13:58:22 +00:00
|
|
|
before do
|
2017-06-06 14:21:39 +00:00
|
|
|
post api("/projects/#{project.id}/jobs/#{job.id}/play", api_user)
|
2016-08-15 13:58:22 +00:00
|
|
|
end
|
|
|
|
|
2017-01-26 11:52:58 +00:00
|
|
|
context 'on an playable job' do
|
2017-06-06 14:21:39 +00:00
|
|
|
let(:job) { create(:ci_build, :manual, project: project, pipeline: pipeline) }
|
2016-08-15 13:58:22 +00:00
|
|
|
|
2017-05-02 08:29:09 +00:00
|
|
|
context 'when user is authorized to trigger a manual action' do
|
|
|
|
it 'plays the job' do
|
|
|
|
expect(response).to have_http_status(200)
|
|
|
|
expect(json_response['user']['id']).to eq(user.id)
|
2017-06-06 14:21:39 +00:00
|
|
|
expect(json_response['id']).to eq(job.id)
|
|
|
|
expect(job.reload).to be_pending
|
2017-05-02 08:29:09 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when user is not authorized to trigger a manual action' do
|
|
|
|
context 'when user does not have access to the project' do
|
|
|
|
let(:api_user) { create(:user) }
|
|
|
|
|
|
|
|
it 'does not trigger a manual action' do
|
2017-06-06 14:21:39 +00:00
|
|
|
expect(job.reload).to be_manual
|
2017-05-02 08:29:09 +00:00
|
|
|
expect(response).to have_http_status(404)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when user is not allowed to trigger the manual action' do
|
|
|
|
let(:api_user) { reporter }
|
|
|
|
|
|
|
|
it 'does not trigger a manual action' do
|
2017-06-06 14:21:39 +00:00
|
|
|
expect(job.reload).to be_manual
|
2017-05-02 08:29:09 +00:00
|
|
|
expect(response).to have_http_status(403)
|
|
|
|
end
|
|
|
|
end
|
2016-08-15 13:58:22 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-01-26 11:52:58 +00:00
|
|
|
context 'on a non-playable job' do
|
2016-08-15 13:58:22 +00:00
|
|
|
it 'returns a status code 400, Bad Request' do
|
|
|
|
expect(response).to have_http_status 400
|
2017-01-26 11:52:58 +00:00
|
|
|
expect(response.body).to match("Unplayable Job")
|
2016-08-15 13:58:22 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2015-12-29 22:12:36 +00:00
|
|
|
end
|