Change response for /ci/api/v1/builds/register.json from 404 to 204
This commit is contained in:
parent
404f438f45
commit
940f900f1c
4 changed files with 44 additions and 20 deletions
|
@ -269,6 +269,10 @@ module API
|
|||
render_api_error!('304 Not Modified', 304)
|
||||
end
|
||||
|
||||
def no_content!
|
||||
render_api_error!('204 No Content', 204)
|
||||
end
|
||||
|
||||
def render_validation_error!(model)
|
||||
if model.errors.any?
|
||||
render_api_error!(model.errors.messages || '400 Bad Request', 400)
|
||||
|
|
|
@ -27,7 +27,7 @@ module Ci
|
|||
else
|
||||
Gitlab::Metrics.add_event(:build_not_found)
|
||||
|
||||
not_found!
|
||||
build_not_found!
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -32,6 +32,14 @@ module Ci
|
|||
end
|
||||
end
|
||||
|
||||
def build_not_found!
|
||||
if headers['User-Agent'].match(/gitlab-ci-multi-runner \d+\.\d+\.\d+(~beta\.\d+\.g[0-9a-f]+)? /)
|
||||
no_content!
|
||||
else
|
||||
not_found!
|
||||
end
|
||||
end
|
||||
|
||||
def current_runner
|
||||
@runner ||= Runner.find_by_token(params[:token].to_s)
|
||||
end
|
||||
|
|
|
@ -15,6 +15,25 @@ describe Ci::API::API do
|
|||
|
||||
describe "POST /builds/register" do
|
||||
let!(:build) { create(:ci_build, pipeline: pipeline, name: 'spinach', stage: 'test', stage_idx: 0) }
|
||||
let(:user_agent) { 'gitlab-ci-multi-runner 1.5.2 (1-5-stable; go1.6.3; linux/amd64)' }
|
||||
|
||||
shared_examples 'no builds available' do
|
||||
context 'when runner sends version in User-Agent' do
|
||||
context 'for stable version' do
|
||||
it { expect(response).to have_http_status(204) }
|
||||
end
|
||||
|
||||
context 'for beta version' do
|
||||
let(:user_agent) { 'gitlab-ci-multi-runner 1.6.0~beta.167.g2b2bacc (1-5-stable; go1.6.3; linux/amd64)' }
|
||||
it { expect(response).to have_http_status(204) }
|
||||
end
|
||||
end
|
||||
|
||||
context "when runner doesn't send version in User-Agent" do
|
||||
let(:user_agent) { 'Go-http-client/1.1' }
|
||||
it { expect(response).to have_http_status(404) }
|
||||
end
|
||||
end
|
||||
|
||||
it "starts a build" do
|
||||
register_builds info: { platform: :darwin }
|
||||
|
@ -33,36 +52,30 @@ describe Ci::API::API do
|
|||
context 'when builds are finished' do
|
||||
before do
|
||||
build.success
|
||||
end
|
||||
|
||||
it "returns 404 error if no builds for specific runner" do
|
||||
register_builds
|
||||
|
||||
expect(response).to have_http_status(404)
|
||||
end
|
||||
|
||||
it_behaves_like 'no builds available'
|
||||
end
|
||||
|
||||
context 'for other project with builds' do
|
||||
before do
|
||||
build.success
|
||||
create(:ci_build, :pending)
|
||||
end
|
||||
|
||||
it "returns 404 error if no builds for shared runner" do
|
||||
register_builds
|
||||
|
||||
expect(response).to have_http_status(404)
|
||||
end
|
||||
|
||||
it_behaves_like 'no builds available'
|
||||
end
|
||||
|
||||
context 'for shared runner' do
|
||||
let(:shared_runner) { create(:ci_runner, token: "SharedRunner") }
|
||||
|
||||
it "should return 404 error if no builds for shared runner" do
|
||||
before do
|
||||
register_builds shared_runner.token
|
||||
|
||||
expect(response).to have_http_status(404)
|
||||
end
|
||||
|
||||
it_behaves_like 'no builds available'
|
||||
end
|
||||
|
||||
context 'for triggered build' do
|
||||
|
@ -136,18 +149,17 @@ describe Ci::API::API do
|
|||
end
|
||||
|
||||
context 'when runner is not allowed to pick untagged builds' do
|
||||
before { runner.update_column(:run_untagged, false) }
|
||||
|
||||
it 'does not pick build' do
|
||||
before do
|
||||
runner.update_column(:run_untagged, false)
|
||||
register_builds
|
||||
|
||||
expect(response).to have_http_status 404
|
||||
end
|
||||
|
||||
it_behaves_like 'no builds available'
|
||||
end
|
||||
end
|
||||
|
||||
def register_builds(token = runner.token, **params)
|
||||
post ci_api("/builds/register"), params.merge(token: token)
|
||||
post ci_api("/builds/register"), params.merge(token: token), {'User-Agent' => user_agent}
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue