diff options
Diffstat (limited to 'spec/lib/gitlab/ci/config/entry/root_spec.rb')
-rw-r--r-- | spec/lib/gitlab/ci/config/entry/root_spec.rb | 49 |
1 files changed, 47 insertions, 2 deletions
diff --git a/spec/lib/gitlab/ci/config/entry/root_spec.rb b/spec/lib/gitlab/ci/config/entry/root_spec.rb index 085293d7368..c40589104cd 100644 --- a/spec/lib/gitlab/ci/config/entry/root_spec.rb +++ b/spec/lib/gitlab/ci/config/entry/root_spec.rb @@ -5,7 +5,8 @@ require 'spec_helper' RSpec.describe Gitlab::Ci::Config::Entry::Root do let(:user) {} let(:project) {} - let(:root) { described_class.new(hash, user: user, project: project) } + let(:logger) { Gitlab::Ci::Pipeline::Logger.new(project: project) } + let(:root) { described_class.new(hash, user: user, project: project, logger: logger) } describe '.nodes' do it 'returns a hash' do @@ -37,7 +38,7 @@ RSpec.describe Gitlab::Ci::Config::Entry::Root do variables: { VAR: 'root', VAR2: { value: 'val 2', description: 'this is var 2' }, - VAR3: { value: %w[val3 val3b], description: 'this is var 3' } + VAR3: { value: 'val3', options: %w[val3 val4 val5], description: 'this is var 3 and some options' } }, after_script: ['make clean'], stages: %w(build pages release), @@ -228,6 +229,14 @@ RSpec.describe Gitlab::Ci::Config::Entry::Root do ) end end + + it 'tracks log entries' do + expect(logger.observations_hash).to match( + a_hash_including( + 'config_root_compose_jobs_factory_duration_s' => a_kind_of(Numeric) + ) + ) + end end end @@ -317,6 +326,42 @@ RSpec.describe Gitlab::Ci::Config::Entry::Root do end end + context 'when variables have `options` data' do + before do + root.compose! + end + + context 'and the value is in the `options` array' do + let(:hash) do + { + variables: { 'VAR' => { value: 'val1', options: %w[val1 val2] } }, + rspec: { script: 'bin/rspec' } + } + end + + it 'returns correct value' do + expect(root.variables_entry.value_with_data).to eq( + 'VAR' => { value: 'val1' } + ) + + expect(root.variables_value).to eq('VAR' => 'val1') + end + end + + context 'and the value is not in the `options` array' do + let(:hash) do + { + variables: { 'VAR' => { value: 'val', options: %w[val1 val2] } }, + rspec: { script: 'bin/rspec' } + } + end + + it 'returns an error' do + expect(root.errors).to contain_exactly('variables:var config value must be present in options') + end + end + end + context 'when variables have "expand" data' do let(:hash) do { |