2016-08-18 06:50:01 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2017-04-21 20:32:02 +00:00
|
|
|
describe API::Lint do
|
2016-08-29 13:07:19 +00:00
|
|
|
describe 'POST /ci/lint' do
|
2016-08-24 08:16:58 +00:00
|
|
|
context 'with valid .gitlab-ci.yaml content' do
|
2016-08-30 13:38:36 +00:00
|
|
|
let(:yaml_content) do
|
|
|
|
File.read(Rails.root.join('spec/support/gitlab_stubs/gitlab_ci.yml'))
|
|
|
|
end
|
|
|
|
|
2016-08-29 13:07:19 +00:00
|
|
|
it 'passes validation' do
|
|
|
|
post api('/ci/lint'), { content: yaml_content }
|
2016-08-24 12:36:14 +00:00
|
|
|
|
|
|
|
expect(response).to have_http_status(200)
|
|
|
|
expect(json_response).to be_an Hash
|
|
|
|
expect(json_response['status']).to eq('valid')
|
2016-08-30 11:03:29 +00:00
|
|
|
expect(json_response['errors']).to eq([])
|
2016-08-18 06:50:01 +00:00
|
|
|
end
|
|
|
|
end
|
2016-08-23 10:12:21 +00:00
|
|
|
|
2016-08-26 10:49:59 +00:00
|
|
|
context 'with an invalid .gitlab_ci.yml' do
|
2016-08-29 13:07:19 +00:00
|
|
|
it 'responds with errors about invalid syntax' do
|
|
|
|
post api('/ci/lint'), { content: 'invalid content' }
|
2016-08-23 10:12:21 +00:00
|
|
|
|
2016-08-24 08:16:58 +00:00
|
|
|
expect(response).to have_http_status(200)
|
|
|
|
expect(json_response['status']).to eq('invalid')
|
2016-08-30 11:03:29 +00:00
|
|
|
expect(json_response['errors']).to eq(['Invalid configuration format'])
|
2016-08-24 12:36:14 +00:00
|
|
|
end
|
|
|
|
|
2016-08-29 13:07:19 +00:00
|
|
|
it "responds with errors about invalid configuration" do
|
|
|
|
post api('/ci/lint'), { content: '{ image: "ruby:2.1", services: ["postgres"] }' }
|
2016-08-24 12:36:14 +00:00
|
|
|
|
|
|
|
expect(response).to have_http_status(200)
|
|
|
|
expect(json_response['status']).to eq('invalid')
|
2016-08-30 11:03:29 +00:00
|
|
|
expect(json_response['errors']).to eq(['jobs config should contain at least one visible job'])
|
2016-08-23 10:12:21 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-08-26 10:49:59 +00:00
|
|
|
context 'without the content parameter' do
|
2016-08-29 13:07:19 +00:00
|
|
|
it 'responds with validation error about missing content' do
|
|
|
|
post api('/ci/lint')
|
2016-08-23 10:12:21 +00:00
|
|
|
|
|
|
|
expect(response).to have_http_status(400)
|
2016-08-26 10:49:59 +00:00
|
|
|
expect(json_response['error']).to eq('content is missing')
|
2016-08-23 10:12:21 +00:00
|
|
|
end
|
|
|
|
end
|
2016-08-18 06:50:01 +00:00
|
|
|
end
|
|
|
|
end
|