BigW Consortium Gitlab

lint_spec.rb 1.55 KB
Newer Older
Katarzyna Kobierska committed
1 2
require 'spec_helper'

3
describe API::Lint do
Katarzyna Kobierska committed
4
  describe 'POST /ci/lint' do
5
    context 'with valid .gitlab-ci.yaml content' do
Katarzyna Kobierska committed
6 7 8 9
      let(:yaml_content) do
        File.read(Rails.root.join('spec/support/gitlab_stubs/gitlab_ci.yml'))
      end

Katarzyna Kobierska committed
10 11
      it 'passes validation' do
        post api('/ci/lint'), { content: yaml_content }
12 13 14 15

        expect(response).to have_http_status(200)
        expect(json_response).to be_an Hash
        expect(json_response['status']).to eq('valid')
Katarzyna Kobierska committed
16
        expect(json_response['errors']).to eq([])
Katarzyna Kobierska committed
17 18
      end
    end
19

20
    context 'with an invalid .gitlab_ci.yml' do
Katarzyna Kobierska committed
21 22
      it 'responds with errors about invalid syntax' do
        post api('/ci/lint'), { content: 'invalid content' }
23

24 25
        expect(response).to have_http_status(200)
        expect(json_response['status']).to eq('invalid')
Katarzyna Kobierska committed
26
        expect(json_response['errors']).to eq(['Invalid configuration format'])
27 28
      end

Katarzyna Kobierska committed
29 30
      it "responds with errors about invalid configuration" do
        post api('/ci/lint'), { content: '{ image: "ruby:2.1",  services: ["postgres"] }' }
31 32 33

        expect(response).to have_http_status(200)
        expect(json_response['status']).to eq('invalid')
Katarzyna Kobierska committed
34
        expect(json_response['errors']).to eq(['jobs config should contain at least one visible job'])
35 36 37
      end
    end

38
    context 'without the content parameter' do
Katarzyna Kobierska committed
39 40
      it 'responds with validation error about missing content' do
        post api('/ci/lint')
41 42

        expect(response).to have_http_status(400)
43
        expect(json_response['error']).to eq('content is missing')
44 45
      end
    end
Katarzyna Kobierska committed
46 47
  end
end