Commit 2892cca8 authored by Fabio Pitino's avatar Fabio Pitino Committed by Kamil Trzciński
Browse files

Remove unnecessary ci_pipeline factories

* Remove config transient
* Remove factory for 1 job pipeline
* Remove factory for 0 job pipeline
parent ce42916a
......@@ -20,7 +20,7 @@ describe Projects::Security::DashboardController do
end
 
describe 'GET #show' do
let(:pipeline) { create(:ci_pipeline_without_jobs, sha: project.commit.id, project: project, user: user) }
let(:pipeline) { create(:ci_pipeline, sha: project.commit.id, project: project, user: user) }
 
render_views
 
......
......@@ -10,7 +10,7 @@ describe 'Merge request > User sees deployment widget', :js do
let(:role) { :developer }
let(:ref) { merge_request.target_branch }
let(:sha) { project.commit(ref).id }
let(:pipeline) { create(:ci_pipeline_without_jobs, sha: sha, project: project, ref: ref) }
let(:pipeline) { create(:ci_pipeline, sha: sha, project: project, ref: ref) }
let!(:manual) { }
 
before do
......
......@@ -14,22 +14,22 @@ describe EE::Gitlab::Ci::Pipeline::Quota::Size do
subject { described_class.new(namespace, pipeline) }
 
shared_context 'pipeline size limit exceeded' do
let(:pipeline) do
config = { rspec: { script: 'rspec' },
spinach: { script: 'spinach' } }
build(:ci_pipeline, project: project, config: config)
end
before do
config = YAML.dump({
rspec: { script: 'rspec' },
spinach: { script: 'spinach' }
})
stub_ci_pipeline_yaml_file(config)
plan_limits.update!(ci_pipeline_size: 1)
end
end
 
shared_context 'pipeline size limit not exceeded' do
let(:pipeline) { build(:ci_pipeline_with_one_job, project: project) }
before do
config = YAML.dump({
rspec: { script: 'rspec' }
})
stub_ci_pipeline_yaml_file(config)
plan_limits.update!(ci_pipeline_size: 2)
end
end
......
......@@ -7,10 +7,7 @@ describe ::Gitlab::Ci::Pipeline::Chain::Limit::Size do
set(:project) { create(:project, :repository, namespace: namespace) }
set(:user) { create(:user) }
 
let(:pipeline) do
build(:ci_pipeline_with_one_job, project: project,
ref: 'master')
end
let(:pipeline) { build(:ci_pipeline, project: project) }
 
