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

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

226 lines
5.8 KiB
Ruby
Raw Normal View History

2020-03-13 15:44:24 +05:30
# frozen_string_literal: true
require 'spec_helper'
2023-03-04 22:38:38 +05:30
RSpec.describe Gitlab::Ci::Config::Entry::Trigger, feature_category: :pipeline_authoring do
2020-03-13 15:44:24 +05:30
subject { described_class.new(config) }
context 'when trigger config is a non-empty string' do
let(:config) { 'some/project' }
describe '#valid?' do
it { is_expected.to be_valid }
end
describe '#value' do
it 'returns a trigger configuration hash' do
expect(subject.value).to eq(project: 'some/project')
end
end
end
context 'when trigger config an empty string' do
let(:config) { '' }
describe '#valid?' do
it { is_expected.not_to be_valid }
end
describe '#errors' do
it 'returns an error about an empty config' do
expect(subject.errors.first)
.to match /config can't be blank/
end
end
end
2022-05-07 20:08:51 +05:30
context 'when trigger is a hash - cross-project' do
2023-03-04 22:38:38 +05:30
context 'when project is a string' do
context 'when project is a non-empty string' do
let(:config) { { project: 'some/project' } }
it 'is valid' do
expect(subject).to be_valid
end
end
context 'when project is an empty string' do
let(:config) { { project: '' } }
it 'returns error' do
expect(subject).not_to be_valid
expect(subject.errors.first)
.to match /project can't be blank/
end
end
end
context 'when project is not a string' do
context 'when project is an array' do
let(:config) { { project: ['some/project'] } }
it 'returns error' do
expect(subject).not_to be_valid
expect(subject.errors.first)
.to match /should be a string/
end
end
context 'when project is a boolean' do
let(:config) { { project: true } }
it 'returns error' do
expect(subject).not_to be_valid
expect(subject.errors.first)
.to match /should be a string/
end
end
end
2020-03-13 15:44:24 +05:30
context 'when branch is provided' do
let(:config) { { project: 'some/project', branch: 'feature' } }
describe '#valid?' do
it { is_expected.to be_valid }
end
describe '#value' do
it 'returns a trigger configuration hash' do
expect(subject.value)
.to eq(project: 'some/project', branch: 'feature')
end
end
end
context 'when strategy is provided' do
context 'when strategy is depend' do
let(:config) { { project: 'some/project', strategy: 'depend' } }
describe '#valid?' do
it { is_expected.to be_valid }
end
describe '#value' do
it 'returns a trigger configuration hash' do
expect(subject.value)
.to eq(project: 'some/project', strategy: 'depend')
end
end
end
context 'when strategy is invalid' do
let(:config) { { project: 'some/project', strategy: 'notdepend' } }
describe '#valid?' do
it { is_expected.not_to be_valid }
end
describe '#errors' do
it 'returns an error about unknown config key' do
expect(subject.errors.first)
.to match /trigger strategy should be depend/
end
end
end
end
2022-05-07 20:08:51 +05:30
context 'when config contains unknown keys' do
let(:config) { { project: 'some/project', unknown: 123 } }
2020-03-13 15:44:24 +05:30
2022-05-07 20:08:51 +05:30
describe '#valid?' do
it { is_expected.not_to be_valid }
end
2020-03-13 15:44:24 +05:30
2022-05-07 20:08:51 +05:30
describe '#errors' do
it 'returns an error about unknown config key' do
expect(subject.errors.first)
.to match /config contains unknown keys: unknown/
2020-03-13 15:44:24 +05:30
end
end
2022-05-07 20:08:51 +05:30
end
2020-03-13 15:44:24 +05:30
2022-05-07 20:08:51 +05:30
context 'with forward' do
let(:config) { { project: 'some/project', forward: { pipeline_variables: true } } }
2020-03-13 15:44:24 +05:30
2022-05-07 20:08:51 +05:30
before do
subject.compose!
end
2020-03-13 15:44:24 +05:30
2022-05-07 20:08:51 +05:30
it { is_expected.to be_valid }
it 'returns a trigger configuration hash' do
expect(subject.value).to eq(
project: 'some/project', forward: { pipeline_variables: true }
)
2020-03-13 15:44:24 +05:30
end
2022-05-07 20:08:51 +05:30
end
end
2020-03-13 15:44:24 +05:30
2022-05-07 20:08:51 +05:30
context 'when trigger is a hash - parent-child' do
context 'with simple include' do
let(:config) { { include: 'path/to/config.yml' } }
2020-03-13 15:44:24 +05:30
2022-05-07 20:08:51 +05:30
it { is_expected.to be_valid }
2020-03-13 15:44:24 +05:30
2022-05-07 20:08:51 +05:30
it 'returns a trigger configuration hash' do
expect(subject.value).to eq(include: 'path/to/config.yml' )
2020-03-13 15:44:24 +05:30
end
end
2022-05-07 20:08:51 +05:30
context 'with project' do
let(:config) { { project: 'some/project', include: 'path/to/config.yml' } }
2020-03-13 15:44:24 +05:30
2022-05-07 20:08:51 +05:30
it { is_expected.not_to be_valid }
it 'returns an error' do
expect(subject.errors.first)
.to match /config contains unknown keys: project/
2020-03-13 15:44:24 +05:30
end
2022-05-07 20:08:51 +05:30
end
2020-03-13 15:44:24 +05:30
2022-05-07 20:08:51 +05:30
context 'with branch' do
let(:config) { { branch: 'feature', include: 'path/to/config.yml' } }
it { is_expected.not_to be_valid }
it 'returns an error' do
expect(subject.errors.first)
.to match /config contains unknown keys: branch/
end
end
context 'with forward' do
let(:config) { { include: 'path/to/config.yml', forward: { yaml_variables: false } } }
before do
subject.compose!
end
it { is_expected.to be_valid }
it 'returns a trigger configuration hash' do
expect(subject.value).to eq(
include: 'path/to/config.yml', forward: { yaml_variables: false }
)
2020-03-13 15:44:24 +05:30
end
end
end
context 'when trigger configuration is not valid' do
context 'when branch is not provided' do
let(:config) { 123 }
describe '#valid?' do
it { is_expected.not_to be_valid }
end
describe '#errors' do
it 'returns an error message' do
expect(subject.errors.first)
.to match /has to be either a string or a hash/
end
end
end
end
end