Add [] method for accessing ci entry dependencies

This commit is contained in:
Grzegorz Bizon 2016-08-25 14:31:06 +02:00
parent 4f837f6690
commit 30f58cf392
2 changed files with 27 additions and 0 deletions

View File

@ -20,6 +20,10 @@ module Gitlab
@validator.validate(:new)
end
def [](key)
@entries[key] || Node::Undefined.new
end
def compose!(deps = nil)
return unless valid?

View File

@ -253,4 +253,27 @@ describe Gitlab::Ci::Config::Node::Global do
expect(global.specified?).to be true
end
end
describe '#[]' do
before { global.compose! }
let(:hash) do
{ cache: { key: 'a' }, rspec: { script: 'ls' } }
end
context 'when node exists' do
it 'returns correct entry' do
expect(global[:cache])
.to be_an_instance_of Gitlab::Ci::Config::Node::Cache
expect(global[:jobs][:rspec][:script].value).to eq ['ls']
end
end
context 'when node does not exist' do
it 'always return unspecified node' do
expect(global[:some][:unknown][:node])
.not_to be_specified
end
end
end
end