Skip to content
Snippets Groups Projects
Commit de2e8d4a authored by Katarzyna Kobierska's avatar Katarzyna Kobierska
Browse files

Add tests for yaml content with errors

parent ca1f5ede
No related branches found
No related tags found
No related merge requests found
Loading
@@ -3,30 +3,36 @@ require 'spec_helper'
Loading
@@ -3,30 +3,36 @@ require 'spec_helper'
describe API::API do describe API::API do
include ApiHelpers include ApiHelpers
   
let(:user) { create(:user) }
let(:yaml_content) do let(:yaml_content) do
File.read(Rails.root.join('spec/support/gitlab_stubs/gitlab_ci.yml')) File.read(Rails.root.join('spec/support/gitlab_stubs/gitlab_ci.yml'))
end end
   
describe 'POST /lint' do describe 'POST /lint' do
context 'with valid .gitlab-ci.yaml content' do context 'with valid .gitlab-ci.yaml content' do
context 'authorized user' do it 'validates content' do
it 'validate content' do post api('/lint'), { content: yaml_content }
post api('/lint'), { content: yaml_content }
expect(response).to have_http_status(200)
expect(response).to have_http_status(200) expect(json_response).to be_an Hash
expect(json_response).to be_an Hash expect(json_response['status']).to eq('valid')
expect(json_response['status']).to eq('valid')
end
end end
end end
   
context 'with invalid .gitlab_ci.yml content' do context 'with invalid .gitlab_ci.yml' do
it 'validate content' do it 'validates content and shows correct errors' do
post api('/lint'), { content: 'invalid content' } post api('/lint'), { content: 'invalid content' }
   
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(json_response['status']).to eq('invalid') expect(json_response['status']).to eq('invalid')
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'])
end end
end end
   
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment