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

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

137 lines
3.5 KiB
Ruby
Raw Normal View History

2020-04-22 19:07:51 +05:30
# frozen_string_literal: true
2021-10-27 15:23:28 +05:30
require 'fast_spec_helper'
2022-04-04 11:22:00 +05:30
require_dependency 'active_model'
2020-04-22 19:07:51 +05:30
2020-07-28 23:09:34 +05:30
RSpec.describe ::Gitlab::Ci::Config::Entry::Include do
2020-04-22 19:07:51 +05:30
subject(:include_entry) { described_class.new(config) }
describe 'validations' do
before do
include_entry.compose!
end
context 'when value is a string' do
let(:config) { 'test.yml' }
it { is_expected.to be_valid }
end
context 'when value is hash' do
context 'when using not allowed keys' do
let(:config) do
{ not_allowed: 'key' }
end
it { is_expected.not_to be_valid }
end
context 'when using "local"' do
let(:config) { { local: 'test.yml' } }
it { is_expected.to be_valid }
end
context 'when using "file"' do
let(:config) { { file: 'test.yml' } }
it { is_expected.to be_valid }
end
context 'when using "template"' do
let(:config) { { template: 'test.yml' } }
it { is_expected.to be_valid }
end
context 'when using "artifact"' do
context 'and specifying "job"' do
let(:config) { { artifact: 'test.yml', job: 'generator' } }
it { is_expected.to be_valid }
end
context 'without "job"' do
let(:config) { { artifact: 'test.yml' } }
it { is_expected.not_to be_valid }
it 'has specific error' do
expect(include_entry.errors)
.to include('include config must specify the job where to fetch the artifact from')
end
end
end
2021-01-03 14:25:43 +05:30
context 'when using "project"' do
context 'and specifying "ref" and "file"' do
let(:config) { { project: 'my-group/my-pipeline-library', ref: 'master', file: 'test.yml' } }
it { is_expected.to be_valid }
end
context 'without "ref"' do
let(:config) { { project: 'my-group/my-pipeline-library', file: 'test.yml' } }
it { is_expected.to be_valid }
end
context 'without "file"' do
let(:config) { { project: 'my-group/my-pipeline-library' } }
it { is_expected.not_to be_valid }
it 'has specific error' do
expect(include_entry.errors)
.to include('include config must specify the file where to fetch the config from')
end
end
end
2021-10-27 15:23:28 +05:30
context 'when using with "rules"' do
let(:config) { { local: 'test.yml', rules: [{ if: '$VARIABLE' }] } }
it { is_expected.to be_valid }
context 'when rules is not an array of hashes' do
let(:config) { { local: 'test.yml', rules: ['$VARIABLE'] } }
it { is_expected.not_to be_valid }
it 'has specific error' do
expect(include_entry.errors).to include('include rules should be an array of hashes')
end
end
end
2020-04-22 19:07:51 +05:30
end
context 'when value is something else' do
let(:config) { 123 }
it { is_expected.not_to be_valid }
end
end
2021-10-27 15:23:28 +05:30
describe '#value' do
subject(:value) { include_entry.value }
context 'when config is a string' do
let(:config) { 'test.yml' }
it { is_expected.to eq('test.yml') }
end
context 'when config is a hash' do
let(:config) { { local: 'test.yml' } }
it { is_expected.to eq(local: 'test.yml') }
end
context 'when config has "rules"' do
let(:config) { { local: 'test.yml', rules: [{ if: '$VARIABLE' }] } }
it { is_expected.to eq(local: 'test.yml', rules: [{ if: '$VARIABLE' }]) }
end
end
2020-04-22 19:07:51 +05:30
end