BigW Consortium Gitlab

Commit a17bf380 by Tomasz Maczukin

Add cancel/retry features to builds API

parent 593d87ea
...@@ -60,5 +60,9 @@ FactoryGirl.define do ...@@ -60,5 +60,9 @@ FactoryGirl.define do
id 999 id 999
trace 'BUILD TRACE' trace 'BUILD TRACE'
end end
factory :ci_build_canceled do
status 'canceled'
end
end end
end end
...@@ -7,10 +7,11 @@ describe API::API, api: true do ...@@ -7,10 +7,11 @@ describe API::API, api: true do
let(:user2) { create(:user) } let(:user2) { create(:user) }
let!(:project) { create(:project, creator_id: user.id) } let!(:project) { create(:project, creator_id: user.id) }
let!(:master) { create(:project_member, user: user, project: project, access_level: ProjectMember::MASTER) } let!(:master) { create(:project_member, user: user, project: project, access_level: ProjectMember::MASTER) }
let!(:guest) { create(:project_member, user: user2, project: project, access_level: ProjectMember::GUEST) } let!(:reporter) { create(:project_member, user: user2, project: project, access_level: ProjectMember::REPORTER) }
let(:commit) { create(:ci_commit, project: project)} let(:commit) { create(:ci_commit, project: project)}
let(:build) { create(:ci_build, commit: commit) } let(:build) { create(:ci_build, commit: commit) }
let(:build_with_trace) { create(:ci_build_with_trace, commit: commit) } let(:build_with_trace) { create(:ci_build_with_trace, commit: commit) }
let(:build_canceled) { create(:ci_build_canceled, commit: commit) }
describe 'GET /projects/:id/builds ' do describe 'GET /projects/:id/builds ' do
context 'authorized user' do context 'authorized user' do
...@@ -85,4 +86,63 @@ describe API::API, api: true do ...@@ -85,4 +86,63 @@ describe API::API, api: true do
end end
end end
end end
describe 'GET /projects/:id/builds/:build_id/cancel' do
context 'authorized user' do
context 'user with :manage_builds persmission' do
it 'should cancel running or pending build' do
post api("/projects/#{project.id}/builds/#{build.id}/cancel", user)
expect(response.status).to eq(201)
expect(project.builds.first.status).to eq('canceled')
end
end
context 'user without :manage_builds permission' do
it 'should not cancel build' do
post api("/projects/#{project.id}/builds/#{build.id}/cancel", user2)
expect(response.status).to eq(403)
end
end
end
context 'unauthorized user' do
it 'should not cancel build' do
post api("/projects/#{project.id}/builds/#{build.id}/cancel")
expect(response.status).to eq(401)
end
end
end
describe 'GET /projects/:id/builds/:build_id/retry' do
context 'authorized user' do
context 'user with :manage_builds persmission' do
it 'should retry non-running build' do
post api("/projects/#{project.id}/builds/#{build_canceled.id}/retry", user)
expect(response.status).to eq(201)
expect(project.builds.first.status).to eq('canceled')
expect(json_response['status']).to eq('pending')
end
end
context 'user without :manage_builds permission' do
it 'should not retry build' do
post api("/projects/#{project.id}/builds/#{build_canceled.id}/retry", user2)
expect(response.status).to eq(403)
end
end
end
context 'unauthorized user' do
it 'should not retry build' do
post api("/projects/#{project.id}/builds/#{build_canceled.id}/retry")
expect(response.status).to eq(401)
end
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