2016-09-29 09:46:39 +05:30
|
|
|
require 'spec_helper'
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
describe API::Lint do
|
2016-09-29 09:46:39 +05:30
|
|
|
describe 'POST /ci/lint' do
|
|
|
|
context 'with valid .gitlab-ci.yaml content' do
|
|
|
|
let(:yaml_content) do
|
|
|
|
File.read(Rails.root.join('spec/support/gitlab_stubs/gitlab_ci.yml'))
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'passes validation' do
|
2019-02-13 22:33:31 +05:30
|
|
|
post api('/ci/lint'), params: { content: yaml_content }
|
2016-09-29 09:46:39 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
expect(response).to have_gitlab_http_status(200)
|
2016-09-29 09:46:39 +05:30
|
|
|
expect(json_response).to be_an Hash
|
|
|
|
expect(json_response['status']).to eq('valid')
|
|
|
|
expect(json_response['errors']).to eq([])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with an invalid .gitlab_ci.yml' do
|
|
|
|
it 'responds with errors about invalid syntax' do
|
2019-02-13 22:33:31 +05:30
|
|
|
post api('/ci/lint'), params: { content: 'invalid content' }
|
2016-09-29 09:46:39 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
expect(response).to have_gitlab_http_status(200)
|
2016-09-29 09:46:39 +05:30
|
|
|
expect(json_response['status']).to eq('invalid')
|
|
|
|
expect(json_response['errors']).to eq(['Invalid configuration format'])
|
|
|
|
end
|
|
|
|
|
|
|
|
it "responds with errors about invalid configuration" do
|
2019-02-13 22:33:31 +05:30
|
|
|
post api('/ci/lint'), params: { content: '{ image: "ruby:2.1", services: ["postgres"] }' }
|
2016-09-29 09:46:39 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
expect(response).to have_gitlab_http_status(200)
|
2016-09-29 09:46:39 +05:30
|
|
|
expect(json_response['status']).to eq('invalid')
|
|
|
|
expect(json_response['errors']).to eq(['jobs config should contain at least one visible job'])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'without the content parameter' do
|
|
|
|
it 'responds with validation error about missing content' do
|
|
|
|
post api('/ci/lint')
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
expect(response).to have_gitlab_http_status(400)
|
2016-09-29 09:46:39 +05:30
|
|
|
expect(json_response['error']).to eq('content is missing')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|