gitlab-org--gitlab-foss/spec/requests/api/lint_spec.rb

48 lines
1.6 KiB
Ruby
Raw Normal View History

2016-08-18 02:50:01 -04:00
require 'spec_helper'
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
post api('/ci/lint'), { content: yaml_content }
2016-08-24 08:36:14 -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
post api('/ci/lint'), { content: 'invalid content' }
2016-08-23 06:12:21 -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
post api('/ci/lint'), { content: '{ image: "ruby:2.1", services: ["postgres"] }' }
2016-08-24 08:36:14 -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
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