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