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

48 lines
1.4 KiB
Ruby
Raw Normal View History

2016-08-18 06:50:01 +00:00
require 'spec_helper'
2016-08-24 09:42:48 +00:00
describe API::API do
2016-08-18 06:50:01 +00:00
include ApiHelpers
2016-08-23 10:12:21 +00:00
let(:yaml_content) do
2016-08-18 06:50:01 +00:00
File.read(Rails.root.join('spec/support/gitlab_stubs/gitlab_ci.yml'))
end
2016-08-24 09:42:48 +00:00
describe 'POST /lint' do
2016-08-24 08:16:58 +00:00
context 'with valid .gitlab-ci.yaml content' do
2016-08-24 12:36:14 +00:00
it 'validates content' do
post api('/lint'), { content: yaml_content }
expect(response).to have_http_status(200)
expect(json_response).to be_an Hash
expect(json_response['status']).to eq('valid')
2016-08-18 06:50:01 +00:00
end
end
2016-08-23 10:12:21 +00:00
2016-08-24 12:36:14 +00:00
context 'with invalid .gitlab_ci.yml' do
it 'validates content and shows correct errors' do
2016-08-24 09:42:48 +00:00
post api('/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-24 12:36:14 +00:00
expect(json_response['errors']).to eq(['Invalid configuration format'])
end
it "validates content and shows configuration error" do
post api('/lint'), { content: '{ image: "ruby:2.1", services: ["postgres"] }' }
expect(response).to have_http_status(200)
expect(json_response['status']).to eq('invalid')
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-24 08:16:58 +00:00
context 'no content parameters' do
it 'shows error message' do
2016-08-24 09:42:48 +00:00
post api('/lint')
2016-08-23 10:12:21 +00:00
expect(response).to have_http_status(400)
end
end
2016-08-18 06:50:01 +00:00
end
end