let(:command) do
double('command', project: project,
......@@ -26,13 +23,10 @@ describe ::Gitlab::Ci::Pipeline::Chain::Limit::Size do
gold_plan = create(:gold_plan)
create(:plan_limits, plan: gold_plan, ci_pipeline_size: 1)
create(:gitlab_subscription, namespace: namespace, hosted_plan: gold_plan)
end
let(:pipeline) do
config = { rspec: { script: 'rspec' },
spinach: { script: 'spinach' } }
create(:ci_pipeline, project: project, config: config)
stub_ci_pipeline_yaml_file(YAML.dump({
rspec: { script: 'rspec' },
spinach: { script: 'spinach' }
}))
end
 
context 'when saving incomplete pipelines' do
......
# frozen_string_literal: true
require 'spec_helper'
describe ::Gitlab::Ci::Pipeline::Chain::RemoveUnwantedChatJobs do
let(:project) { create(:project, :repository) }
let(:pipeline) do
build(:ci_pipeline_with_one_job, project: project, ref: 'master')
end
let(:command) do
double(:command, project: project, chat_data: { command: 'echo' })
end
describe '#perform!' do
it 'removes unwanted jobs for chat pipelines' do
allow(pipeline).to receive(:chat?).and_return(true)
pipeline.config_processor.jobs[:echo] = double(:job)
described_class.new(pipeline, command).perform!
expect(pipeline.config_processor.jobs.keys).to eq([:echo])
end
end
it 'does not remove any jobs for non-chat pipelines' do
described_class.new(pipeline, command).perform!
expect(pipeline.config_processor.jobs.keys).to eq([:rspec])
end
end
......@@ -23,9 +23,9 @@ describe Ci::Pipeline do
end
 
describe '#with_vulnerabilities scope' do
let!(:pipeline_1) { create(:ci_pipeline_without_jobs, project: project) }
let!(:pipeline_2) { create(:ci_pipeline_without_jobs, project: project) }
let!(:pipeline_3) { create(:ci_pipeline_without_jobs, project: project) }
let!(:pipeline_1) { create(:ci_pipeline, project: project) }
let!(:pipeline_2) { create(:ci_pipeline, project: project) }
let!(:pipeline_3) { create(:ci_pipeline, project: project) }
 
before do
create(:vulnerabilities_occurrence, pipelines: [pipeline_1], project: pipeline.project)
......
......@@ -597,7 +597,7 @@ describe MergeRequest do
 
describe '#mergeable_with_quick_action?' do
def create_pipeline(status)
pipeline = create(:ci_pipeline_with_one_job,
pipeline = create(:ci_pipeline,
project: project,
ref: merge_request.source_branch,
sha: merge_request.diff_head_sha,
......
......@@ -1378,9 +1378,9 @@ describe Project do
 
describe '#latest_pipeline_with_security_reports' do
let(:project) { create(:project) }
let!(:pipeline_1) { create(:ci_pipeline_without_jobs, project: project) }
let!(:pipeline_2) { create(:ci_pipeline_without_jobs, project: project) }
let!(:pipeline_3) { create(:ci_pipeline_without_jobs, project: project) }
let!(:pipeline_1) { create(:ci_pipeline, project: project) }
let!(:pipeline_2) { create(:ci_pipeline, project: project) }
let!(:pipeline_3) { create(:ci_pipeline, project: project) }
 
subject { project.latest_pipeline_with_security_reports }
 
......
......@@ -18,7 +18,7 @@ describe API::VulnerabilityFindings do
end
 
let(:pipeline) { create(:ci_empty_pipeline, status: :created, project: project) }
let(:pipeline_without_vulnerabilities) { create(:ci_pipeline_without_jobs, status: :created, project: project) }
let(:pipeline_without_vulnerabilities) { create(:ci_pipeline, status: :created, project: project) }
 
let(:build_ds) { create(:ci_build, :success, name: 'ds_job', pipeline: pipeline, project: project) }
let(:build_sast) { create(:ci_build, :success, name: 'sast_job', pipeline: pipeline, project: project) }
......
......@@ -440,7 +440,7 @@ describe SystemNoteService do
describe '.add_to_merge_train_when_pipeline_succeeds' do
subject { described_class.add_to_merge_train_when_pipeline_succeeds(noteable, project, author, pipeline.sha) }
 
let(:pipeline) { build(:ci_pipeline_without_jobs) }
let(:pipeline) { build(:ci_pipeline) }
 
let(:noteable) do
create(:merge_request, source_project: project, target_project: project)
......
......@@ -149,7 +149,7 @@ describe Projects::PipelinesController do
end
 
describe 'GET show.json' do
let(:pipeline) { create(:ci_pipeline_with_one_job, project: project) }
let(:pipeline) { create(:ci_pipeline, project: project) }
 
it 'returns the pipeline' do
get_pipeline_json
......
# frozen_string_literal: true
 
FactoryBot.define do
# TODO: we can remove this factory in favour of :ci_pipeline
factory :ci_empty_pipeline, class: Ci::Pipeline do
source { :push }
ref { 'master' }
......@@ -10,20 +11,6 @@ FactoryBot.define do
 
project
 
factory :ci_pipeline_without_jobs do
after(:build) do |pipeline|
pipeline.instance_variable_set(:@ci_yaml_file, YAML.dump({}))
end
end
factory :ci_pipeline_with_one_job do
after(:build) do |pipeline|
allow(pipeline).to receive(:ci_yaml_file) do
pipeline.instance_variable_set(:@ci_yaml_file, YAML.dump({ rspec: { script: "ls" } }))
end
end
end
# Persist merge request head_pipeline_id
# on pipeline factories to avoid circular references
transient { head_pipeline_of { nil } }
......@@ -34,24 +21,8 @@ FactoryBot.define do
end
 
factory :ci_pipeline do
transient { config { nil } }
after(:build) do |pipeline, evaluator|
if evaluator.config
pipeline.instance_variable_set(:@ci_yaml_file, YAML.dump(evaluator.config))
# Populates pipeline with errors
pipeline.config_processor if evaluator.config
else
pipeline.instance_variable_set(:@ci_yaml_file, File.read(Rails.root.join('spec/support/gitlab_stubs/gitlab_ci.yml')))
end
end
trait :invalid do
config do
{ rspec: nil }
end
yaml_errors { 'invalid YAML' }
failure_reason { :config_error }
end
 
......
......@@ -7,7 +7,7 @@ FactoryBot.define do
stage_idx { 0 }
status { 'success' }
description { 'commit status'}
pipeline factory: :ci_pipeline_with_one_job
pipeline factory: :ci_pipeline
started_at { 'Tue, 26 Jan 2016 08:21:42 +0100'}
finished_at { 'Tue, 26 Jan 2016 08:23:42 +0100'}
 
......
......@@ -11,7 +11,7 @@ describe 'Merge request > User sees deployment widget', :js do
let(:role) { :developer }
let(:ref) { merge_request.target_branch }
let(:sha) { project.commit(ref).id }
let(:pipeline) { create(:ci_pipeline_without_jobs, sha: sha, project: project, ref: ref) }
let(:pipeline) { create(:ci_pipeline, sha: sha, project: project, ref: ref) }
let!(:manual) { }
 
before do
......@@ -33,7 +33,7 @@ describe 'Merge request > User sees deployment widget', :js do
end
 
context 'when a user created a new merge request with the same SHA' do
let(:pipeline2) { create(:ci_pipeline_without_jobs, sha: sha, project: project, ref: 'new-patch-1') }
let(:pipeline2) { create(:ci_pipeline, sha: sha, project: project, ref: 'new-patch-1') }
let(:build2) { create(:ci_build, :success, pipeline: pipeline2) }
let(:environment2) { create(:environment, project: project) }
let!(:deployment2) { create(:deployment, environment: environment2, sha: sha, ref: 'new-patch-1', deployable: build2) }
......
......@@ -44,7 +44,7 @@ describe 'Merge request > User sees merge widget', :js do
context 'view merge request' do
let!(:environment) { create(:environment, project: project) }
let(:sha) { project.commit(merge_request.source_branch).sha }
let(:pipeline) { create(:ci_pipeline_without_jobs, status: 'success', sha: sha, project: project, ref: merge_request.source_branch) }
let(:pipeline) { create(:ci_pipeline, status: 'success', sha: sha, project: project, ref: merge_request.source_branch) }
let(:build) { create(:ci_build, :success, pipeline: pipeline) }
 
let!(:deployment) do
......@@ -745,7 +745,7 @@ describe 'Merge request > User sees merge widget', :js do
 
context 'when MR has pipeline but user does not have permission' do
let(:sha) { project.commit(merge_request.source_branch).sha }
let!(:pipeline) { create(:ci_pipeline_without_jobs, status: 'success', sha: sha, project: project, ref: merge_request.source_branch) }
let!(:pipeline) { create(:ci_pipeline, status: 'success', sha: sha, project: project, ref: merge_request.source_branch) }
 
before do
project.update(
......
......@@ -7,9 +7,7 @@ describe Gitlab::Ci::Pipeline::Chain::Populate do
set(:user) { create(:user) }
 
let(:pipeline) do
build(:ci_pipeline_with_one_job, project: project,
ref: 'master',
user: user)
build(:ci_pipeline, project: project, ref: 'master', user: user)
end
 
let(:command) do
......@@ -22,6 +20,14 @@ describe Gitlab::Ci::Pipeline::Chain::Populate do
 
let(:step) { described_class.new(pipeline, command) }
 
let(:config) do
{ rspec: { script: 'rspec' } }
end
before do
stub_ci_pipeline_yaml_file(YAML.dump(config))
end
context 'when pipeline doesn not have seeds block' do
before do
step.perform!
......@@ -59,10 +65,6 @@ describe Gitlab::Ci::Pipeline::Chain::Populate do
} }
end
 
let(:pipeline) do
build(:ci_pipeline, project: project, config: config)
end
before do
step.perform!
end
......@@ -202,10 +204,6 @@ describe Gitlab::Ci::Pipeline::Chain::Populate do
prod: { script: 'cap prod', stage: 'deploy', only: ['tags'] } }
end
 
let(:pipeline) do
build(:ci_pipeline, ref: 'master', project: project, config: config)
end
it_behaves_like 'a correct pipeline'
 
context 'when variables expression is specified' do
......
......@@ -6,13 +6,17 @@ describe Gitlab::Ci::Pipeline::Chain::RemoveUnwantedChatJobs do
let(:project) { create(:project, :repository) }
 
let(:pipeline) do
build(:ci_pipeline_with_one_job, project: project, ref: 'master')
build(:ci_pipeline, project: project)
end
 
let(:command) do
double(:command, project: project, chat_data: { command: 'echo' })
end
 
before do
stub_ci_pipeline_yaml_file(YAML.dump(rspec: { script: 'rspec' }))
end
describe '#perform!' do
it 'removes unwanted jobs for chat pipelines' do
allow(pipeline).to receive(:chat?).and_return(true)
......
......@@ -13,11 +13,13 @@ describe Gitlab::Ci::Pipeline::Chain::Validate::Config do
save_incompleted: true)
end
 
