2021-02-22 17:27:13 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
RSpec.describe Gitlab::Ci::Pipeline::Seed::Pipeline do
|
|
|
|
let_it_be(:project) { create(:project, :repository) }
|
|
|
|
let_it_be(:pipeline) { create(:ci_pipeline, project: project) }
|
|
|
|
|
2021-04-29 21:17:54 +05:30
|
|
|
let(:seed_context) { double(pipeline: pipeline, root_variables: []) }
|
|
|
|
|
2021-02-22 17:27:13 +05:30
|
|
|
let(:stages_attributes) do
|
|
|
|
[
|
|
|
|
{
|
|
|
|
name: 'build',
|
|
|
|
index: 0,
|
|
|
|
builds: [
|
|
|
|
{ name: 'init', scheduling_type: :stage },
|
|
|
|
{ name: 'build', scheduling_type: :stage }
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'test',
|
|
|
|
index: 1,
|
|
|
|
builds: [
|
|
|
|
{ name: 'rspec', scheduling_type: :stage },
|
|
|
|
{ name: 'staging', scheduling_type: :stage, environment: 'staging' },
|
|
|
|
{ name: 'deploy', scheduling_type: :stage, environment: 'production' }
|
|
|
|
]
|
|
|
|
}
|
|
|
|
]
|
|
|
|
end
|
|
|
|
|
|
|
|
subject(:seed) do
|
2021-04-29 21:17:54 +05:30
|
|
|
described_class.new(seed_context, stages_attributes)
|
2021-02-22 17:27:13 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
describe '#stages' do
|
|
|
|
it 'returns the stage resources' do
|
|
|
|
stages = seed.stages
|
|
|
|
|
|
|
|
expect(stages).to all(be_a(Ci::Stage))
|
|
|
|
expect(stages.map(&:name)).to contain_exactly('build', 'test')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#size' do
|
|
|
|
it 'returns the number of jobs' do
|
|
|
|
expect(seed.size).to eq(5)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#errors' do
|
|
|
|
context 'when attributes are valid' do
|
|
|
|
it 'returns nil' do
|
|
|
|
expect(seed.errors).to be_nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when attributes are not valid' do
|
|
|
|
it 'returns the errors' do
|
|
|
|
stages_attributes[0][:builds] << {
|
|
|
|
name: 'invalid_job',
|
|
|
|
scheduling_type: :dag,
|
|
|
|
needs_attributes: [{ name: 'non-existent', artifacts: true }]
|
|
|
|
}
|
|
|
|
|
2021-03-08 18:12:59 +05:30
|
|
|
expect(seed.errors).to contain_exactly(
|
2021-09-30 23:02:18 +05:30
|
|
|
"'invalid_job' job needs 'non-existent' job, but 'non-existent' is not in any previous stage")
|
2021-02-22 17:27:13 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#deployments_count' do
|
|
|
|
it 'counts the jobs having an environment associated' do
|
|
|
|
expect(seed.deployments_count).to eq(2)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|