debian-mirror-gitlab/spec/lib/gitlab/ci/config/entry/jobs_spec.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

146 lines
4.1 KiB
Ruby
Raw Normal View History

2019-10-12 21:52:04 +05:30
# frozen_string_literal: true
2016-09-13 17:45:13 +05:30
require 'spec_helper'
2020-07-28 23:09:34 +05:30
RSpec.describe Gitlab::Ci::Config::Entry::Jobs do
2016-09-13 17:45:13 +05:30
let(:entry) { described_class.new(config) }
2020-03-13 15:44:24 +05:30
let(:config) do
{
'.hidden_job'.to_sym => { script: 'something' },
'.hidden_bridge'.to_sym => { trigger: 'my/project' },
regular_job: { script: 'something' },
my_trigger: { trigger: 'my/project' }
}
end
2019-09-30 21:07:59 +05:30
describe '.all_types' do
subject { described_class.all_types }
it { is_expected.to include(::Gitlab::Ci::Config::Entry::Hidden) }
it { is_expected.to include(::Gitlab::Ci::Config::Entry::Job) }
2020-03-13 15:44:24 +05:30
it { is_expected.to include(::Gitlab::Ci::Config::Entry::Bridge) }
2019-09-30 21:07:59 +05:30
end
describe '.find_type' do
using RSpec::Parameterized::TableSyntax
where(:name, :type) do
:'.hidden_job' | ::Gitlab::Ci::Config::Entry::Hidden
2020-03-13 15:44:24 +05:30
:'.hidden_bridge' | ::Gitlab::Ci::Config::Entry::Hidden
2019-09-30 21:07:59 +05:30
:regular_job | ::Gitlab::Ci::Config::Entry::Job
2020-03-13 15:44:24 +05:30
:my_trigger | ::Gitlab::Ci::Config::Entry::Bridge
2019-09-30 21:07:59 +05:30
:invalid_job | nil
end
subject { described_class.find_type(name, config[name]) }
with_them do
it { is_expected.to eq(type) }
end
end
2016-09-13 17:45:13 +05:30
describe 'validations' do
2017-09-10 17:25:29 +05:30
before do
entry.compose!
end
2016-09-13 17:45:13 +05:30
context 'when entry config value is correct' do
describe '#valid?' do
it 'is valid' do
expect(entry).to be_valid
end
end
end
context 'when entry value is not correct' do
describe '#errors' do
context 'incorrect config value type' do
let(:config) { ['incorrect'] }
it 'returns error about incorrect type' do
expect(entry.errors)
.to include 'jobs config should be a hash'
end
end
2019-09-30 21:07:59 +05:30
context 'when job is invalid' do
2016-09-13 17:45:13 +05:30
let(:config) { { rspec: nil } }
it 'reports error' do
2020-11-24 15:15:51 +05:30
expect(entry.errors).to include 'jobs rspec config should implement a script: or a trigger: keyword'
2016-09-13 17:45:13 +05:30
end
2022-04-04 11:22:00 +05:30
context 'when the job name cannot be cast directly to a symbol' do
let(:config) { { true => nil } }
it 'properly parses the job name without raising a NoMethodError' do
expect(entry.errors).to include 'jobs true config should implement a script: or a trigger: keyword'
end
end
2016-09-13 17:45:13 +05:30
end
context 'when no visible jobs present' do
let(:config) { { '.hidden'.to_sym => { script: [] } } }
it 'returns error about no visible jobs defined' do
expect(entry.errors)
.to include 'jobs config should contain at least one visible job'
end
end
end
end
end
2019-09-30 21:07:59 +05:30
describe '.compose!' do
context 'when valid job entries composed' do
before do
entry.compose!
end
2016-09-13 17:45:13 +05:30
2019-09-30 21:07:59 +05:30
describe '#value' do
it 'returns key value' do
expect(entry.value).to eq(
2020-03-13 15:44:24 +05:30
my_trigger: {
ignore: false,
name: :my_trigger,
only: { refs: %w[branches tags] },
stage: 'test',
trigger: { project: 'my/project' },
2021-04-29 21:17:54 +05:30
job_variables: {},
root_variables_inheritance: true,
2020-03-13 15:44:24 +05:30
scheduling_type: :stage
},
regular_job: {
ignore: false,
name: :regular_job,
only: { refs: %w[branches tags] },
script: ['something'],
stage: 'test',
2021-04-29 21:17:54 +05:30
job_variables: {},
root_variables_inheritance: true,
2020-03-13 15:44:24 +05:30
scheduling_type: :stage
})
2019-09-30 21:07:59 +05:30
end
2016-09-13 17:45:13 +05:30
end
2019-09-30 21:07:59 +05:30
describe '#descendants' do
it 'creates valid descendant nodes' do
2020-03-13 15:44:24 +05:30
expect(entry.descendants.map(&:class)).to eq [
Gitlab::Ci::Config::Entry::Hidden,
Gitlab::Ci::Config::Entry::Hidden,
Gitlab::Ci::Config::Entry::Job,
Gitlab::Ci::Config::Entry::Bridge
]
2019-09-30 21:07:59 +05:30
end
2016-09-13 17:45:13 +05:30
end
2019-09-30 21:07:59 +05:30
describe '#value' do
it 'returns value of visible jobs only' do
2020-03-13 15:44:24 +05:30
expect(entry.value.keys).to eq [:regular_job, :my_trigger]
2019-09-30 21:07:59 +05:30
end
2016-09-13 17:45:13 +05:30
end
end
end
end