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

resolver_spec.rb « tags « yaml « config « ci « gitlab « lib « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 594242c33cc1172d7c83dd3b890e9f273ea7156e (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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Gitlab::Ci::Config::Yaml::Tags::Resolver do
  let(:config) do
    Gitlab::Ci::Config::Yaml.load!(yaml)
  end

  describe '#to_hash' do
    subject { described_class.new(config).to_hash }

    context 'when referencing deeply nested arrays' do
      let(:yaml_templates) do
        <<~YML
        .job-1:
          script:
            - echo doing step 1 of job 1
            - echo doing step 2 of job 1

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

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

      let(:job_yaml) do
        <<~YML
        test:
          script:
            - echo preparing to test
            - !reference [.job-3, script]
            - echo test finished
        YML
      end

      shared_examples 'expands references' do
        it 'expands the references' do
          is_expected.to match({
            '.job-1': {
              script: [
                'echo doing step 1 of job 1',
                'echo doing step 2 of job 1'
              ]
            },
            '.job-2': {
              script: [
                'echo doing step 1 of job 2',
                [
                  'echo doing step 1 of job 1',
                  'echo doing step 2 of job 1'
                ],
                'echo doing step 2 of job 2'
              ]
            },
            '.job-3': {
              script: [
                'echo doing step 1 of job 3',
                [
                  'echo doing step 1 of job 2',
                  [
                    'echo doing step 1 of job 1',
                    'echo doing step 2 of job 1'
                  ],
                  'echo doing step 2 of job 2'
                ],
                'echo doing step 2 of job 3'
              ]
            },
            test: {
              script: [
                'echo preparing to test',
                [
                  'echo doing step 1 of job 3',
                  [
                    'echo doing step 1 of job 2',
                    [
                      'echo doing step 1 of job 1',
                      'echo doing step 2 of job 1'
                    ],
                    'echo doing step 2 of job 2'
                  ],
                  'echo doing step 2 of job 3'
                ],
                'echo test finished'
              ]
            }
          })
        end
      end

      context 'when templates are defined before the job' do
        let(:yaml) do
          <<~YML
          #{yaml_templates}
          #{job_yaml}
          YML
        end

        it_behaves_like 'expands references'
      end

      context 'when templates are defined after the job' do
        let(:yaml) do
          <<~YML
          #{job_yaml}
          #{yaml_templates}
          YML
        end

        it_behaves_like 'expands references'
      end
    end
  end
end