Commit 1339fda1 authored by Grzegorz Bizon's avatar Grzegorz Bizon

Minor refactorings in CI config

parent 2972a991
...@@ -45,7 +45,10 @@ module Ci ...@@ -45,7 +45,10 @@ module Ci
end end
def job_variables(name) def job_variables(name)
@jobs[name.to_sym].try(:fetch, :variables, []) || [] job = @jobs[name.to_sym]
return [] unless job
job.fetch(:variables, [])
end end
private private
...@@ -123,7 +126,7 @@ module Ci ...@@ -123,7 +126,7 @@ module Ci
end end
unless @variables.nil? || validate_variables(@variables) unless @variables.nil? || validate_variables(@variables)
raise ValidationError, "variables should be a map of key-valued strings" raise ValidationError, "variables should be a map of key-value strings"
end end
if @cache if @cache
...@@ -216,9 +219,9 @@ module Ci ...@@ -216,9 +219,9 @@ module Ci
end end
def validate_job_variables!(name, job) def validate_job_variables!(name, job)
if job[:variables] && !validate_variables(job[:variables]) unless validate_variables(job[:variables])
raise ValidationError, raise ValidationError,
"#{name} job: variables should be a map of key-valued strings" "#{name} job: variables should be a map of key-value strings"
end end
end end
......
...@@ -786,14 +786,14 @@ EOT ...@@ -786,14 +786,14 @@ EOT
config = YAML.dump({ variables: "test", rspec: { script: "test" } }) config = YAML.dump({ variables: "test", rspec: { script: "test" } })
expect do expect do
GitlabCiYamlProcessor.new(config, path) GitlabCiYamlProcessor.new(config, path)
end.to raise_error(GitlabCiYamlProcessor::ValidationError, "variables should be a map of key-valued strings") end.to raise_error(GitlabCiYamlProcessor::ValidationError, "variables should be a map of key-value strings")
end end
it "returns errors if variables is not a map of key-valued strings" do it "returns errors if variables is not a map of key-value strings" do
config = YAML.dump({ variables: { test: false }, rspec: { script: "test" } }) config = YAML.dump({ variables: { test: false }, rspec: { script: "test" } })
expect do expect do
GitlabCiYamlProcessor.new(config, path) GitlabCiYamlProcessor.new(config, path)
end.to raise_error(GitlabCiYamlProcessor::ValidationError, "variables should be a map of key-valued strings") end.to raise_error(GitlabCiYamlProcessor::ValidationError, "variables should be a map of key-value strings")
end end
it "returns errors if job when is not on_success, on_failure or always" do it "returns errors if job when is not on_success, on_failure or always" do
......
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