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

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

124 lines
2.8 KiB
Ruby
Raw Normal View History

2019-10-12 21:52:04 +05:30
# frozen_string_literal: true
2016-08-24 12:49:21 +05:30
require 'spec_helper'
2020-07-28 23:09:34 +05:30
RSpec.describe Gitlab::Ci::Config::Entry::Variables do
2021-02-22 17:27:13 +05:30
let(:metadata) { {} }
2021-03-08 18:12:59 +05:30
subject { described_class.new(config, **metadata) }
2016-08-24 12:49:21 +05:30
2021-01-03 14:25:43 +05:30
shared_examples 'valid config' do
describe '#value' do
it 'returns hash with key value strings' do
expect(subject.value).to eq result
2016-08-24 12:49:21 +05:30
end
2021-01-03 14:25:43 +05:30
end
2016-08-24 12:49:21 +05:30
2021-01-03 14:25:43 +05:30
describe '#errors' do
it 'does not append errors' do
expect(subject.errors).to be_empty
end
end
2017-09-10 17:25:29 +05:30
2021-01-03 14:25:43 +05:30
describe '#valid?' do
it 'is valid' do
expect(subject).to be_valid
2016-08-24 12:49:21 +05:30
end
2021-01-03 14:25:43 +05:30
end
end
2016-08-24 12:49:21 +05:30
2021-01-03 14:25:43 +05:30
shared_examples 'invalid config' do
describe '#valid?' do
it 'is not valid' do
expect(subject).not_to be_valid
2016-08-24 12:49:21 +05:30
end
2021-01-03 14:25:43 +05:30
end
2016-08-24 12:49:21 +05:30
2021-01-03 14:25:43 +05:30
describe '#errors' do
it 'saves errors' do
expect(subject.errors)
.to include /should be a hash of key value pairs/
2016-08-24 12:49:21 +05:30
end
end
2021-01-03 14:25:43 +05:30
end
2016-08-24 12:49:21 +05:30
2021-01-03 14:25:43 +05:30
context 'when entry config value has key-value pairs' do
let(:config) do
{ 'VARIABLE_1' => 'value 1', 'VARIABLE_2' => 'value 2' }
end
2016-08-24 12:49:21 +05:30
2021-01-03 14:25:43 +05:30
let(:result) do
{ 'VARIABLE_1' => 'value 1', 'VARIABLE_2' => 'value 2' }
end
2016-08-24 12:49:21 +05:30
2021-01-03 14:25:43 +05:30
it_behaves_like 'valid config'
end
context 'with numeric keys and values in the config' do
let(:config) { { 10 => 20 } }
let(:result) do
{ '10' => '20' }
end
it_behaves_like 'valid config'
end
context 'when entry config value has key-value pair and hash' do
let(:config) do
{ 'VARIABLE_1' => { value: 'value 1', description: 'variable 1' },
'VARIABLE_2' => 'value 2' }
end
let(:result) do
{ 'VARIABLE_1' => 'value 1', 'VARIABLE_2' => 'value 2' }
end
2021-02-22 17:27:13 +05:30
it_behaves_like 'invalid config'
context 'when metadata has use_value_data' do
let(:metadata) { { use_value_data: true } }
it_behaves_like 'valid config'
end
2021-01-03 14:25:43 +05:30
end
context 'when entry value is an array' do
let(:config) { [:VAR, 'test'] }
it_behaves_like 'invalid config'
end
2021-02-22 17:27:13 +05:30
context 'when metadata has use_value_data' do
let(:metadata) { { use_value_data: true } }
2021-01-03 14:25:43 +05:30
2021-02-22 17:27:13 +05:30
context 'when entry value has hash with other key-pairs' do
let(:config) do
{ 'VARIABLE_1' => { value: 'value 1', hello: 'variable 1' },
'VARIABLE_2' => 'value 2' }
end
2021-01-03 14:25:43 +05:30
2021-02-22 17:27:13 +05:30
it_behaves_like 'invalid config'
2021-01-03 14:25:43 +05:30
end
2021-02-22 17:27:13 +05:30
context 'when entry config value has hash with nil description' do
let(:config) do
{ 'VARIABLE_1' => { value: 'value 1', description: nil } }
end
2021-01-03 14:25:43 +05:30
2021-02-22 17:27:13 +05:30
it_behaves_like 'invalid config'
2021-01-03 14:25:43 +05:30
end
2021-02-22 17:27:13 +05:30
context 'when entry config value has hash without description' do
let(:config) do
{ 'VARIABLE_1' => { value: 'value 1' } }
end
2021-01-03 14:25:43 +05:30
2021-02-22 17:27:13 +05:30
let(:result) do
{ 'VARIABLE_1' => 'value 1' }
end
it_behaves_like 'valid config'
end
2016-08-24 12:49:21 +05:30
end
end