BigW Consortium Gitlab

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

Katarzyna Kobierska committed
3
describe API::Lint, api: true do
Katarzyna Kobierska committed
4 5
  include ApiHelpers

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

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

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

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

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

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

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

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

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