Commit 3a5cc77e authored by Shinya Maeda's avatar Shinya Maeda

Merge branch 'make-yaml-processor-return-results-1' into 'master'

Refactor specs for YamlProcessor

See merge request gitlab-org/gitlab!39868
parents c83a9450 5fe451d6
...@@ -9,6 +9,12 @@ module Gitlab ...@@ -9,6 +9,12 @@ module Gitlab
subject { described_class.new(config, user: nil) } subject { described_class.new(config, user: nil) }
shared_examples 'returns errors' do |error_message|
it 'raises exception when error encountered' do
expect { subject }.to raise_error(described_class::ValidationError, error_message)
end
end
describe '#build_attributes' do describe '#build_attributes' do
subject { described_class.new(config, user: nil).build_attributes(:rspec) } subject { described_class.new(config, user: nil).build_attributes(:rspec) }
...@@ -345,9 +351,7 @@ module Gitlab ...@@ -345,9 +351,7 @@ module Gitlab
EOYML EOYML
end end
it 'parses the workflow:rules configuration' do it_behaves_like 'returns errors', 'workflow config contains unknown keys: variables'
expect { subject }.to raise_error(Gitlab::Ci::YamlProcessor::ValidationError, 'workflow config contains unknown keys: variables')
end
end end
context 'with rules and variables' do context 'with rules and variables' do
...@@ -471,11 +475,11 @@ module Gitlab ...@@ -471,11 +475,11 @@ module Gitlab
it 'is propagated all the way up into the raised exception' do it 'is propagated all the way up into the raised exception' do
expect { subject }.to raise_error do |error| expect { subject }.to raise_error do |error|
expect(error).to be_a(described_class::ValidationError)
expect(error.message).to eq('jobs:invalid:artifacts config should be a hash')
expect(error.warnings).to contain_exactly(/jobs:rspec may allow multiple pipelines to run/) expect(error.warnings).to contain_exactly(/jobs:rspec may allow multiple pipelines to run/)
end end
end end
it_behaves_like 'returns errors', 'jobs:invalid:artifacts config should be a hash'
end end
context 'when error is raised before composing the config' do context 'when error is raised before composing the config' do
...@@ -491,11 +495,11 @@ module Gitlab ...@@ -491,11 +495,11 @@ module Gitlab
it 'raises an exception with empty warnings array' do it 'raises an exception with empty warnings array' do
expect { subject }.to raise_error do |error| expect { subject }.to raise_error do |error|
expect(error).to be_a(described_class::ValidationError)
expect(error.message).to eq('Local file `unknown/file.yml` does not have project!')
expect(error.warnings).to be_empty expect(error.warnings).to be_empty
end end
end end
it_behaves_like 'returns errors', 'Local file `unknown/file.yml` does not have project!'
end end
context 'when error is raised after composing the config with warnings' do context 'when error is raised after composing the config with warnings' do
...@@ -585,65 +589,49 @@ module Gitlab ...@@ -585,65 +589,49 @@ module Gitlab
describe 'only / except policies validations' do describe 'only / except policies validations' do
context 'when `only` has an invalid value' do context 'when `only` has an invalid value' do
let(:config) { { rspec: { script: "rspec", type: "test", only: only } } } let(:config) { { rspec: { script: "rspec", type: "test", only: only } } }
let(:processor) { Gitlab::Ci::YamlProcessor.new(YAML.dump(config)) }
subject { Gitlab::Ci::YamlProcessor.new(YAML.dump(config)) }
context 'when it is integer' do context 'when it is integer' do
let(:only) { 1 } let(:only) { 1 }
it do it_behaves_like 'returns errors', 'jobs:rspec:only has to be either an array of conditions or a hash'
expect { processor }.to raise_error(Gitlab::Ci::YamlProcessor::ValidationError,
'jobs:rspec:only has to be either an array of conditions or a hash')
end
end end
context 'when it is an array of integers' do context 'when it is an array of integers' do
let(:only) { [1, 1] } let(:only) { [1, 1] }
it do it_behaves_like 'returns errors', 'jobs:rspec:only config should be an array of strings or regexps'
expect { processor }.to raise_error(Gitlab::Ci::YamlProcessor::ValidationError,
'jobs:rspec:only config should be an array of strings or regexps')
end
end end
context 'when it is invalid regex' do context 'when it is invalid regex' do
let(:only) { ["/*invalid/"] } let(:only) { ["/*invalid/"] }
it do it_behaves_like 'returns errors', 'jobs:rspec:only config should be an array of strings or regexps'
expect { processor }.to raise_error(Gitlab::Ci::YamlProcessor::ValidationError,
'jobs:rspec:only config should be an array of strings or regexps')
end
end end
end end
context 'when `except` has an invalid value' do context 'when `except` has an invalid value' do
let(:config) { { rspec: { script: "rspec", except: except } } } let(:config) { { rspec: { script: "rspec", except: except } } }
let(:processor) { Gitlab::Ci::YamlProcessor.new(YAML.dump(config)) }
subject { Gitlab::Ci::YamlProcessor.new(YAML.dump(config)) }
context 'when it is integer' do context 'when it is integer' do
let(:except) { 1 } let(:except) { 1 }
it do it_behaves_like 'returns errors', 'jobs:rspec:except has to be either an array of conditions or a hash'
expect { processor }.to raise_error(Gitlab::Ci::YamlProcessor::ValidationError,
'jobs:rspec:except has to be either an array of conditions or a hash')
end
end end
context 'when it is an array of integers' do context 'when it is an array of integers' do
let(:except) { [1, 1] } let(:except) { [1, 1] }
it do it_behaves_like 'returns errors', 'jobs:rspec:except config should be an array of strings or regexps'
expect { processor }.to raise_error(Gitlab::Ci::YamlProcessor::ValidationError,
'jobs:rspec:except config should be an array of strings or regexps')
end
end end
context 'when it is invalid regex' do context 'when it is invalid regex' do
let(:except) { ["/*invalid/"] } let(:except) { ["/*invalid/"] }
it do it_behaves_like 'returns errors', 'jobs:rspec:except config should be an array of strings or regexps'
expect { processor }.to raise_error(Gitlab::Ci::YamlProcessor::ValidationError,
'jobs:rspec:except config should be an array of strings or regexps')
end
end end
end end
end end
...@@ -1040,11 +1028,7 @@ module Gitlab ...@@ -1040,11 +1028,7 @@ module Gitlab
%w(VAR1 value1 VAR2 value2) %w(VAR1 value1 VAR2 value2)
end end
it 'raises error' do it_behaves_like 'returns errors', /jobs:rspec:variables config should be a hash of key value pairs/
expect { subject }
.to raise_error(Gitlab::Ci::YamlProcessor::ValidationError,
/jobs:rspec:variables config should be a hash of key value pairs/)
end
end end
context 'when variables key defined but value not specified' do context 'when variables key defined but value not specified' do
...@@ -1156,17 +1140,13 @@ module Gitlab ...@@ -1156,17 +1140,13 @@ module Gitlab
context "when an array is provided" do context "when an array is provided" do
let(:include_content) { ["/local.gitlab-ci.yml"] } let(:include_content) { ["/local.gitlab-ci.yml"] }
it "returns a validation error" do it_behaves_like 'returns errors', /does not have project/
expect { subject }.to raise_error(Gitlab::Ci::YamlProcessor::ValidationError, /does not have project/)
end
end end
context "when an array of wrong keyed object is provided" do context "when an array of wrong keyed object is provided" do
let(:include_content) { [{ yolo: "/local.gitlab-ci.yml" }] } let(:include_content) { [{ yolo: "/local.gitlab-ci.yml" }] }
it "returns a validation error" do it_behaves_like 'returns errors', /needs to match exactly one accessor/
expect { subject }.to raise_error(Gitlab::Ci::YamlProcessor::ValidationError)
end
end end
context "when an array of mixed typed objects is provided" do context "when an array of mixed typed objects is provided" do
...@@ -1193,9 +1173,7 @@ module Gitlab ...@@ -1193,9 +1173,7 @@ module Gitlab
context "when the include type is incorrect" do context "when the include type is incorrect" do
let(:include_content) { { name: "/local.gitlab-ci.yml" } } let(:include_content) { { name: "/local.gitlab-ci.yml" } }
it "returns an invalid configuration error" do it_behaves_like 'returns errors', /needs to match exactly one accessor/
expect { subject }.to raise_error(Gitlab::Ci::YamlProcessor::ValidationError)
end
end end
end end
...@@ -1216,12 +1194,7 @@ module Gitlab ...@@ -1216,12 +1194,7 @@ module Gitlab
end end
context "when the included internal file is not present" do context "when the included internal file is not present" do
it "returns an error with missing file details" do it_behaves_like 'returns errors', "Local file `/local.gitlab-ci.yml` does not exist!"
expect { subject }.to raise_error(
Gitlab::Ci::YamlProcessor::ValidationError,
"Local file `#{include_content}` does not exist!"
)
end
end end
end end
end end
...@@ -1243,13 +1216,14 @@ module Gitlab ...@@ -1243,13 +1216,14 @@ module Gitlab
context 'delayed' do context 'delayed' do
context 'with start_in' do context 'with start_in' do
it 'creates one build and sets when:' do let(:config) do
config = YAML.dump({ YAML.dump({
rspec: { script: 'rspec', when: 'delayed', start_in: '1 hour' } rspec: { script: 'rspec', when: 'delayed', start_in: '1 hour' }
}) })
end
config_processor = Gitlab::Ci::YamlProcessor.new(config) it 'creates one build and sets when:' do
builds = config_processor.stage_builds_attributes("test") builds = subject.stage_builds_attributes("test")
expect(builds.size).to eq(1) expect(builds.size).to eq(1)
expect(builds.first[:when]).to eq('delayed') expect(builds.first[:when]).to eq('delayed')
...@@ -1258,15 +1232,13 @@ module Gitlab ...@@ -1258,15 +1232,13 @@ module Gitlab
end end
context 'without start_in' do context 'without start_in' do
it 'raises an error' do let(:config) do
config = YAML.dump({ YAML.dump({
rspec: { script: 'rspec', when: 'delayed' } rspec: { script: 'rspec', when: 'delayed' }
}) })
expect do
Gitlab::Ci::YamlProcessor.new(config)
end.to raise_error(YamlProcessor::ValidationError, /start in should be a duration/)
end end
it_behaves_like 'returns errors', /start in should be a duration/
end end
end end
end end
...@@ -1377,16 +1349,13 @@ module Gitlab ...@@ -1377,16 +1349,13 @@ module Gitlab
describe 'cache' do describe 'cache' do
context 'when cache definition has unknown keys' do context 'when cache definition has unknown keys' do
it 'raises relevant validation error' do let(:config) do
config = YAML.dump( YAML.dump(
{ cache: { untracked: true, invalid: 'key' }, { cache: { untracked: true, invalid: 'key' },
rspec: { script: 'rspec' } }) rspec: { script: 'rspec' } })
expect { Gitlab::Ci::YamlProcessor.new(config) }.to raise_error(
Gitlab::Ci::YamlProcessor::ValidationError,
'cache config contains unknown keys: invalid'
)
end end
it_behaves_like 'returns errors', 'cache config contains unknown keys: invalid'
end end
it "returns cache when defined globally" do it "returns cache when defined globally" do
...@@ -1594,8 +1563,9 @@ module Gitlab ...@@ -1594,8 +1563,9 @@ module Gitlab
end end
end end
it "gracefully handles errors in artifacts type" do context 'when artifacts syntax is wrong' do
config = <<~YAML let(:config) do
<<~YAML
test: test:
script: script:
- echo "Hello world" - echo "Hello world"
...@@ -1603,8 +1573,9 @@ module Gitlab ...@@ -1603,8 +1573,9 @@ module Gitlab
- paths: - paths:
- test/ - test/
YAML YAML
end
expect { described_class.new(config) }.to raise_error(described_class::ValidationError) it_behaves_like 'returns errors', 'jobs:test:artifacts config should be a hash'
end end
it 'populates a build options with complete artifacts configuration' do it 'populates a build options with complete artifacts configuration' do
...@@ -1672,8 +1643,9 @@ module Gitlab ...@@ -1672,8 +1643,9 @@ module Gitlab
} }
end end
let(:processor) { Gitlab::Ci::YamlProcessor.new(YAML.dump(config)) } subject { Gitlab::Ci::YamlProcessor.new(YAML.dump(config)) }
let(:builds) { processor.stage_builds_attributes('deploy') }
let(:builds) { subject.stage_builds_attributes('deploy') }
context 'when a production environment is specified' do context 'when a production environment is specified' do
let(:environment) { 'production' } let(:environment) { 'production' }
...@@ -1723,18 +1695,13 @@ module Gitlab ...@@ -1723,18 +1695,13 @@ module Gitlab
context 'is not a string' do context 'is not a string' do
let(:environment) { 1 } let(:environment) { 1 }
it 'raises error' do it_behaves_like 'returns errors', 'jobs:deploy_to_production:environment config should be a hash or a string'
expect { builds }.to raise_error(
'jobs:deploy_to_production:environment config should be a hash or a string')
end
end end
context 'is not a valid string' do context 'is not a valid string' do
let(:environment) { 'production:staging' } let(:environment) { 'production:staging' }
it 'raises error' do it_behaves_like 'returns errors', "jobs:deploy_to_production:environment name #{Gitlab::Regex.environment_name_regex_message}"
expect { builds }.to raise_error("jobs:deploy_to_production:environment name #{Gitlab::Regex.environment_name_regex_message}")
end
end end
context 'when on_stop is specified' do context 'when on_stop is specified' do
...@@ -1753,33 +1720,25 @@ module Gitlab ...@@ -1753,33 +1720,25 @@ module Gitlab
context 'without matching job' do context 'without matching job' do
let(:close_review) { nil } let(:close_review) { nil }
it 'raises error' do it_behaves_like 'returns errors', 'review job: on_stop job close_review is not defined'
expect { builds }.to raise_error('review job: on_stop job close_review is not defined')
end
end end
context 'with close job without environment' do context 'with close job without environment' do
let(:close_review) { { stage: 'deploy', script: 'test' } } let(:close_review) { { stage: 'deploy', script: 'test' } }
it 'raises error' do it_behaves_like 'returns errors', 'review job: on_stop job close_review does not have environment defined'
expect { builds }.to raise_error('review job: on_stop job close_review does not have environment defined')
end
end end
context 'with close job for different environment' do context 'with close job for different environment' do
let(:close_review) { { stage: 'deploy', script: 'test', environment: 'production' } } let(:close_review) { { stage: 'deploy', script: 'test', environment: 'production' } }
it 'raises error' do it_behaves_like 'returns errors', 'review job: on_stop job close_review have different environment name'
expect { builds }.to raise_error('review job: on_stop job close_review have different environment name')
end
end end
context 'with close job without stop action' do context 'with close job without stop action' do
let(:close_review) { { stage: 'deploy', script: 'test', environment: { name: 'review' } } } let(:close_review) { { stage: 'deploy', script: 'test', environment: { name: 'review' } } }
it 'raises error' do it_behaves_like 'returns errors', 'review job: on_stop job close_review needs to have action stop defined'
expect { builds }.to raise_error('review job: on_stop job close_review needs to have action stop defined')
end
end end
end end
end end
...@@ -1794,8 +1753,9 @@ module Gitlab ...@@ -1794,8 +1753,9 @@ module Gitlab
} }
end end
let(:processor) { Gitlab::Ci::YamlProcessor.new(YAML.dump(config)) } subject { Gitlab::Ci::YamlProcessor.new(YAML.dump(config)) }
let(:builds) { processor.stage_builds_attributes('deploy') }
let(:builds) { subject.stage_builds_attributes('deploy') }
context 'when no timeout was provided' do context 'when no timeout was provided' do
it 'does not include job_timeout' do it 'does not include job_timeout' do
...@@ -1809,9 +1769,7 @@ module Gitlab ...@@ -1809,9 +1769,7 @@ module Gitlab
config[:deploy_to_production][:timeout] = 'not-a-number' config[:deploy_to_production][:timeout] = 'not-a-number'
end end
it 'raises an error for invalid number' do it_behaves_like 'returns errors', 'jobs:deploy_to_production:timeout config should be a duration'
expect { builds }.to raise_error(Gitlab::Ci::YamlProcessor::ValidationError, 'jobs:deploy_to_production:timeout config should be a duration')
end
end end
context 'when some valid timeout was provided' do context 'when some valid timeout was provided' do
...@@ -1860,13 +1818,13 @@ module Gitlab ...@@ -1860,13 +1818,13 @@ module Gitlab
context 'undefined dependency' do context 'undefined dependency' do
let(:dependencies) { ['undefined'] } let(:dependencies) { ['undefined'] }
it { expect { subject }.to raise_error(Gitlab::Ci::YamlProcessor::ValidationError, 'test1 job: undefined dependency: undefined') } it_behaves_like 'returns errors', 'test1 job: undefined dependency: undefined'
end end
context 'dependencies to deploy' do context 'dependencies to deploy' do
let(:dependencies) { ['deploy'] } let(:dependencies) { ['deploy'] }
it { expect { subject }.to raise_error(Gitlab::Ci::YamlProcessor::ValidationError, 'test1 job: dependency deploy is not defined in prior stages') } it_behaves_like 'returns errors', 'test1 job: dependency deploy is not defined in prior stages'
end end
context 'when a job depends on another job that references a not-yet defined stage' do context 'when a job depends on another job that references a not-yet defined stage' do
...@@ -1891,7 +1849,7 @@ module Gitlab ...@@ -1891,7 +1849,7 @@ module Gitlab
} }
end end
it { expect { subject }.to raise_error(Gitlab::Ci::YamlProcessor::ValidationError, /is not defined in prior stages/) } it_behaves_like 'returns errors', /is not defined in prior stages/
end end
end end
...@@ -2053,20 +2011,20 @@ module Gitlab ...@@ -2053,20 +2011,20 @@ module Gitlab
context 'undefined need' do context 'undefined need' do
let(:needs) { ['undefined'] } let(:needs) { ['undefined'] }
it { expect { subject }.to raise_error(Gitlab::Ci::YamlProcessor::ValidationError, 'test1 job: undefined need: undefined') } it_behaves_like 'returns errors', 'test1 job: undefined need: undefined'
end end
context 'needs to deploy' do context 'needs to deploy' do
let(:needs) { ['deploy'] } let(:needs) { ['deploy'] }
it { expect { subject }.to raise_error(Gitlab::Ci::YamlProcessor::ValidationError, 'test1 job: need deploy is not defined in prior stages') } it_behaves_like 'returns errors', 'test1 job: need deploy is not defined in prior stages'
end end
context 'needs and dependencies that are mismatching' do context 'needs and dependencies that are mismatching' do
let(:needs) { %w(build1) } let(:needs) { %w(build1) }
let(:dependencies) { %w(build2) } let(:dependencies) { %w(build2) }
it { expect { subject }.to raise_error(Gitlab::Ci::YamlProcessor::ValidationError, 'jobs:test1 dependencies the build2 should be part of needs') } it_behaves_like 'returns errors', 'jobs:test1 dependencies the build2 should be part of needs'
end end
context 'needs with a Hash type and dependencies with a string type that are mismatching' do context 'needs with a Hash type and dependencies with a string type that are mismatching' do
...@@ -2079,28 +2037,28 @@ module Gitlab ...@@ -2079,28 +2037,28 @@ module Gitlab
let(:dependencies) { %w(build3) } let(:dependencies) { %w(build3) }
it { expect { subject }.to raise_error(Gitlab::Ci::YamlProcessor::ValidationError, 'jobs:test1 dependencies the build3 should be part of needs') } it_behaves_like 'returns errors', 'jobs:test1 dependencies the build3 should be part of needs'
end end
context 'needs with an array type and dependency with a string type' do context 'needs with an array type and dependency with a string type' do
let(:needs) { %w(build1) } let(:needs) { %w(build1) }
let(:dependencies) { 'deploy' } let(:dependencies) { 'deploy' }
it { expect { subject }.to raise_error(Gitlab::Ci::YamlProcessor::ValidationError, 'jobs:test1 dependencies should be an array of strings') } it_behaves_like 'returns errors', 'jobs:test1 dependencies should be an array of strings'
end end
context 'needs with a string type and dependency with an array type' do context 'needs with a string type and dependency with an array type' do
let(:needs) { 'build1' } let(:needs) { 'build1' }
let(:dependencies) { %w(deploy) } let(:dependencies) { %w(deploy) }
it { expect { subject }.to raise_error(Gitlab::Ci::YamlProcessor::ValidationError, 'jobs:test1:needs config can only be a hash or an array') } it_behaves_like 'returns errors', 'jobs:test1:needs config can only be a hash or an array'
end end
context 'needs with a Hash type and dependency with a string type' do context 'needs with a Hash type and dependency with a string type' do
let(:needs) { { job: 'build1' } } let(:needs) { { job: 'build1' } }
let(:dependencies) { 'deploy' } let(:dependencies) { 'deploy' }
it { expect { subject }.to raise_error(Gitlab::Ci::YamlProcessor::ValidationError, 'jobs:test1 dependencies should be an array of strings') } it_behaves_like 'returns errors', 'jobs:test1 dependencies should be an array of strings'
end end
end end
...@@ -2141,9 +2099,7 @@ module Gitlab ...@@ -2141,9 +2099,7 @@ module Gitlab
} }
end end
it 'raises a ValidationError' do it_behaves_like 'returns errors', /may not be used with `rules`: when/
expect { subject }.to raise_error(YamlProcessor::ValidationError, /may not be used with `rules`: when/)
end
end end
context 'used with job-level when:delayed' do context 'used with job-level when:delayed' do
...@@ -2159,9 +2115,7 @@ module Gitlab ...@@ -2159,9 +2115,7 @@ module Gitlab
} }
end end
it 'raises a ValidationError' do it_behaves_like 'returns errors', /may not be used with `rules`: when, start_in/
expect { subject }.to raise_error(YamlProcessor::ValidationError, /may not be used with `rules`: when, start_in/)
end
end end
end end
...@@ -2348,371 +2302,318 @@ module Gitlab ...@@ -2348,371 +2302,318 @@ module Gitlab
end end
describe "Error handling" do describe "Error handling" do
it "fails to parse YAML" do subject { described_class.new(config) }
expect do
Gitlab::Ci::YamlProcessor.new("invalid: yaml: test") context 'when YAML syntax is invalid' do
end.to raise_error(Gitlab::Ci::YamlProcessor::ValidationError) let(:config) { 'invalid: yaml: test' }
it_behaves_like 'returns errors', /mapping values are not allowed/
end end
it "indicates that object is invalid" do context 'when object is invalid' do
expect do let(:config) { 'invalid_yaml' }
Gitlab::Ci::YamlProcessor.new("invalid_yaml")
end.to raise_error(Gitlab::Ci::YamlProcessor::ValidationError) it_behaves_like 'returns errors', /Invalid configuration format/
end end
it "returns errors if tags parameter is invalid" do context 'returns errors if tags parameter is invalid' do
config = YAML.dump({ rspec: { script: "test", tags: "mysql" } }) let(:config) { YAML.dump({ rspec: { script: "test", tags: "mysql" } }) }
expect do
Gitlab::Ci::YamlProcessor.new(config) it_behaves_like 'returns errors', 'jobs:rspec:tags config should be an array of strings'
end.to raise_error(Gitlab::Ci::YamlProcessor::ValidationError, "jobs:rspec:tags config should be an array of strings")
end end
it "returns errors if before_script parameter is invalid" do context 'returns errors if before_script parameter is invalid' do
config = YAML.dump({ before_script: "bundle update", rspec: { script: "test" } }) let(:config) { YAML.dump({ before_script: "bundle update", rspec: { script: "test" } }) }
expect do
Gitlab::Ci::YamlProcessor.new(config) it_behaves_like 'returns errors', 'before_script config should be an array containing strings and arrays of strings'
end.to raise_error(Gitlab::Ci::YamlProcessor::ValidationError, "before_script config should be an array containing strings and arrays of strings")
end end
it "returns errors if job before_script parameter is not an array of strings" do context 'returns errors if job before_script parameter is not an array of strings' do
config = YAML.dump({ rspec: { script: "test", before_script: [10, "test"] } }) let(:config) { YAML.dump({ rspec: { script: "test", before_script: [10, "test"] } }) }
expect do
Gitlab::Ci::YamlProcessor.new(config) it_behaves_like 'returns errors', 'jobs:rspec:before_script config should be an array containing strings and arrays of strings'
end.to raise_error(Gitlab::Ci::YamlProcessor::ValidationError, "jobs:rspec:before_script config should be an array containing strings and arrays of strings")
end end
it "returns errors if job before_script parameter is multi-level nested array of strings" do context '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"] } }) let(:config) { YAML.dump({ rspec: { script: "test", before_script: [["ls", ["pwd"]], "test"] } }) }
expect do
Gitlab::Ci::YamlProcessor.new(config) it_behaves_like 'returns errors', 'jobs:rspec:before_script config should be an array containing strings and arrays of strings'
end.to raise_error(Gitlab::Ci::YamlProcessor::ValidationError, "jobs:rspec:before_script config should be an array containing strings and arrays of strings")
end end
it "returns errors if after_script parameter is invalid" do context 'returns errors if after_script parameter is invalid' do
config = YAML.dump({ after_script: "bundle update", rspec: { script: "test" } }) let(:config) { YAML.dump({ after_script: "bundle update", rspec: { script: "test" } }) }
expect do
Gitlab::Ci::YamlProcessor.new(config) it_behaves_like 'returns errors', 'after_script config should be an array containing strings and arrays of strings'
end.to raise_error(Gitlab::Ci::YamlProcessor::ValidationError, "after_script config should be an array containing strings and arrays of strings")
end end
it "returns errors if job after_script parameter is not an array of strings" do context 'returns errors if job after_script parameter is not an array of strings' do
config = YAML.dump({ rspec: { script: "test", after_script: [10, "test"] } }) let(:config) { YAML.dump({ rspec: { script: "test", after_script: [10, "test"] } }) }
expect do
Gitlab::Ci::YamlProcessor.new(config) it_behaves_like 'returns errors', 'jobs:rspec:after_script config should be an array containing strings and arrays of strings'
end.to raise_error(Gitlab::Ci::YamlProcessor::ValidationError, "jobs:rspec:after_script config should be an array containing strings and arrays of strings")
end end
it "returns errors if job after_script parameter is multi-level nested array of strings" do context '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"] } }) let(:config) { YAML.dump({ rspec: { script: "test", after_script: [["ls", ["pwd"]], "test"] } }) }
expect do
Gitlab::Ci::YamlProcessor.new(config) it_behaves_like 'returns errors', 'jobs:rspec:after_script config should be an array containing strings and arrays of strings'
end.to raise_error(Gitlab::Ci::YamlProcessor::ValidationError, "jobs:rspec:after_script config should be an array containing strings and arrays of strings")
end end
it "returns errors if image parameter is invalid" do context 'returns errors if image parameter is invalid' do
config = YAML.dump({ image: ["test"], rspec: { script: "test" } }) let(:config) { YAML.dump({ image: ["test"], rspec: { script: "test" } }) }
expect do
Gitlab::Ci::YamlProcessor.new(config) it_behaves_like 'returns errors', 'image config should be a hash or a string'
end.to raise_error(Gitlab::Ci::YamlProcessor::ValidationError, "image config should be a hash or a string")
end end
it "returns errors if job name is blank" do context 'returns errors if job name is blank' do
config = YAML.dump({ '' => { script: "test" } }) let(:config) { YAML.dump({ '' => { script: "test" } }) }
expect do
Gitlab::Ci::YamlProcessor.new(config) it_behaves_like 'returns errors', "jobs:job name can't be blank"
end.to raise_error(Gitlab::Ci::YamlProcessor::ValidationError, "jobs:job name can't be blank")
end end
it "returns errors if job name is non-string" do context 'returns errors if job name is non-string' do
config = YAML.dump({ 10 => { script: "test" } }) let(:config) { YAML.dump({ 10 => { script: "test" } }) }
expect do
Gitlab::Ci::YamlProcessor.new(config) it_behaves_like 'returns errors', 'jobs:10 name should be a symbol'
end.to raise_error(Gitlab::Ci::YamlProcessor::ValidationError, "jobs:10 name should be a symbol")
end end
it "returns errors if job image parameter is invalid" do context 'returns errors if job image parameter is invalid' do
config = YAML.dump({ rspec: { script: "test", image: ["test"] } }) let(:config) { YAML.dump({ rspec: { script: "test", image: ["test"] } }) }
expect do
Gitlab::Ci::YamlProcessor.new(config) it_behaves_like 'returns errors', 'jobs:rspec:image config should be a hash or a string'
end.to raise_error(Gitlab::Ci::YamlProcessor::ValidationError, "jobs:rspec:image config should be a hash or a string")
end end
it "returns errors if services parameter is not an array" do context 'returns errors if services parameter is not an array' do
config = YAML.dump({ services: "test", rspec: { script: "test" } }) let(:config) { YAML.dump({ services: "test", rspec: { script: "test" } }) }
expect do
Gitlab::Ci::YamlProcessor.new(config) it_behaves_like 'returns errors', 'services config should be a array'
end.to raise_error(Gitlab::Ci::YamlProcessor::ValidationError, "services config should be a array")
end end
it "returns errors if services parameter is not an array of strings" do context 'returns errors if services parameter is not an array of strings' do
config = YAML.dump({ services: [10, "test"], rspec: { script: "test" } }) let(:config) { YAML.dump({ services: [10, "test"], rspec: { script: "test" } }) }
expect do
Gitlab::Ci::YamlProcessor.new(config) it_behaves_like 'returns errors', 'services:service config should be a hash or a string'
end.to raise_error(Gitlab::Ci::YamlProcessor::ValidationError, "services:service config should be a hash or a string")
end end
it "returns errors if job services parameter is not an array" do context 'returns errors if job services parameter is not an array' do
config = YAML.dump({ rspec: { script: "test", services: "test" } }) let(:config) { YAML.dump({ rspec: { script: "test", services: "test" } }) }
expect do
Gitlab::Ci::YamlProcessor.new(config) it_behaves_like 'returns errors', 'jobs:rspec:services config should be a array'
end.to raise_error(Gitlab::Ci::YamlProcessor::ValidationError, "jobs:rspec:services config should be a array")
end end
it "returns errors if job services parameter is not an array of strings" do context 'returns errors if job services parameter is not an array of strings' do
config = YAML.dump({ rspec: { script: "test", services: [10, "test"] } }) let(:config) { YAML.dump({ rspec: { script: "test", services: [10, "test"] } }) }
expect do
Gitlab::Ci::YamlProcessor.new(config) it_behaves_like 'returns errors', 'jobs:rspec:services:service config should be a hash or a string'
end.to raise_error(Gitlab::Ci::YamlProcessor::ValidationError, "jobs:rspec:services:service config should be a hash or a string")
end end
it "returns error if job configuration is invalid" do context 'returns error if job configuration is invalid' do
config = YAML.dump({ extra: "bundle update" }) let(:config) { YAML.dump({ extra: "bundle update" }) }
expect do
Gitlab::Ci::YamlProcessor.new(config) it_behaves_like 'returns errors', 'root config contains unknown keys: extra'
end.to raise_error(Gitlab::Ci::YamlProcessor::ValidationError, "root config contains unknown keys: extra")
end end
it "returns errors if services configuration is not correct" do context 'returns errors if services configuration is not correct' do
config = YAML.dump({ extra: { script: 'rspec', services: "test" } }) let(:config) { YAML.dump({ extra: { script: 'rspec', services: "test" } }) }
expect do
Gitlab::Ci::YamlProcessor.new(config) it_behaves_like 'returns errors', 'jobs:extra:services config should be a array'
end.to raise_error(Gitlab::Ci::YamlProcessor::ValidationError, "jobs:extra:services config should be a array")
end end
it "returns errors if there are no jobs defined" do context 'returns errors if there are no jobs defined' do
config = YAML.dump({ before_script: ["bundle update"] }) let(:config) { YAML.dump({ before_script: ["bundle update"] }) }
expect do
Gitlab::Ci::YamlProcessor.new(config) it_behaves_like 'returns errors', 'jobs config should contain at least one visible job'
end.to raise_error(Gitlab::Ci::YamlProcessor::ValidationError, "jobs config should contain at least one visible job")
end end
it "returns errors if the job script is not defined" do context 'returns errors if the job script is not defined' do
config = YAML.dump({ rspec: { before_script: "test" } }) let(:config) { YAML.dump({ rspec: { before_script: "test" } }) }
expect do it_behaves_like 'returns errors', "jobs:rspec script can't be blank"
Gitlab::Ci::YamlProcessor.new(config)
end.to raise_error(Gitlab::Ci::YamlProcessor::ValidationError, "jobs:rspec script can't be blank")
end end
it "returns errors if there are no visible jobs defined" do context 'returns errors if there are no visible jobs defined' do
config = YAML.dump({ before_script: ["bundle update"], '.hidden'.to_sym => { script: 'ls' } }) let(:config) { YAML.dump({ before_script: ["bundle update"], '.hidden'.to_sym => { script: 'ls' } }) }
expect do
Gitlab::Ci::YamlProcessor.new(config) it_behaves_like 'returns errors', 'jobs config should contain at least one visible job'
end.to raise_error(Gitlab::Ci::YamlProcessor::ValidationError, "jobs config should contain at least one visible job")
end end
it "returns errors if job allow_failure parameter is not an boolean" do context 'returns errors if job allow_failure parameter is not an boolean' do
config = YAML.dump({ rspec: { script: "test", allow_failure: "string" } }) let(:config) { YAML.dump({ rspec: { script: "test", allow_failure: "string" } }) }
expect do
Gitlab::Ci::YamlProcessor.new(config) it_behaves_like 'returns errors', 'jobs:rspec allow failure should be a boolean value'
end.to raise_error(Gitlab::Ci::YamlProcessor::ValidationError, "jobs:rspec allow failure should be a boolean value")
end end
it "returns errors if job stage is not a string" do context 'returns errors if job stage is not a string' do
config = YAML.dump({ rspec: { script: "test", type: 1 } }) let(:config) { YAML.dump({ rspec: { script: "test", type: 1 } }) }
expect do
Gitlab::Ci::YamlProcessor.new(config) it_behaves_like 'returns errors', 'jobs:rspec:type config should be a string'
end.to raise_error(Gitlab::Ci::YamlProcessor::ValidationError, "jobs:rspec:type config should be a string")
end end
it "returns errors if job stage is not a pre-defined stage" do context 'returns errors if job stage is not a pre-defined stage' do
config = YAML.dump({ rspec: { script: "test", type: "acceptance" } }) let(:config) { YAML.dump({ rspec: { script: "test", type: "acceptance" } }) }
expect do
Gitlab::Ci::YamlProcessor.new(config) it_behaves_like 'returns errors', 'rspec job: chosen stage does not exist; available stages are .pre, build, test, deploy, .post'
end.to raise_error(Gitlab::Ci::YamlProcessor::ValidationError, "rspec job: chosen stage does not exist; available stages are .pre, build, test, deploy, .post")
end end
it "returns errors if job stage is not a defined stage" do context 'returns errors if job stage is not a defined stage' do
config = YAML.dump({ types: %w(build test), rspec: { script: "test", type: "acceptance" } }) let(:config) { YAML.dump({ types: %w(build test), rspec: { script: "test", type: "acceptance" } }) }
expect do
Gitlab::Ci::YamlProcessor.new(config) it_behaves_like 'returns errors', 'rspec job: chosen stage does not exist; available stages are .pre, build, test, .post'
end.to raise_error(Gitlab::Ci::YamlProcessor::ValidationError, "rspec job: chosen stage does not exist; available stages are .pre, build, test, .post")
end end
it "returns errors if stages is not an array" do context 'returns errors if stages is not an array' do
config = YAML.dump({ stages: "test", rspec: { script: "test" } }) let(:config) { YAML.dump({ stages: "test", rspec: { script: "test" } }) }
expect do
Gitlab::Ci::YamlProcessor.new(config) it_behaves_like 'returns errors', 'stages config should be an array of strings'
end.to raise_error(Gitlab::Ci::YamlProcessor::ValidationError, "stages config should be an array of strings")
end end
it "returns errors if stages is not an array of strings" do context 'returns errors if stages is not an array of strings' do
config = YAML.dump({ stages: [true, "test"], rspec: { script: "test" } }) let(:config) { YAML.dump({ stages: [true, "test"], rspec: { script: "test" } }) }
expect do
Gitlab::Ci::YamlProcessor.new(config) it_behaves_like 'returns errors', 'stages config should be an array of strings'
end.to raise_error(Gitlab::Ci::YamlProcessor::ValidationError, "stages config should be an array of strings")
end end
it "returns errors if variables is not a map" do context 'returns errors if variables is not a map' do
config = YAML.dump({ variables: "test", rspec: { script: "test" } }) let(:config) { YAML.dump({ variables: "test", rspec: { script: "test" } }) }
expect do
Gitlab::Ci::YamlProcessor.new(config) it_behaves_like 'returns errors', 'variables config should be a hash of key value pairs'
end.to raise_error(Gitlab::Ci::YamlProcessor::ValidationError, "variables config should be a hash of key value pairs")
end end
it "returns errors if variables is not a map of key-value strings" do context 'returns errors if variables is not a map of key-value strings' do
config = YAML.dump({ variables: { test: false }, rspec: { script: "test" } }) let(:config) { YAML.dump({ variables: { test: false }, rspec: { script: "test" } }) }
expect do
Gitlab::Ci::YamlProcessor.new(config) it_behaves_like 'returns errors', 'variables config should be a hash of key value pairs'
end.to raise_error(Gitlab::Ci::YamlProcessor::ValidationError, "variables config should be a hash of key value pairs")
end end
it "returns errors if job when is not on_success, on_failure or always" do context 'returns errors if job when is not on_success, on_failure or always' do
config = YAML.dump({ rspec: { script: "test", when: 1 } }) let(:config) { YAML.dump({ rspec: { script: "test", when: 1 } }) }
expect do
Gitlab::Ci::YamlProcessor.new(config) it_behaves_like 'returns errors', "jobs:rspec when should be one of: #{Gitlab::Ci::Config::Entry::Job::ALLOWED_WHEN.join(', ')}"
end.to raise_error(Gitlab::Ci::YamlProcessor::ValidationError, "jobs:rspec when should be one of: #{Gitlab::Ci::Config::Entry::Job::ALLOWED_WHEN.join(', ')}")
end end
it "returns errors if job artifacts:name is not an a string" do context 'returns errors if job artifacts:name is not an a string' do
config = YAML.dump({ types: %w(build test), rspec: { script: "test", artifacts: { name: 1 } } }) let(:config) { YAML.dump({ types: %w(build test), rspec: { script: "test", artifacts: { name: 1 } } }) }
expect do
Gitlab::Ci::YamlProcessor.new(config) it_behaves_like 'returns errors', 'jobs:rspec:artifacts name should be a string'
end.to raise_error(Gitlab::Ci::YamlProcessor::ValidationError, "jobs:rspec:artifacts name should be a string")
end end
it "returns errors if job artifacts:when is not an a predefined value" do context 'returns errors if job artifacts:when is not an a predefined value' do
config = YAML.dump({ types: %w(build test), rspec: { script: "test", artifacts: { when: 1 } } }) let(:config) { YAML.dump({ types: %w(build test), rspec: { script: "test", artifacts: { when: 1 } } }) }
expect do
Gitlab::Ci::YamlProcessor.new(config) it_behaves_like 'returns errors', 'jobs:rspec:artifacts when should be on_success, on_failure or always'
end.to raise_error(Gitlab::Ci::YamlProcessor::ValidationError, "jobs:rspec:artifacts when should be on_success, on_failure or always")
end end
it "returns errors if job artifacts:expire_in is not an a string" do context 'returns errors if job artifacts:expire_in is not an a string' do
config = YAML.dump({ types: %w(build test), rspec: { script: "test", artifacts: { expire_in: 1 } } }) let(:config) { YAML.dump({ types: %w(build test), rspec: { script: "test", artifacts: { expire_in: 1 } } }) }
expect do
Gitlab::Ci::YamlProcessor.new(config) it_behaves_like 'returns errors', 'jobs:rspec:artifacts expire in should be a duration'
end.to raise_error(Gitlab::Ci::YamlProcessor::ValidationError, "jobs:rspec:artifacts expire in should be a duration")
end end
it "returns errors if job artifacts:expire_in is not an a valid duration" do context 'returns errors if job artifacts:expire_in is not an a valid duration' do
config = YAML.dump({ types: %w(build test), rspec: { script: "test", artifacts: { expire_in: "7 elephants" } } }) let(:config) { YAML.dump({ types: %w(build test), rspec: { script: "test", artifacts: { expire_in: "7 elephants" } } }) }
expect do
Gitlab::Ci::YamlProcessor.new(config) it_behaves_like 'returns errors', 'jobs:rspec:artifacts expire in should be a duration'
end.to raise_error(Gitlab::Ci::YamlProcessor::ValidationError, "jobs:rspec:artifacts expire in should be a duration")
end end
it "returns errors if job artifacts:untracked is not an array of strings" do context 'returns errors if job artifacts:untracked is not an array of strings' do
config = YAML.dump({ types: %w(build test), rspec: { script: "test", artifacts: { untracked: "string" } } }) let(:config) { YAML.dump({ types: %w(build test), rspec: { script: "test", artifacts: { untracked: "string" } } }) }
expect do
Gitlab::Ci::YamlProcessor.new(config) it_behaves_like 'returns errors', 'jobs:rspec:artifacts untracked should be a boolean value'
end.to raise_error(Gitlab::Ci::YamlProcessor::ValidationError, "jobs:rspec:artifacts untracked should be a boolean value")
end end
it "returns errors if job artifacts:paths is not an array of strings" do context 'returns errors if job artifacts:paths is not an array of strings' do
config = YAML.dump({ types: %w(build test), rspec: { script: "test", artifacts: { paths: "string" } } }) let(:config) { YAML.dump({ types: %w(build test), rspec: { script: "test", artifacts: { paths: "string" } } }) }
expect do
Gitlab::Ci::YamlProcessor.new(config) it_behaves_like 'returns errors', 'jobs:rspec:artifacts paths should be an array of strings'
end.to raise_error(Gitlab::Ci::YamlProcessor::ValidationError, "jobs:rspec:artifacts paths should be an array of strings")
end end
it "returns errors if cache:untracked is not an array of strings" do context 'returns errors if cache:untracked is not an array of strings' do
config = YAML.dump({ cache: { untracked: "string" }, rspec: { script: "test" } }) let(:config) { YAML.dump({ cache: { untracked: "string" }, rspec: { script: "test" } }) }
expect do
Gitlab::Ci::YamlProcessor.new(config) it_behaves_like 'returns errors', 'cache:untracked config should be a boolean value'
end.to raise_error(Gitlab::Ci::YamlProcessor::ValidationError, "cache:untracked config should be a boolean value")
end end
it "returns errors if cache:paths is not an array of strings" do context 'returns errors if cache:paths is not an array of strings' do
config = YAML.dump({ cache: { paths: "string" }, rspec: { script: "test" } }) let(:config) { YAML.dump({ cache: { paths: "string" }, rspec: { script: "test" } }) }
expect do
Gitlab::Ci::YamlProcessor.new(config) it_behaves_like 'returns errors', 'cache:paths config should be an array of strings'
end.to raise_error(Gitlab::Ci::YamlProcessor::ValidationError, "cache:paths config should be an array of strings")
end end
it "returns errors if cache:key is not a string" do context 'returns errors if cache:key is not a string' do
config = YAML.dump({ cache: { key: 1 }, rspec: { script: "test" } }) let(:config) { YAML.dump({ cache: { key: 1 }, rspec: { script: "test" } }) }
expect do
Gitlab::Ci::YamlProcessor.new(config) it_behaves_like 'returns errors', "cache:key should be a hash, a string or a symbol"
end.to raise_error(Gitlab::Ci::YamlProcessor::ValidationError, "cache:key should be a hash, a string or a symbol")
end end
it "returns errors if job cache:key is not an a string" do context 'returns errors if job cache:key is not an a string' do
config = YAML.dump({ types: %w(build test), rspec: { script: "test", cache: { key: 1 } } }) let(:config) { YAML.dump({ types: %w(build test), rspec: { script: "test", cache: { key: 1 } } }) }
expect do
Gitlab::Ci::YamlProcessor.new(config) it_behaves_like 'returns errors', "jobs:rspec:cache:key should be a hash, a string or a symbol"
end.to raise_error(Gitlab::Ci::YamlProcessor::ValidationError, "jobs:rspec:cache:key should be a hash, a string or a symbol")
end end
it 'returns errors if job cache:key:files is not an array of strings' do context 'returns errors if job cache:key:files is not an array of strings' do
config = YAML.dump({ types: %w(build test), rspec: { script: "test", cache: { key: { files: [1] } } } }) let(:config) { YAML.dump({ types: %w(build test), rspec: { script: "test", cache: { key: { files: [1] } } } }) }
expect do
Gitlab::Ci::YamlProcessor.new(config) it_behaves_like 'returns errors', 'jobs:rspec:cache:key:files config should be an array of strings'
end.to raise_error(Gitlab::Ci::YamlProcessor::ValidationError, 'jobs:rspec:cache:key:files config should be an array of strings')
end end
it 'returns errors if job cache:key:files is an empty array' do context 'returns errors if job cache:key:files is an empty array' do
config = YAML.dump({ types: %w(build test), rspec: { script: "test", cache: { key: { files: [] } } } }) let(:config) { YAML.dump({ types: %w(build test), rspec: { script: "test", cache: { key: { files: [] } } } }) }
expect do
Gitlab::Ci::YamlProcessor.new(config) it_behaves_like 'returns errors', 'jobs:rspec:cache:key:files config requires at least 1 item'
end.to raise_error(Gitlab::Ci::YamlProcessor::ValidationError, 'jobs:rspec:cache:key:files config requires at least 1 item')
end end
it 'returns errors if job defines only cache:key:prefix' do context 'returns errors if job defines only cache:key:prefix' do
config = YAML.dump({ types: %w(build test), rspec: { script: "test", cache: { key: { prefix: 'prefix-key' } } } }) let(:config) { YAML.dump({ types: %w(build test), rspec: { script: "test", cache: { key: { prefix: 'prefix-key' } } } }) }
expect do
Gitlab::Ci::YamlProcessor.new(config) it_behaves_like 'returns errors', 'jobs:rspec:cache:key config missing required keys: files'
end.to raise_error(Gitlab::Ci::YamlProcessor::ValidationError, 'jobs:rspec:cache:key config missing required keys: files')
end end
it 'returns errors if job cache:key:prefix is not an a string' do context 'returns errors if job cache:key:prefix is not an a string' do
config = YAML.dump({ types: %w(build test), rspec: { script: "test", cache: { key: { prefix: 1, files: ['file'] } } } }) let(:config) { YAML.dump({ types: %w(build test), rspec: { script: "test", cache: { key: { prefix: 1, files: ['file'] } } } }) }
expect do
Gitlab::Ci::YamlProcessor.new(config) it_behaves_like 'returns errors', 'jobs:rspec:cache:key:prefix config should be a string or symbol'
end.to raise_error(Gitlab::Ci::YamlProcessor::ValidationError, 'jobs:rspec:cache:key:prefix config should be a string or symbol')
end end
it "returns errors if job cache:untracked is not an array of strings" do context "returns errors if job cache:untracked is not an array of strings" do
config = YAML.dump({ types: %w(build test), rspec: { script: "test", cache: { untracked: "string" } } }) let(:config) { YAML.dump({ types: %w(build test), rspec: { script: "test", cache: { untracked: "string" } } }) }
expect do
Gitlab::Ci::YamlProcessor.new(config) it_behaves_like 'returns errors', "jobs:rspec:cache:untracked config should be a boolean value"
end.to raise_error(Gitlab::Ci::YamlProcessor::ValidationError, "jobs:rspec:cache:untracked config should be a boolean value")
end end
it "returns errors if job cache:paths is not an array of strings" do context "returns errors if job cache:paths is not an array of strings" do
config = YAML.dump({ types: %w(build test), rspec: { script: "test", cache: { paths: "string" } } }) let(:config) { YAML.dump({ types: %w(build test), rspec: { script: "test", cache: { paths: "string" } } }) }
expect do
Gitlab::Ci::YamlProcessor.new(config) it_behaves_like 'returns errors', "jobs:rspec:cache:paths config should be an array of strings"
end.to raise_error(Gitlab::Ci::YamlProcessor::ValidationError, "jobs:rspec:cache:paths config should be an array of strings")
end end
it "returns errors if job dependencies is not an array of strings" do context "returns errors if job dependencies is not an array of strings" do
config = YAML.dump({ types: %w(build test), rspec: { script: "test", dependencies: "string" } }) let(:config) { YAML.dump({ types: %w(build test), rspec: { script: "test", dependencies: "string" } }) }
expect do
Gitlab::Ci::YamlProcessor.new(config) it_behaves_like 'returns errors', "jobs:rspec dependencies should be an array of strings"
end.to raise_error(Gitlab::Ci::YamlProcessor::ValidationError, "jobs:rspec dependencies should be an array of strings")
end end
it 'returns errors if pipeline variables expression policy is invalid' do context 'returns errors if pipeline variables expression policy is invalid' do
config = YAML.dump({ rspec: { script: 'test', only: { variables: ['== null'] } } }) let(:config) { YAML.dump({ rspec: { script: 'test', only: { variables: ['== null'] } } }) }
expect { Gitlab::Ci::YamlProcessor.new(config) } it_behaves_like 'returns errors', 'jobs:rspec:only variables invalid expression syntax'
.to raise_error(Gitlab::Ci::YamlProcessor::ValidationError,
'jobs:rspec:only variables invalid expression syntax')
end end
it 'returns errors if pipeline changes policy is invalid' do context 'returns errors if pipeline changes policy is invalid' do
config = YAML.dump({ rspec: { script: 'test', only: { changes: [1] } } }) let(:config) { YAML.dump({ rspec: { script: 'test', only: { changes: [1] } } }) }
expect { Gitlab::Ci::YamlProcessor.new(config) } it_behaves_like 'returns errors', 'jobs:rspec:only changes should be an array of strings'
.to raise_error(Gitlab::Ci::YamlProcessor::ValidationError,
'jobs:rspec:only changes should be an array of strings')
end end
it 'returns errors if extended hash configuration is invalid' do context 'returns errors if extended hash configuration is invalid' do
config = YAML.dump({ rspec: { extends: 'something', script: 'test' } }) let(:config) { YAML.dump({ rspec: { extends: 'something', script: 'test' } }) }
expect { Gitlab::Ci::YamlProcessor.new(config) } it_behaves_like 'returns errors', 'rspec: unknown keys in `extends` (something)'
.to raise_error(Gitlab::Ci::YamlProcessor::ValidationError,
'rspec: unknown keys in `extends` (something)')
end end
it 'returns errors if parallel is invalid' do context 'returns errors if parallel is invalid' do
config = YAML.dump({ rspec: { parallel: 'test', script: 'test' } }) let(:config) { YAML.dump({ rspec: { parallel: 'test', script: 'test' } }) }
expect { Gitlab::Ci::YamlProcessor.new(config) } it_behaves_like 'returns errors', 'jobs:rspec:parallel should be an integer or a hash'
.to raise_error(Gitlab::Ci::YamlProcessor::ValidationError,
'jobs:rspec:parallel should be an integer or a hash')
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