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

project_config_spec.rb « ci « gitlab « lib « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: c4b179c9ef538b038976eb74a4756577e610423e (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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Gitlab::Ci::ProjectConfig do
  let(:project) { create(:project, :empty_repo, ci_config_path: ci_config_path) }
  let(:sha) { '123456' }
  let(:content) { nil }
  let(:source) { :push }
  let(:bridge) { nil }

  subject(:config) do
    described_class.new(project: project, sha: sha,
                        custom_content: content, pipeline_source: source, pipeline_source_bridge: bridge)
  end

  context 'when bridge job is passed in as parameter' do
    let(:ci_config_path) { nil }
    let(:bridge) { create(:ci_bridge) }

    before do
      allow(bridge).to receive(:yaml_for_downstream).and_return('the-yaml')
    end

    it 'returns the content already available in command' do
      expect(config.source).to eq(:bridge_source)
      expect(config.content).to eq('the-yaml')
    end
  end

  context 'when config is defined in a custom path in the repository' do
    let(:ci_config_path) { 'path/to/config.yml' }
    let(:config_content_result) do
      <<~CICONFIG
        ---
        include:
        - local: #{ci_config_path}
      CICONFIG
    end

    before do
      allow(project.repository)
        .to receive(:gitlab_ci_yml_for)
        .with(sha, ci_config_path)
        .and_return('the-content')
    end

    it 'returns root config including the local custom file' do
      expect(config.source).to eq(:repository_source)
      expect(config.content).to eq(config_content_result)
    end
  end

  context 'when config is defined remotely' do
    let(:ci_config_path) { 'http://example.com/path/to/ci/config.yml' }
    let(:config_content_result) do
      <<~CICONFIG
        ---
        include:
        - remote: #{ci_config_path}
      CICONFIG
    end

    it 'returns root config including the remote config' do
      expect(config.source).to eq(:remote_source)
      expect(config.content).to eq(config_content_result)
    end
  end

  context 'when config is defined in a separate repository' do
    let(:ci_config_path) { 'path/to/.gitlab-ci.yml@another-group/another-repo' }
    let(:config_content_result) do
      <<~CICONFIG
        ---
        include:
        - project: another-group/another-repo
          file: path/to/.gitlab-ci.yml
      CICONFIG
    end

    it 'returns root config including the path to another repository' do
      expect(config.source).to eq(:external_project_source)
      expect(config.content).to eq(config_content_result)
    end

    context 'when path specifies a refname' do
      let(:ci_config_path) { 'path/to/.gitlab-ci.yml@another-group/another-repo:refname' }
      let(:config_content_result) do
        <<~CICONFIG
          ---
          include:
          - project: another-group/another-repo
            file: path/to/.gitlab-ci.yml
            ref: refname
        CICONFIG
      end

      it 'returns root config including the path and refname to another repository' do
        expect(config.source).to eq(:external_project_source)
        expect(config.content).to eq(config_content_result)
      end
    end
  end

  context 'when config is defined in the default .gitlab-ci.yml' do
    let(:ci_config_path) { nil }
    let(:config_content_result) do
      <<~CICONFIG
        ---
        include:
        - local: ".gitlab-ci.yml"
      CICONFIG
    end

    before do
      allow(project.repository)
        .to receive(:gitlab_ci_yml_for)
        .with(sha, '.gitlab-ci.yml')
        .and_return('the-content')
    end

    it 'returns root config including the canonical CI config file' do
      expect(config.source).to eq(:repository_source)
      expect(config.content).to eq(config_content_result)
    end
  end

  context 'when config is the Auto-Devops template' do
    let(:ci_config_path) { nil }
    let(:config_content_result) do
      <<~CICONFIG
        ---
        include:
        - template: Auto-DevOps.gitlab-ci.yml
      CICONFIG
    end

    before do
      allow(project).to receive(:auto_devops_enabled?).and_return(true)
    end

    it 'returns root config including the auto-devops template' do
      expect(config.source).to eq(:auto_devops_source)
      expect(config.content).to eq(config_content_result)
    end
  end

  context 'when config is passed as a parameter' do
    let(:source) { :ondemand_dast_scan }
    let(:ci_config_path) { nil }
    let(:content) do
      <<~CICONFIG
        ---
        stages:
        - dast
      CICONFIG
    end

    it 'returns the parameter content' do
      expect(config.source).to eq(:parameter_source)
      expect(config.content).to eq(content)
    end
  end

  context 'when config is not defined anywhere' do
    let(:ci_config_path) { nil }

    before do
      allow(project).to receive(:auto_devops_enabled?).and_return(false)
    end

    it 'returns nil' do
      expect(config.source).to be_nil
      expect(config.content).to be_nil
    end
  end
end