Commit 30f58cf3 authored by Grzegorz Bizon's avatar Grzegorz Bizon

Add [] method for accessing ci entry dependencies

parent 4f837f66
...@@ -20,6 +20,10 @@ module Gitlab ...@@ -20,6 +20,10 @@ module Gitlab
@validator.validate(:new) @validator.validate(:new)
end end
def [](key)
@entries[key] || Node::Undefined.new
end
def compose!(deps = nil) def compose!(deps = nil)
return unless valid? return unless valid?
......
...@@ -253,4 +253,27 @@ describe Gitlab::Ci::Config::Node::Global do ...@@ -253,4 +253,27 @@ describe Gitlab::Ci::Config::Node::Global do
expect(global.specified?).to be true expect(global.specified?).to be true
end end
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 end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment