2015-12-29 17:12:36 -05:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2016-11-23 15:14:08 -05:00
|
|
|
describe API::Builds, api: true do
|
2015-12-29 17:12:36 -05:00
|
|
|
include ApiHelpers
|
|
|
|
|
|
|
|
let(:user) { create(:user) }
|
2016-02-19 12:06:53 -05:00
|
|
|
let(:api_user) { user }
|
2017-01-26 18:51:57 -05:00
|
|
|
let!(:project) { create(:project, :repository, creator: user, public_builds: false) }
|
2016-07-19 13:24:59 -04:00
|
|
|
let!(:developer) { create(:project_member, :developer, user: user, project: project) }
|
2016-07-20 12:09:35 -04:00
|
|
|
let(:reporter) { create(:project_member, :reporter, project: project) }
|
|
|
|
let(:guest) { create(:project_member, :guest, project: project) }
|
2016-08-11 16:54:25 -04:00
|
|
|
let!(:pipeline) { create(:ci_empty_pipeline, project: project, sha: project.commit.id, ref: project.default_branch) }
|
2016-07-19 13:24:59 -04:00
|
|
|
let!(:build) { create(:ci_build, pipeline: pipeline) }
|
2015-12-29 17:12:36 -05:00
|
|
|
|
|
|
|
describe 'GET /projects/:id/builds ' do
|
2016-02-19 12:06:53 -05:00
|
|
|
let(:query) { '' }
|
|
|
|
|
2016-07-14 12:53:27 -04:00
|
|
|
before do
|
|
|
|
get api("/projects/#{project.id}/builds?#{query}", api_user)
|
|
|
|
end
|
2016-02-19 12:06:53 -05:00
|
|
|
|
2015-12-29 17:12:36 -05:00
|
|
|
context 'authorized user' do
|
2016-08-01 11:00:44 -04:00
|
|
|
it 'returns project builds' do
|
2016-06-27 14:10:42 -04:00
|
|
|
expect(response).to have_http_status(200)
|
2016-01-08 08:01:31 -05:00
|
|
|
expect(json_response).to be_an Array
|
|
|
|
end
|
|
|
|
|
2016-06-21 08:26:57 -04: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 19:43:57 -04:00
|
|
|
it 'returns pipeline data' do
|
|
|
|
json_build = json_response.first
|
|
|
|
expect(json_build['pipeline']).not_to be_empty
|
|
|
|
expect(json_build['pipeline']['id']).to eq build.pipeline.id
|
|
|
|
expect(json_build['pipeline']['ref']).to eq build.pipeline.ref
|
|
|
|
expect(json_build['pipeline']['sha']).to eq build.pipeline.sha
|
|
|
|
expect(json_build['pipeline']['status']).to eq build.pipeline.status
|
|
|
|
end
|
|
|
|
|
2016-02-19 12:06:53 -05:00
|
|
|
context 'filter project with one scope element' do
|
|
|
|
let(:query) { 'scope=pending' }
|
2016-01-08 08:01:31 -05:00
|
|
|
|
2016-02-19 12:06:53 -05:00
|
|
|
it do
|
2016-06-27 14:10:42 -04:00
|
|
|
expect(response).to have_http_status(200)
|
2016-02-19 12:06:53 -05:00
|
|
|
expect(json_response).to be_an Array
|
|
|
|
end
|
2016-01-08 08:01:31 -05:00
|
|
|
end
|
|
|
|
|
2016-02-19 12:06:53 -05:00
|
|
|
context 'filter project with array of scope elements' do
|
|
|
|
let(:query) { 'scope[0]=pending&scope[1]=running' }
|
2016-01-08 08:01:31 -05:00
|
|
|
|
2016-02-19 12:06:53 -05:00
|
|
|
it do
|
2016-06-27 14:10:42 -04:00
|
|
|
expect(response).to have_http_status(200)
|
2016-02-19 12:06:53 -05:00
|
|
|
expect(json_response).to be_an Array
|
|
|
|
end
|
2015-12-29 17:12:36 -05:00
|
|
|
end
|
2016-01-13 09:17:59 -05:00
|
|
|
|
2016-02-19 12:06:53 -05:00
|
|
|
context 'respond 400 when scope contains invalid state' do
|
|
|
|
let(:query) { 'scope[0]=pending&scope[1]=unknown_status' }
|
2016-01-13 09:17:59 -05:00
|
|
|
|
2016-06-27 14:10:42 -04:00
|
|
|
it { expect(response).to have_http_status(400) }
|
2016-01-13 09:17:59 -05:00
|
|
|
end
|
2015-12-29 17:12:36 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'unauthorized user' do
|
2016-02-19 12:06:53 -05:00
|
|
|
let(:api_user) { nil }
|
2015-12-29 17:12:36 -05:00
|
|
|
|
2016-02-19 12:06:53 -05:00
|
|
|
it 'should not return project builds' do
|
2016-06-27 14:10:42 -04:00
|
|
|
expect(response).to have_http_status(401)
|
2015-12-29 17:12:36 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-01-11 04:20:45 -05:00
|
|
|
describe 'GET /projects/:id/repository/commits/:sha/builds' do
|
2016-06-28 06:22:31 -04:00
|
|
|
context 'when commit does not exist in repository' do
|
|
|
|
before do
|
|
|
|
get api("/projects/#{project.id}/repository/commits/1a271fd1/builds", api_user)
|
|
|
|
end
|
2016-06-22 02:53:05 -04:00
|
|
|
|
2016-06-28 06:22:31 -04:00
|
|
|
it 'responds with 404' do
|
|
|
|
expect(response).to have_http_status(404)
|
|
|
|
end
|
2016-02-19 12:06:53 -05:00
|
|
|
end
|
|
|
|
|
2016-06-28 06:22:31 -04:00
|
|
|
context 'when commit exists in repository' do
|
|
|
|
context 'when user is authorized' do
|
|
|
|
context 'when pipeline has builds' do
|
|
|
|
before do
|
2016-07-21 06:47:05 -04:00
|
|
|
create(:ci_pipeline, project: project, sha: project.commit.id)
|
2016-06-28 06:22:31 -04:00
|
|
|
create(:ci_build, pipeline: pipeline)
|
2016-07-21 06:47:05 -04:00
|
|
|
create(:ci_build)
|
2016-06-28 06:22:31 -04:00
|
|
|
|
|
|
|
get api("/projects/#{project.id}/repository/commits/#{project.commit.id}/builds", api_user)
|
|
|
|
end
|
|
|
|
|
2016-08-01 11:00:44 -04:00
|
|
|
it 'returns project builds for specific commit' do
|
2016-06-28 06:22:31 -04:00
|
|
|
expect(response).to have_http_status(200)
|
|
|
|
expect(json_response).to be_an Array
|
|
|
|
expect(json_response.size).to eq 2
|
|
|
|
end
|
2016-09-23 19:43:57 -04:00
|
|
|
|
|
|
|
it 'returns pipeline data' do
|
|
|
|
json_build = json_response.first
|
|
|
|
expect(json_build['pipeline']).not_to be_empty
|
|
|
|
expect(json_build['pipeline']['id']).to eq build.pipeline.id
|
|
|
|
expect(json_build['pipeline']['ref']).to eq build.pipeline.ref
|
|
|
|
expect(json_build['pipeline']['sha']).to eq build.pipeline.sha
|
|
|
|
expect(json_build['pipeline']['status']).to eq build.pipeline.status
|
|
|
|
end
|
2016-06-28 06:22:31 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'when pipeline has no builds' do
|
|
|
|
before do
|
|
|
|
branch_head = project.commit('feature').id
|
|
|
|
get api("/projects/#{project.id}/repository/commits/#{branch_head}/builds", api_user)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns an empty array' do
|
|
|
|
expect(response).to have_http_status(200)
|
|
|
|
expect(json_response).to be_an Array
|
|
|
|
expect(json_response).to be_empty
|
|
|
|
end
|
|
|
|
end
|
2015-12-29 17:12:36 -05:00
|
|
|
end
|
|
|
|
|
2016-06-28 06:22:31 -04:00
|
|
|
context 'when user is not authorized' do
|
|
|
|
before do
|
2016-07-21 06:47:05 -04:00
|
|
|
create(:ci_pipeline, project: project, sha: project.commit.id)
|
|
|
|
create(:ci_build, pipeline: pipeline)
|
2015-12-29 17:12:36 -05:00
|
|
|
|
2016-06-28 06:22:31 -04:00
|
|
|
get api("/projects/#{project.id}/repository/commits/#{project.commit.id}/builds", nil)
|
|
|
|
end
|
|
|
|
|
2016-08-01 11:00:44 -04:00
|
|
|
it 'does not return project builds' do
|
2016-06-28 06:22:31 -04:00
|
|
|
expect(response).to have_http_status(401)
|
|
|
|
expect(json_response.except('message')).to be_empty
|
|
|
|
end
|
2015-12-29 17:12:36 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2015-12-30 09:12:07 -05:00
|
|
|
|
2016-01-13 12:30:49 -05:00
|
|
|
describe 'GET /projects/:id/builds/:build_id' do
|
2016-07-14 12:53:27 -04:00
|
|
|
before do
|
|
|
|
get api("/projects/#{project.id}/builds/#{build.id}", api_user)
|
|
|
|
end
|
2016-02-19 12:06:53 -05:00
|
|
|
|
2015-12-30 09:12:07 -05:00
|
|
|
context 'authorized user' do
|
2016-08-01 11:00:44 -04:00
|
|
|
it 'returns specific build data' do
|
2016-06-27 14:10:42 -04:00
|
|
|
expect(response).to have_http_status(200)
|
2015-12-30 09:12:07 -05:00
|
|
|
expect(json_response['name']).to eq('test')
|
|
|
|
end
|
2016-09-23 19:43:57 -04:00
|
|
|
|
|
|
|
it 'returns pipeline data' do
|
|
|
|
json_build = json_response
|
|
|
|
expect(json_build['pipeline']).not_to be_empty
|
|
|
|
expect(json_build['pipeline']['id']).to eq build.pipeline.id
|
|
|
|
expect(json_build['pipeline']['ref']).to eq build.pipeline.ref
|
|
|
|
expect(json_build['pipeline']['sha']).to eq build.pipeline.sha
|
|
|
|
expect(json_build['pipeline']['status']).to eq build.pipeline.status
|
|
|
|
end
|
2016-01-13 12:30:49 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'unauthorized user' do
|
2016-02-19 12:06:53 -05:00
|
|
|
let(:api_user) { nil }
|
2015-12-30 09:12:07 -05:00
|
|
|
|
2016-08-01 11:00:44 -04:00
|
|
|
it 'does not return specific build data' do
|
2016-06-27 14:10:42 -04:00
|
|
|
expect(response).to have_http_status(401)
|
2016-01-13 12:30:49 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-02-08 16:32:36 -05:00
|
|
|
describe 'GET /projects/:id/builds/:build_id/artifacts' do
|
2016-07-14 12:53:27 -04:00
|
|
|
before do
|
|
|
|
get api("/projects/#{project.id}/builds/#{build.id}/artifacts", api_user)
|
|
|
|
end
|
2016-02-08 16:32:36 -05:00
|
|
|
|
2016-02-19 12:06:53 -05:00
|
|
|
context 'build with artifacts' do
|
2016-06-03 10:22:26 -04:00
|
|
|
let(:build) { create(:ci_build, :artifacts, pipeline: pipeline) }
|
2016-02-08 16:32:36 -05:00
|
|
|
|
2016-02-19 12:06:53 -05:00
|
|
|
context 'authorized user' do
|
|
|
|
let(:download_headers) do
|
2016-05-10 22:58:06 -04:00
|
|
|
{ 'Content-Transfer-Encoding' => 'binary',
|
|
|
|
'Content-Disposition' => 'attachment; filename=ci_build_artifacts.zip' }
|
2016-02-19 12:06:53 -05:00
|
|
|
end
|
2016-02-08 16:32:36 -05:00
|
|
|
|
2016-08-01 11:00:44 -04:00
|
|
|
it 'returns specific build artifacts' do
|
2016-06-27 14:10:42 -04:00
|
|
|
expect(response).to have_http_status(200)
|
2016-02-19 12:06:53 -05:00
|
|
|
expect(response.headers).to include(download_headers)
|
|
|
|
end
|
2016-02-08 16:32:36 -05:00
|
|
|
end
|
|
|
|
|
2016-02-19 12:06:53 -05:00
|
|
|
context 'unauthorized user' do
|
|
|
|
let(:api_user) { nil }
|
2016-02-08 16:32:36 -05:00
|
|
|
|
2016-08-01 11:00:44 -04:00
|
|
|
it 'does not return specific build artifacts' do
|
2016-06-27 14:10:42 -04:00
|
|
|
expect(response).to have_http_status(401)
|
2016-02-19 12:06:53 -05:00
|
|
|
end
|
2016-02-08 16:32:36 -05:00
|
|
|
end
|
|
|
|
end
|
2016-02-19 12:06:53 -05:00
|
|
|
|
2016-08-01 11:00:44 -04:00
|
|
|
it 'does not return build artifacts if not uploaded' do
|
2016-06-27 14:10:42 -04:00
|
|
|
expect(response).to have_http_status(404)
|
2016-02-19 12:06:53 -05:00
|
|
|
end
|
2016-02-08 16:32:36 -05:00
|
|
|
end
|
|
|
|
|
2016-07-14 14:01:10 -04:00
|
|
|
describe 'GET /projects/:id/artifacts/:ref_name/download?job=name' do
|
2016-07-20 12:09:35 -04:00
|
|
|
let(:api_user) { reporter.user }
|
2016-08-11 16:54:25 -04:00
|
|
|
let(:build) { create(:ci_build, :artifacts, pipeline: pipeline) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
build.success
|
|
|
|
end
|
2016-07-14 13:07:41 -04:00
|
|
|
|
2016-07-19 12:39:41 -04:00
|
|
|
def path_for_ref(ref = pipeline.ref, job = build.name)
|
2016-07-19 13:24:59 -04:00
|
|
|
api("/projects/#{project.id}/builds/artifacts/#{ref}/download?job=#{job}", api_user)
|
2016-07-14 13:07:41 -04:00
|
|
|
end
|
|
|
|
|
2016-07-20 11:19:35 -04:00
|
|
|
context 'when not logged in' do
|
2016-07-19 13:24:59 -04:00
|
|
|
let(:api_user) { nil }
|
2016-07-14 13:07:41 -04:00
|
|
|
|
|
|
|
before do
|
2016-07-19 12:39:41 -04:00
|
|
|
get path_for_ref
|
2016-07-14 13:07:41 -04:00
|
|
|
end
|
|
|
|
|
2016-07-20 10:02:42 -04:00
|
|
|
it 'gives 401' do
|
2016-07-14 13:07:41 -04:00
|
|
|
expect(response).to have_http_status(401)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-07-20 11:17:49 -04:00
|
|
|
context 'when logging as guest' do
|
2016-07-20 12:09:35 -04:00
|
|
|
let(:api_user) { guest.user }
|
2016-07-20 10:40:49 -04:00
|
|
|
|
|
|
|
before do
|
|
|
|
get path_for_ref
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'gives 403' do
|
|
|
|
expect(response).to have_http_status(403)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-07-19 08:59:38 -04:00
|
|
|
context 'non-existing build' do
|
2016-07-20 05:38:49 -04:00
|
|
|
shared_examples 'not found' do
|
|
|
|
it { expect(response).to have_http_status(:not_found) }
|
2016-07-14 13:07:41 -04:00
|
|
|
end
|
|
|
|
|
2016-07-19 08:59:38 -04:00
|
|
|
context 'has no such ref' do
|
|
|
|
before do
|
2016-07-19 12:39:41 -04:00
|
|
|
get path_for_ref('TAIL', build.name)
|
2016-07-19 08:59:38 -04:00
|
|
|
end
|
|
|
|
|
2016-07-20 05:38:49 -04:00
|
|
|
it_behaves_like 'not found'
|
2016-07-19 08:59:38 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'has no such build' do
|
|
|
|
before do
|
2016-07-19 12:39:41 -04:00
|
|
|
get path_for_ref(pipeline.ref, 'NOBUILD')
|
2016-07-19 08:59:38 -04:00
|
|
|
end
|
|
|
|
|
2016-07-20 05:38:49 -04:00
|
|
|
it_behaves_like 'not found'
|
2016-07-19 08:59:38 -04:00
|
|
|
end
|
2016-07-14 13:07:41 -04:00
|
|
|
end
|
|
|
|
|
2016-07-19 08:59:38 -04:00
|
|
|
context 'find proper build' do
|
2016-07-20 05:30:34 -04:00
|
|
|
shared_examples 'a valid file' do
|
2016-07-20 08:09:29 -04:00
|
|
|
let(:download_headers) do
|
2016-07-14 13:07:41 -04:00
|
|
|
{ 'Content-Transfer-Encoding' => 'binary',
|
|
|
|
'Content-Disposition' =>
|
|
|
|
"attachment; filename=#{build.artifacts_file.filename}" }
|
2016-07-20 08:09:29 -04:00
|
|
|
end
|
2016-07-14 13:07:41 -04:00
|
|
|
|
2016-07-20 05:30:34 -04:00
|
|
|
it { expect(response).to have_http_status(200) }
|
|
|
|
it { expect(response.headers).to include(download_headers) }
|
2016-07-19 08:59:38 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'with regular branch' do
|
|
|
|
before do
|
2016-10-26 05:34:40 -04:00
|
|
|
pipeline.reload
|
2016-07-19 08:59:38 -04:00
|
|
|
pipeline.update(ref: 'master',
|
|
|
|
sha: project.commit('master').sha)
|
|
|
|
|
2016-07-19 12:39:41 -04:00
|
|
|
get path_for_ref('master')
|
2016-07-19 08:59:38 -04:00
|
|
|
end
|
|
|
|
|
2016-07-20 05:30:34 -04:00
|
|
|
it_behaves_like 'a valid file'
|
2016-07-14 13:07:41 -04:00
|
|
|
end
|
|
|
|
|
2016-07-19 08:59:38 -04:00
|
|
|
context 'with branch name containing slash' do
|
|
|
|
before do
|
2016-10-26 05:34:40 -04:00
|
|
|
pipeline.reload
|
2016-07-19 08:59:38 -04:00
|
|
|
pipeline.update(ref: 'improve/awesome',
|
|
|
|
sha: project.commit('improve/awesome').sha)
|
|
|
|
end
|
|
|
|
|
|
|
|
before do
|
2016-07-19 12:39:41 -04:00
|
|
|
get path_for_ref('improve/awesome')
|
2016-07-19 08:59:38 -04:00
|
|
|
end
|
|
|
|
|
2016-07-20 05:30:34 -04:00
|
|
|
it_behaves_like 'a valid file'
|
2016-07-19 08:59:38 -04:00
|
|
|
end
|
2016-07-14 13:07:41 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-01-13 12:30:49 -05:00
|
|
|
describe 'GET /projects/:id/builds/:build_id/trace' do
|
2016-06-03 10:22:26 -04:00
|
|
|
let(:build) { create(:ci_build, :trace, pipeline: pipeline) }
|
2016-06-21 08:26:57 -04:00
|
|
|
|
2016-07-14 12:53:27 -04:00
|
|
|
before do
|
|
|
|
get api("/projects/#{project.id}/builds/#{build.id}/trace", api_user)
|
|
|
|
end
|
2016-02-19 12:06:53 -05:00
|
|
|
|
2016-01-13 12:30:49 -05:00
|
|
|
context 'authorized user' do
|
2016-08-01 11:00:44 -04:00
|
|
|
it 'returns specific build trace' do
|
2016-06-27 14:10:42 -04:00
|
|
|
expect(response).to have_http_status(200)
|
2016-02-19 12:06:53 -05:00
|
|
|
expect(response.body).to eq(build.trace)
|
2015-12-30 09:12:07 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'unauthorized user' do
|
2016-02-19 12:06:53 -05:00
|
|
|
let(:api_user) { nil }
|
2015-12-30 09:12:07 -05:00
|
|
|
|
2016-08-01 11:00:44 -04:00
|
|
|
it 'does not return specific build trace' do
|
2016-06-27 14:10:42 -04:00
|
|
|
expect(response).to have_http_status(401)
|
2015-12-30 09:12:07 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2015-12-30 10:37:47 -05:00
|
|
|
|
2016-01-08 17:33:45 -05:00
|
|
|
describe 'POST /projects/:id/builds/:build_id/cancel' do
|
2016-07-14 12:53:27 -04:00
|
|
|
before do
|
|
|
|
post api("/projects/#{project.id}/builds/#{build.id}/cancel", api_user)
|
|
|
|
end
|
2016-02-19 12:06:53 -05:00
|
|
|
|
2015-12-30 10:37:47 -05:00
|
|
|
context 'authorized user' do
|
2016-02-01 17:58:04 -05:00
|
|
|
context 'user with :update_build persmission' do
|
2016-08-01 11:00:44 -04:00
|
|
|
it 'cancels running or pending build' do
|
2016-06-27 14:10:42 -04:00
|
|
|
expect(response).to have_http_status(201)
|
2015-12-30 10:37:47 -05:00
|
|
|
expect(project.builds.first.status).to eq('canceled')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-02-01 17:58:04 -05:00
|
|
|
context 'user without :update_build permission' do
|
2016-07-20 12:09:35 -04:00
|
|
|
let(:api_user) { reporter.user }
|
2015-12-30 10:37:47 -05:00
|
|
|
|
2016-08-01 11:00:44 -04:00
|
|
|
it 'does not cancel build' do
|
2016-06-27 14:10:42 -04:00
|
|
|
expect(response).to have_http_status(403)
|
2015-12-30 10:37:47 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'unauthorized user' do
|
2016-02-19 12:06:53 -05:00
|
|
|
let(:api_user) { nil }
|
2015-12-30 10:37:47 -05:00
|
|
|
|
2016-08-01 11:00:44 -04:00
|
|
|
it 'does not cancel build' do
|
2016-06-27 14:10:42 -04:00
|
|
|
expect(response).to have_http_status(401)
|
2015-12-30 10:37:47 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-01-08 17:33:45 -05:00
|
|
|
describe 'POST /projects/:id/builds/:build_id/retry' do
|
2016-06-03 10:22:26 -04:00
|
|
|
let(:build) { create(:ci_build, :canceled, pipeline: pipeline) }
|
2016-02-19 12:06:53 -05:00
|
|
|
|
2016-07-14 12:53:27 -04:00
|
|
|
before do
|
|
|
|
post api("/projects/#{project.id}/builds/#{build.id}/retry", api_user)
|
|
|
|
end
|
2016-02-19 12:06:53 -05:00
|
|
|
|
2015-12-30 10:37:47 -05:00
|
|
|
context 'authorized user' do
|
2016-02-19 12:06:53 -05:00
|
|
|
context 'user with :update_build permission' do
|
2016-08-01 11:00:44 -04:00
|
|
|
it 'retries non-running build' do
|
2016-06-27 14:10:42 -04:00
|
|
|
expect(response).to have_http_status(201)
|
2015-12-30 10:37:47 -05:00
|
|
|
expect(project.builds.first.status).to eq('canceled')
|
|
|
|
expect(json_response['status']).to eq('pending')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-02-01 17:58:04 -05:00
|
|
|
context 'user without :update_build permission' do
|
2016-07-20 12:09:35 -04:00
|
|
|
let(:api_user) { reporter.user }
|
2015-12-30 10:37:47 -05:00
|
|
|
|
2016-08-01 11:00:44 -04:00
|
|
|
it 'does not retry build' do
|
2016-06-27 14:10:42 -04:00
|
|
|
expect(response).to have_http_status(403)
|
2015-12-30 10:37:47 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'unauthorized user' do
|
2016-02-19 12:06:53 -05:00
|
|
|
let(:api_user) { nil }
|
2015-12-30 10:37:47 -05:00
|
|
|
|
2016-08-01 11:00:44 -04:00
|
|
|
it 'does not retry build' do
|
2016-06-27 14:10:42 -04:00
|
|
|
expect(response).to have_http_status(401)
|
2015-12-30 10:37:47 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2016-02-03 08:12:33 -05:00
|
|
|
|
2016-02-16 03:30:58 -05:00
|
|
|
describe 'POST /projects/:id/builds/:build_id/erase' do
|
2016-02-03 08:12:33 -05:00
|
|
|
before do
|
2016-02-16 03:30:58 -05:00
|
|
|
post api("/projects/#{project.id}/builds/#{build.id}/erase", user)
|
2016-02-03 08:12:33 -05:00
|
|
|
end
|
|
|
|
|
2016-02-05 02:22:29 -05:00
|
|
|
context 'build is erasable' do
|
2016-06-03 10:22:26 -04:00
|
|
|
let(:build) { create(:ci_build, :trace, :artifacts, :success, project: project, pipeline: pipeline) }
|
2016-02-03 08:12:33 -05:00
|
|
|
|
2016-08-01 11:00:44 -04:00
|
|
|
it 'erases build content' do
|
2016-02-16 03:30:58 -05:00
|
|
|
expect(response.status).to eq 201
|
2016-02-03 08:12:33 -05:00
|
|
|
expect(build.trace).to be_empty
|
|
|
|
expect(build.artifacts_file.exists?).to be_falsy
|
|
|
|
expect(build.artifacts_metadata.exists?).to be_falsy
|
|
|
|
end
|
2016-02-16 07:06:52 -05:00
|
|
|
|
2016-08-01 11:00:44 -04:00
|
|
|
it 'updates build' do
|
2016-02-16 07:06:52 -05:00
|
|
|
expect(build.reload.erased_at).to be_truthy
|
|
|
|
expect(build.reload.erased_by).to eq user
|
|
|
|
end
|
2016-02-03 08:12:33 -05:00
|
|
|
end
|
|
|
|
|
2016-02-05 02:22:29 -05:00
|
|
|
context 'build is not erasable' do
|
2016-06-03 10:22:26 -04:00
|
|
|
let(:build) { create(:ci_build, :trace, project: project, pipeline: pipeline) }
|
2016-02-03 08:12:33 -05:00
|
|
|
|
2016-08-01 11:00:44 -04:00
|
|
|
it 'responds with forbidden' do
|
2016-02-03 08:12:33 -05:00
|
|
|
expect(response.status).to eq 403
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2016-06-10 11:11:27 -04:00
|
|
|
|
|
|
|
describe 'POST /projects/:id/builds/:build_id/artifacts/keep' do
|
|
|
|
before do
|
|
|
|
post api("/projects/#{project.id}/builds/#{build.id}/artifacts/keep", user)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'artifacts did not expire' do
|
|
|
|
let(:build) do
|
|
|
|
create(:ci_build, :trace, :artifacts, :success,
|
|
|
|
project: project, pipeline: pipeline, artifacts_expire_at: Time.now + 7.days)
|
|
|
|
end
|
|
|
|
|
2016-06-10 15:45:06 -04:00
|
|
|
it 'keeps artifacts' do
|
2016-06-10 11:11:27 -04:00
|
|
|
expect(response.status).to eq 200
|
2016-06-10 15:45:06 -04:00
|
|
|
expect(build.reload.artifacts_expire_at).to be_nil
|
2016-06-10 11:11:27 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'no artifacts' do
|
|
|
|
let(:build) { create(:ci_build, project: project, pipeline: pipeline) }
|
|
|
|
|
2016-06-10 15:45:06 -04:00
|
|
|
it 'responds with not found' do
|
2016-06-10 11:11:27 -04:00
|
|
|
expect(response.status).to eq 404
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2016-08-15 09:58:22 -04:00
|
|
|
|
|
|
|
describe 'POST /projects/:id/builds/:build_id/play' do
|
|
|
|
before do
|
|
|
|
post api("/projects/#{project.id}/builds/#{build.id}/play", user)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'on an playable build' do
|
|
|
|
let(:build) { create(:ci_build, :manual, project: project, pipeline: pipeline) }
|
|
|
|
|
|
|
|
it 'plays the build' do
|
|
|
|
expect(response).to have_http_status 200
|
|
|
|
expect(json_response['user']['id']).to eq(user.id)
|
2016-08-18 05:42:37 -04:00
|
|
|
expect(json_response['id']).to eq(build.id)
|
2016-08-15 09:58:22 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'on a non-playable build' do
|
|
|
|
it 'returns a status code 400, Bad Request' do
|
|
|
|
expect(response).to have_http_status 400
|
|
|
|
expect(response.body).to match("Unplayable Build")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2015-12-29 17:12:36 -05:00
|
|
|
end
|