let(:pipeline) do
build(:ci_pipeline, project: project)
end
let!(:step) { described_class.new(pipeline, command) }
 
before do
step.perform!
end
subject { step.perform! }
 
context 'when pipeline has no YAML configuration' do
let(:pipeline) do
......@@ -25,18 +27,23 @@ describe Gitlab::Ci::Pipeline::Chain::Validate::Config do
end
 
it 'appends errors about missing configuration' do
subject
expect(pipeline.errors.to_a)
.to include 'Missing .gitlab-ci.yml file'
end
 
it 'breaks the chain' do
subject
expect(step.break?).to be true
end
end
 
context 'when YAML configuration contains errors' do
let(:pipeline) do
build(:ci_pipeline, project: project, config: 'invalid YAML')
before do
stub_ci_pipeline_yaml_file('invalid YAML')
subject
end
 
it 'appends errors about YAML errors' do
......@@ -56,10 +63,14 @@ describe Gitlab::Ci::Pipeline::Chain::Validate::Config do
end
 
it 'fails the pipeline' do
subject
expect(pipeline.reload).to be_failed
end
 
it 'sets a config error failure reason' do
subject
expect(pipeline.reload.config_error?).to eq true
end
end
......@@ -72,6 +83,8 @@ describe Gitlab::Ci::Pipeline::Chain::Validate::Config do
end
 
