Welcome to mirror list, hosted at ThFree Co, Russian Federation.

custom_yaml_tags_spec.rb « create_pipeline_service « ci « services « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 716a929830e2643411fb3d62e3d6d533364fd06b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# frozen_string_literal: true
require 'spec_helper'

RSpec.describe Ci::CreatePipelineService do
  describe '!reference tags' do
    let_it_be(:project) { create(:project, :repository) }
    let_it_be(:user)    { project.first_owner }

    let(:ref) { 'refs/heads/master' }
    let(:source) { :push }
    let(:service) { described_class.new(project, user, { ref: ref }) }
    let(:pipeline) { service.execute(source).payload }

    before do
      stub_ci_pipeline_yaml_file(config)
    end

    context 'with valid config' do
      let(:config) do
        <<~YAML
        .job-1:
          script:
            - echo doing step 1 of job 1

        .job-2:
          before_script:
            - ls
          script: !reference [.job-1, script]

        job:
          before_script: !reference [.job-2, before_script]
          script:
            - echo doing my first step
            - !reference [.job-2, script]
            - echo doing my last step
        YAML
      end

      it 'creates a pipeline' do
        expect(pipeline).to be_persisted
        expect(pipeline.builds.first.options).to match(a_hash_including({
          before_script: ['ls'],
          script: [
            'echo doing my first step',
            'echo doing step 1 of job 1',
            'echo doing my last step'
          ]
        }))
      end
    end

    context 'with invalid config' do
      let(:config) do
        <<~YAML
        job-1:
          script:
            - echo doing step 1 of job 1
            - !reference [job-3, script]

        job-2:
          script:
            - echo doing step 1 of job 2
            - !reference [job-3, script]

        job-3:
          script:
            - echo doing step 1 of job 3
            - !reference [job-1, script]
        YAML
      end

      it 'creates a pipeline without builds' do
        expect(pipeline).to be_persisted
        expect(pipeline.builds).to be_empty
        expect(pipeline.yaml_errors).to eq("!reference [\"job-3\", \"script\"] is part of a circular chain")
      end
    end
  end
end