summaryrefslogtreecommitdiff
path: root/spec/models/ci/pipeline_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/models/ci/pipeline_spec.rb')
-rw-r--r--spec/models/ci/pipeline_spec.rb342
1 files changed, 7 insertions, 335 deletions
diff --git a/spec/models/ci/pipeline_spec.rb b/spec/models/ci/pipeline_spec.rb
index 1242cf05a59..d24cf3d2115 100644
--- a/spec/models/ci/pipeline_spec.rb
+++ b/spec/models/ci/pipeline_spec.rb
@@ -979,149 +979,6 @@ describe Ci::Pipeline, :mailer do
end
describe 'pipeline stages' do
- describe '#stage_seeds' do
- before do
- stub_ci_pipeline_yaml_file(YAML.dump(config))
- end
-
- let(:pipeline) { build(:ci_pipeline) }
- let(:config) { { rspec: { script: 'rake' } } }
-
- it 'returns preseeded stage seeds object' do
- expect(pipeline.stage_seeds)
- .to all(be_a Gitlab::Ci::Pipeline::Seed::Base)
- expect(pipeline.stage_seeds.count).to eq 1
- end
-
- context 'when no refs policy is specified' do
- let(:config) do
- { production: { stage: 'deploy', script: 'cap prod' },
- rspec: { stage: 'test', script: 'rspec' },
- spinach: { stage: 'test', script: 'spinach' } }
- end
-
- it 'correctly fabricates a stage seeds object' do
- seeds = pipeline.stage_seeds
-
- expect(seeds.size).to eq 2
- expect(seeds.first.attributes[:name]).to eq 'test'
- expect(seeds.second.attributes[:name]).to eq 'deploy'
- expect(seeds.dig(0, 0, :name)).to eq 'rspec'
- expect(seeds.dig(0, 1, :name)).to eq 'spinach'
- expect(seeds.dig(1, 0, :name)).to eq 'production'
- end
- end
-
- context 'when refs policy is specified' do
- let(:pipeline) do
- build(:ci_pipeline, ref: 'feature', tag: true)
- end
-
- let(:config) do
- { production: { stage: 'deploy', script: 'cap prod', only: ['master'] },
- spinach: { stage: 'test', script: 'spinach', only: ['tags'] } }
- end
-
- it 'returns stage seeds only assigned to master to master' do
- seeds = pipeline.stage_seeds
-
- expect(seeds.size).to eq 1
- expect(seeds.first.attributes[:name]).to eq 'test'
- expect(seeds.dig(0, 0, :name)).to eq 'spinach'
- end
- end
-
- context 'when source policy is specified' do
- let(:pipeline) { build(:ci_pipeline, source: :schedule) }
-
- let(:config) do
- { production: { stage: 'deploy', script: 'cap prod', only: ['triggers'] },
- spinach: { stage: 'test', script: 'spinach', only: ['schedules'] } }
- end
-
- it 'returns stage seeds only assigned to schedules' do
- seeds = pipeline.stage_seeds
-
- expect(seeds.size).to eq 1
- expect(seeds.first.attributes[:name]).to eq 'test'
- expect(seeds.dig(0, 0, :name)).to eq 'spinach'
- end
- end
-
- context 'when kubernetes policy is specified' do
- let(:config) do
- {
- spinach: { stage: 'test', script: 'spinach' },
- production: {
- stage: 'deploy',
- script: 'cap',
- only: { kubernetes: 'active' }
- }
- }
- end
-
- context 'when kubernetes is active' do
- context 'when user configured kubernetes from CI/CD > Clusters' do
- let!(:cluster) { create(:cluster, :project, :provided_by_gcp) }
- let(:project) { cluster.project }
- let(:pipeline) { build(:ci_pipeline, project: project) }
-
- it 'returns seeds for kubernetes dependent job' do
- seeds = pipeline.stage_seeds
-
- expect(seeds.size).to eq 2
- expect(seeds.dig(0, 0, :name)).to eq 'spinach'
- expect(seeds.dig(1, 0, :name)).to eq 'production'
- end
- end
- end
-
- context 'when kubernetes is not active' do
- it 'does not return seeds for kubernetes dependent job' do
- seeds = pipeline.stage_seeds
-
- expect(seeds.size).to eq 1
- expect(seeds.dig(0, 0, :name)).to eq 'spinach'
- end
- end
- end
-
- context 'when variables policy is specified' do
- let(:config) do
- { unit: { script: 'minitest', only: { variables: ['$CI_PIPELINE_SOURCE'] } },
- feature: { script: 'spinach', only: { variables: ['$UNDEFINED'] } } }
- end
-
- it 'returns stage seeds only when variables expression is truthy' do
- seeds = pipeline.stage_seeds
-
- expect(seeds.size).to eq 1
- expect(seeds.dig(0, 0, :name)).to eq 'unit'
- end
- end
- end
-
- describe '#seeds_size' do
- before do
- stub_ci_pipeline_yaml_file(YAML.dump(config))
- end
-
- context 'when refs policy is specified' do
- let(:config) do
- { production: { stage: 'deploy', script: 'cap prod', only: ['master'] },
- spinach: { stage: 'test', script: 'spinach', only: ['tags'] } }
- end
-
- let(:pipeline) do
- build(:ci_pipeline, ref: 'feature', tag: true)
- end
-
- it 'returns real seeds size' do
- expect(pipeline.seeds_size).to eq 1
- end
- end
- end
-
describe 'legacy stages' do
before do
create(:commit_status, pipeline: pipeline,
@@ -2194,161 +2051,6 @@ describe Ci::Pipeline, :mailer do
end
end
- describe '#ci_yaml_file_path' do
- subject { pipeline.ci_yaml_file_path }
-
- %i[unknown_source repository_source].each do |source|
- context source.to_s do
- before do
- pipeline.config_source = described_class.config_sources.fetch(source)
- end
-
- it 'returns the path from project' do
- allow(pipeline.project).to receive(:ci_config_path) { 'custom/path' }
-
- is_expected.to eq('custom/path')
- end
-
- it 'returns default when custom path is nil' do
- allow(pipeline.project).to receive(:ci_config_path) { nil }
-
- is_expected.to eq('.gitlab-ci.yml')
- end
-
- it 'returns default when custom path is empty' do
- allow(pipeline.project).to receive(:ci_config_path) { '' }
-
- is_expected.to eq('.gitlab-ci.yml')
- end
- end
- end
-
- context 'when pipeline is for auto-devops' do
- before do
- pipeline.config_source = 'auto_devops_source'
- end
-
- it 'does not return config file' do
- is_expected.to be_nil
- end
- end
- end
-
- describe '#set_config_source' do
- context 'when pipelines does not contain needed data and auto devops is disabled' do
- before do
- stub_application_setting(auto_devops_enabled: false)
- end
-
- it 'defines source to be unknown' do
- pipeline.set_config_source
-
- expect(pipeline).to be_unknown_source
- end
- end
-
- context 'when pipeline contains all needed data' do
- let(:pipeline) do
- create(:ci_pipeline, project: project,
- sha: '1234',
- ref: 'master',
- source: :push)
- end
-
- context 'when the repository has a config file' do
- before do
- allow(project.repository).to receive(:gitlab_ci_yml_for)
- .and_return('config')
- end
-
- it 'defines source to be from repository' do
- pipeline.set_config_source
-
- expect(pipeline).to be_repository_source
- end
-
- context 'when loading an object' do
- let(:new_pipeline) { Ci::Pipeline.find(pipeline.id) }
-
- it 'does not redefine the source' do
- # force to overwrite the source
- pipeline.unknown_source!
-
- expect(new_pipeline).to be_unknown_source
- end
- end
- end
-
- context 'when the repository does not have a config file' do
- let(:implied_yml) { Gitlab::Template::GitlabCiYmlTemplate.find('Auto-DevOps').content }
-
- context 'auto devops enabled' do
- before do
- allow(project).to receive(:ci_config_path) { 'custom' }
- end
-
- it 'defines source to be auto devops' do
- pipeline.set_config_source
-
- expect(pipeline).to be_auto_devops_source
- end
- end
- end
- end
- end
-
- describe '#ci_yaml_file' do
- let(:implied_yml) { Gitlab::Template::GitlabCiYmlTemplate.find('Auto-DevOps').content }
-
- context 'the source is unknown' do
- before do
- pipeline.unknown_source!
- end
-
- it 'returns the configuration if found' do
- allow(pipeline.project.repository).to receive(:gitlab_ci_yml_for)
- .and_return('config')
-
- expect(pipeline.ci_yaml_file).to be_a(String)
- expect(pipeline.ci_yaml_file).not_to eq(implied_yml)
- expect(pipeline.yaml_errors).to be_nil
- end
-
- it 'sets yaml errors if not found' do
- expect(pipeline.ci_yaml_file).to be_nil
- expect(pipeline.yaml_errors)
- .to start_with('Failed to load CI/CD config file')
- end
- end
-
- context 'the source is the repository' do
- before do
- pipeline.repository_source!
- end
-
- it 'returns the configuration if found' do
- allow(pipeline.project.repository).to receive(:gitlab_ci_yml_for)
- .and_return('config')
-
- expect(pipeline.ci_yaml_file).to be_a(String)
- expect(pipeline.ci_yaml_file).not_to eq(implied_yml)
- expect(pipeline.yaml_errors).to be_nil
- end
- end
-
- context 'when the source is auto_devops_source' do
- before do
- stub_application_setting(auto_devops_enabled: true)
- pipeline.auto_devops_source!
- end
-
- it 'finds the implied config' do
- expect(pipeline.ci_yaml_file).to eq(implied_yml)
- expect(pipeline.yaml_errors).to be_nil
- end
- end
- end
-
describe '#update_status' do
context 'when pipeline is empty' do
it 'updates does not change pipeline status' do
@@ -2894,49 +2596,19 @@ describe Ci::Pipeline, :mailer do
end
describe '#has_yaml_errors?' do
- before do
- stub_ci_pipeline_yaml_file(YAML.dump(config))
- end
-
- let(:pipeline) { create(:ci_pipeline) }
-
- context 'when pipeline has errors' do
- let(:config) { { rspec: nil } }
-
- it 'contains yaml errors' do
- pipeline.config_processor
-
- expect(pipeline).to have_yaml_errors
- expect(pipeline.yaml_errors).to include('contains unknown keys')
+ context 'when yaml_errors is set' do
+ before do
+ pipeline.yaml_errors = 'File not found'
end
- end
-
- context 'when pipeline has undefined error' do
- let(:config) { double(:config) }
-
- it 'contains yaml errors' do
- expect(::Gitlab::Ci::YamlProcessor).to receive(:new)
- .and_raise(RuntimeError, 'undefined failure')
-
- expect(Gitlab::Sentry).to receive(:track_acceptable_exception)
- .with(be_a(RuntimeError), anything)
- .and_call_original
-
- pipeline.config_processor
+ it 'returns true if yaml_errors is set' do
expect(pipeline).to have_yaml_errors
- expect(pipeline.yaml_errors).to include('Undefined error')
+ expect(pipeline.yaml_errors).to include('File not foun')
end
end
- context 'when pipeline does not have errors' do
- let(:config) do
- { rspec: { script: 'rake test' } }
- end
-
- it 'does not contain yaml errors' do
- expect(pipeline).not_to have_yaml_errors
- end
+ it 'returns false if yaml_errors is not set' do
+ expect(pipeline).not_to have_yaml_errors
end
end