it 'does not drop pipeline' do
subject
expect(pipeline).not_to be_failed
expect(pipeline).not_to be_persisted
end
......@@ -79,17 +92,15 @@ describe Gitlab::Ci::Pipeline::Chain::Validate::Config do
end
 
context 'when pipeline contains configuration validation errors' do
let(:config) do
{
before do
stub_ci_pipeline_yaml_file(YAML.dump({
rspec: {
before_script: 10,
script: 'ls -al'
}
}
end
}))
 
let(:pipeline) do
build(:ci_pipeline, project: project, config: config)
subject
end
 
it 'appends configuration validation errors to pipeline errors' do
......@@ -103,8 +114,13 @@ describe Gitlab::Ci::Pipeline::Chain::Validate::Config do
end
 
context 'when pipeline is correct and complete' do
let(:pipeline) do
build(:ci_pipeline_with_one_job, project: project)
before do
stub_ci_pipeline_yaml_file(YAML.dump({
rspec: {
script: 'rspec'
}
}))
subject
end
 
it 'does not invalidate the pipeline' do
......@@ -119,6 +135,7 @@ describe Gitlab::Ci::Pipeline::Chain::Validate::Config do
context 'when pipeline source is merge request' do
before do
stub_ci_pipeline_yaml_file(YAML.dump(config))
subject
end
 
let(:pipeline) { build_stubbed(:ci_pipeline, project: project) }
......
......@@ -132,10 +132,6 @@ describe Gitlab::ImportExport::FastHashSerializer do
end
 
it 'has no when YML attributes but only the DB column' do
allow_any_instance_of(Ci::Pipeline)
.to receive(:ci_yaml_file)
.and_return(File.read(Rails.root.join('spec/support/gitlab_stubs/gitlab_ci.yml')))
expect_any_instance_of(Gitlab::Ci::YamlProcessor).not_to receive(:build_attributes)
 
subject
......
......@@ -203,7 +203,6 @@ describe Gitlab::ImportExport::ProjectTreeSaver do
end
 
it 'has no when YML attributes but only the DB column' do
allow_any_instance_of(Ci::Pipeline).to receive(:ci_yaml_file).and_return(File.read(Rails.root.join('spec/support/gitlab_stubs/gitlab_ci.yml')))
expect_any_instance_of(Gitlab::Ci::YamlProcessor).not_to receive(:build_attributes)
 
saved_project_json
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment