Verified Commit 5eefb6a5 authored by Matija Čupić's avatar Matija Čupić
Browse files

Simplify script validation error message

Simplifies script validation error messages and adds more specs to cover
the changes.
parent bf5f4271
......@@ -109,7 +109,7 @@ describe Gitlab::WebIde::Config::Entry::Global do
describe '#errors' do
it 'reports errors about missing script' do
expect(global.errors)
.to include "terminal:before_script config should be an array of strings"
.to include "terminal:before_script config should be an array of strings and arrays of strings"
end
end
end
......
......@@ -14,7 +14,7 @@ module Gitlab
validate do
unless config.is_a?(String) ||
(config.is_a?(Array) && config.all? { |element| element.is_a?(String) || validate_array_of_strings?(element) })
errors.add(:config, 'should be an array of strings and arrays of strings or string')
errors.add(:config, 'should be a string or an array of strings and arrays of strings')
end
end
 
......
......@@ -13,7 +13,7 @@ module Gitlab
validations do
validate do
unless config.is_a?(Array) && config.all? { |element| element.is_a?(String) || validate_array_of_strings?(element) }
errors.add(:config, 'should be an array of strings and arrays of strings or string')
errors.add(:config, 'should be an array of strings and arrays of strings')
end
end
 
......
......@@ -87,7 +87,7 @@ describe Gitlab::Ci::Config::Entry::Commands do
describe '#errors' do
it 'saves errors' do
expect(entry.errors)
.to include 'commands config should be an array of strings and arrays of strings or string'
.to include 'commands config should be a string or an array of strings and arrays of strings'
end
end
end
......@@ -98,7 +98,7 @@ describe Gitlab::Ci::Config::Entry::Commands do
describe '#errors' do
it 'saves errors' do
expect(entry.errors)
.to include 'commands config should be an array of strings and arrays of strings or string'
.to include 'commands config should be a string or an array of strings and arrays of strings'
end
end
 
......
......@@ -293,7 +293,7 @@ describe Gitlab::Ci::Config::Entry::Root do
describe '#errors' do
it 'reports errors from child nodes' do
expect(root.errors)
.to include 'before_script config should be an array of strings'
.to include 'before_script config should be an array of strings and arrays of strings'
end
end
end
......
......@@ -78,7 +78,7 @@ describe Gitlab::Ci::Config::Entry::Script do
describe '#errors' do
it 'saves errors' do
expect(entry.errors)
.to include 'script config should be an array of strings and arrays of strings or string'
.to include 'script config should be an array of strings and arrays of strings'
end
end
 
......@@ -95,7 +95,7 @@ describe Gitlab::Ci::Config::Entry::Script do
describe '#errors' do
it 'saves errors' do
expect(entry.errors)
.to include 'script config should be an array of strings and arrays of strings or string'
.to include 'script config should be an array of strings and arrays of strings'
end
end
 
......
......@@ -94,7 +94,7 @@ describe Gitlab::Ci::Pipeline::Chain::Validate::Config do
 
it 'appends configuration validation errors to pipeline errors' do
expect(pipeline.errors.to_a)
.to include "jobs:rspec:before_script config should be an array of strings"
.to include "jobs:rspec:before_script config should be an array of strings and arrays of strings"
end
 
it 'breaks the chain' do
......
......@@ -1587,28 +1587,42 @@ module Gitlab
config = YAML.dump({ before_script: "bundle update", rspec: { script: "test" } })
expect do
Gitlab::Ci::YamlProcessor.new(config)
end.to raise_error(Gitlab::Ci::YamlProcessor::ValidationError, "before_script config should be an array of strings")
end.to raise_error(Gitlab::Ci::YamlProcessor::ValidationError, "before_script config should be an array of strings and arrays of strings")
end
 
it "returns errors if job before_script parameter is not an array of strings" do
config = YAML.dump({ rspec: { script: "test", before_script: [10, "test"] } })
expect do
Gitlab::Ci::YamlProcessor.new(config)
end.to raise_error(Gitlab::Ci::YamlProcessor::ValidationError, "jobs:rspec:before_script config should be an array of strings")
end.to raise_error(Gitlab::Ci::YamlProcessor::ValidationError, "jobs:rspec:before_script config should be an array of strings and arrays of strings")
end
it "returns errors if job before_script parameter is multi-level nested array of strings" do
config = YAML.dump({ rspec: { script: "test", before_script: [["ls", ["pwd"]], "test"] } })
expect do
Gitlab::Ci::YamlProcessor.new(config)
end.to raise_error(Gitlab::Ci::YamlProcessor::ValidationError, "jobs:rspec:before_script config should be an array of strings and arrays of strings")
end
 
it "returns errors if after_script parameter is invalid" do
config = YAML.dump({ after_script: "bundle update", rspec: { script: "test" } })
expect do
Gitlab::Ci::YamlProcessor.new(config)
end.to raise_error(Gitlab::Ci::YamlProcessor::ValidationError, "after_script config should be an array of strings")
end.to raise_error(Gitlab::Ci::YamlProcessor::ValidationError, "after_script config should be an array of strings and arrays of strings")
end
 
it "returns errors if job after_script parameter is not an array of strings" do
config = YAML.dump({ rspec: { script: "test", after_script: [10, "test"] } })
expect do
Gitlab::Ci::YamlProcessor.new(config)
end.to raise_error(Gitlab::Ci::YamlProcessor::ValidationError, "jobs:rspec:after_script config should be an array of strings")
end.to raise_error(Gitlab::Ci::YamlProcessor::ValidationError, "jobs:rspec:after_script config should be an array of strings and arrays of strings")
end
it "returns errors if job after_script parameter is multi-level nested array of strings" do
config = YAML.dump({ rspec: { script: "test", after_script: [["ls", ["pwd"]], "test"] } })
expect do
Gitlab::Ci::YamlProcessor.new(config)
end.to raise_error(Gitlab::Ci::YamlProcessor::ValidationError, "jobs:rspec:after_script config should be an array of strings and arrays of strings")
end
 
it "returns errors if image parameter is invalid" do
......
Supports Markdown
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