提交 cf3e3eff 编写于 作者: G Grzegorz Bizon

Minor refactoring in code related to job variables

上级 a6260b1e
...@@ -45,11 +45,7 @@ module Ci ...@@ -45,11 +45,7 @@ module Ci
end end
def job_variables(name) def job_variables(name)
if job = @jobs[name.to_sym] @jobs[name.to_sym].try(:fetch, :variables, []) || []
job[:variables] || []
else
[]
end
end end
private private
......
...@@ -345,50 +345,55 @@ module Ci ...@@ -345,50 +345,55 @@ module Ci
end end
end end
describe "Variables" do describe 'Variables' do
context 'when global variables are defined' do context 'when global variables are defined' do
it 'returns variables' do it 'returns global variables' do
variables = { variables = {
var1: "value1", VAR1: 'value1',
var2: "value2", VAR2: 'value2',
} }
config = YAML.dump({ config = YAML.dump({
variables: variables, variables: variables,
before_script: ["pwd"], before_script: ['pwd'],
rspec: { script: "rspec" } rspec: { script: 'rspec' }
}) })
config_processor = GitlabCiYamlProcessor.new(config, path) config_processor = GitlabCiYamlProcessor.new(config, path)
expect(config_processor.global_variables).to eq(variables) expect(config_processor.global_variables).to eq(variables)
end end
end end
context 'when job variables are defined' do context 'when job variables are defined' do
let(:job_variables) { { KEY1: 'value1', SOME_KEY_2: 'value2' } } it 'returns job variables' do
let(:yaml_config) do variables = {
YAML.dump( KEY1: 'value1',
SOME_KEY_2: 'value2'
}
config = YAML.dump(
{ before_script: ['pwd'], { before_script: ['pwd'],
rspec: { rspec: {
variables: job_variables, variables: variables,
script: 'rspec' } script: 'rspec' }
}) })
end
it 'returns job variables' do config_processor = GitlabCiYamlProcessor.new(config, path)
config = GitlabCiYamlProcessor.new(yaml_config, path)
expect(config.job_variables(:rspec)).to eq job_variables expect(config_processor.job_variables(:rspec)).to eq variables
end end
end end
context 'when job variables are not defined' do context 'when job variables are not defined' do
it 'returns empty array' do it 'returns empty array' do
config = YAML.dump({ config = YAML.dump({
before_script: ["pwd"], before_script: ['pwd'],
rspec: { script: "rspec" } rspec: { script: 'rspec' }
}) })
config_processor = GitlabCiYamlProcessor.new(config, path) config_processor = GitlabCiYamlProcessor.new(config, path)
expect(config_processor.job_variables(:rspec)).to eq [] expect(config_processor.job_variables(:rspec)).to eq []
end end
end end
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册