Commit f4421817 authored by Grzegorz Bizon's avatar Grzegorz Bizon

Add global cache config entry to new CI config

parent 92312786
...@@ -27,7 +27,8 @@ module Gitlab ...@@ -27,7 +27,8 @@ module Gitlab
def keys def keys
if unknown_keys.any? if unknown_keys.any?
errors.add(:config, "contains unknown keys #{unknown_keys}") unknown_list = unknown_keys.join(', ')
errors.add(:config, "contains unknown keys: #{unknown_list}")
end end
end end
end end
......
...@@ -26,7 +26,10 @@ module Gitlab ...@@ -26,7 +26,10 @@ module Gitlab
private private
def create_node(key, factory) def create_node(key, factory)
factory.with(value: @config[key], key: key) factory.with(value: @config[key])
factory.with(parent: self)
factory.with(key: key)
factory.create! factory.create!
end end
......
...@@ -34,6 +34,10 @@ module Gitlab ...@@ -34,6 +34,10 @@ module Gitlab
self.class.nodes.none? self.class.nodes.none?
end end
def ancestors
@parent ? @parent.ancestors + [@parent] : []
end
def valid? def valid?
errors.none? errors.none?
end end
......
...@@ -30,8 +30,11 @@ module Gitlab ...@@ -30,8 +30,11 @@ module Gitlab
node :types, Stages, node :types, Stages,
description: 'Stages for this pipeline (deprecated key).' description: 'Stages for this pipeline (deprecated key).'
helpers :before_script, :image, :services, :after_script, :variables, node :cache, Cache,
:stages, :types description: 'Configure caching between build jobs.'
helpers :before_script, :image, :services, :after_script,
:variables, :stages, :types, :cache
def stages def stages
stages_defined? ? stages_value : types_value stages_defined? ? stages_value : types_value
......
...@@ -13,7 +13,7 @@ module Gitlab ...@@ -13,7 +13,7 @@ module Gitlab
def messages def messages
errors.full_messages.map do |error| errors.full_messages.map do |error|
"#{location} #{error}".humanize "#{location} #{error}".downcase
end end
end end
...@@ -24,7 +24,9 @@ module Gitlab ...@@ -24,7 +24,9 @@ module Gitlab
private private
def location def location
key || @node.class.name.demodulize.underscore predecessors = ancestors.map(&:key).compact
current = key || @node.class.name.demodulize.underscore
predecessors.append(current).join(':')
end end
end end
end end
......
...@@ -600,7 +600,7 @@ module Ci ...@@ -600,7 +600,7 @@ module Ci
expect { GitlabCiYamlProcessor.new(config) }.to raise_error( expect { GitlabCiYamlProcessor.new(config) }.to raise_error(
GitlabCiYamlProcessor::ValidationError, GitlabCiYamlProcessor::ValidationError,
'Cache config has unknown parameter: invalid' 'cache config contains unknown keys: invalid'
) )
end end
end end
...@@ -964,7 +964,7 @@ EOT ...@@ -964,7 +964,7 @@ EOT
config = YAML.dump({ before_script: "bundle update", rspec: { script: "test" } }) config = YAML.dump({ before_script: "bundle update", rspec: { script: "test" } })
expect do expect do
GitlabCiYamlProcessor.new(config, path) GitlabCiYamlProcessor.new(config, path)
end.to raise_error(GitlabCiYamlProcessor::ValidationError, "Before script config should be an array of strings") end.to raise_error(GitlabCiYamlProcessor::ValidationError, "before_script config should be an array of strings")
end end
it "returns errors if job before_script parameter is not an array of strings" do it "returns errors if job before_script parameter is not an array of strings" do
...@@ -978,7 +978,7 @@ EOT ...@@ -978,7 +978,7 @@ EOT
config = YAML.dump({ after_script: "bundle update", rspec: { script: "test" } }) config = YAML.dump({ after_script: "bundle update", rspec: { script: "test" } })
expect do expect do
GitlabCiYamlProcessor.new(config, path) GitlabCiYamlProcessor.new(config, path)
end.to raise_error(GitlabCiYamlProcessor::ValidationError, "After script config should be an array of strings") end.to raise_error(GitlabCiYamlProcessor::ValidationError, "after_script config should be an array of strings")
end end
it "returns errors if job after_script parameter is not an array of strings" do it "returns errors if job after_script parameter is not an array of strings" do
...@@ -992,7 +992,7 @@ EOT ...@@ -992,7 +992,7 @@ EOT
config = YAML.dump({ image: ["test"], rspec: { script: "test" } }) config = YAML.dump({ image: ["test"], rspec: { script: "test" } })
expect do expect do
GitlabCiYamlProcessor.new(config, path) GitlabCiYamlProcessor.new(config, path)
end.to raise_error(GitlabCiYamlProcessor::ValidationError, "Image config should be a string") end.to raise_error(GitlabCiYamlProcessor::ValidationError, "image config should be a string")
end end
it "returns errors if job name is blank" do it "returns errors if job name is blank" do
...@@ -1020,14 +1020,14 @@ EOT ...@@ -1020,14 +1020,14 @@ EOT
config = YAML.dump({ services: "test", rspec: { script: "test" } }) config = YAML.dump({ services: "test", rspec: { script: "test" } })
expect do expect do
GitlabCiYamlProcessor.new(config, path) GitlabCiYamlProcessor.new(config, path)
end.to raise_error(GitlabCiYamlProcessor::ValidationError, "Services config should be an array of strings") end.to raise_error(GitlabCiYamlProcessor::ValidationError, "services config should be an array of strings")
end end
it "returns errors if services parameter is not an array of strings" do it "returns errors if services parameter is not an array of strings" do
config = YAML.dump({ services: [10, "test"], rspec: { script: "test" } }) config = YAML.dump({ services: [10, "test"], rspec: { script: "test" } })
expect do expect do
GitlabCiYamlProcessor.new(config, path) GitlabCiYamlProcessor.new(config, path)
end.to raise_error(GitlabCiYamlProcessor::ValidationError, "Services config should be an array of strings") end.to raise_error(GitlabCiYamlProcessor::ValidationError, "services config should be an array of strings")
end end
it "returns errors if job services parameter is not an array" do it "returns errors if job services parameter is not an array" do
...@@ -1097,28 +1097,28 @@ EOT ...@@ -1097,28 +1097,28 @@ EOT
config = YAML.dump({ stages: "test", rspec: { script: "test" } }) config = YAML.dump({ stages: "test", rspec: { script: "test" } })
expect do expect do
GitlabCiYamlProcessor.new(config, path) GitlabCiYamlProcessor.new(config, path)
end.to raise_error(GitlabCiYamlProcessor::ValidationError, "Stages config should be an array of strings") end.to raise_error(GitlabCiYamlProcessor::ValidationError, "stages config should be an array of strings")
end end
it "returns errors if stages is not an array of strings" do it "returns errors if stages is not an array of strings" do
config = YAML.dump({ stages: [true, "test"], rspec: { script: "test" } }) config = YAML.dump({ stages: [true, "test"], rspec: { script: "test" } })
expect do expect do
GitlabCiYamlProcessor.new(config, path) GitlabCiYamlProcessor.new(config, path)
end.to raise_error(GitlabCiYamlProcessor::ValidationError, "Stages config should be an array of strings") end.to raise_error(GitlabCiYamlProcessor::ValidationError, "stages config should be an array of strings")
end end
it "returns errors if variables is not a map" do it "returns errors if variables is not a map" do
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 config should be a hash of key value pairs") end.to raise_error(GitlabCiYamlProcessor::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 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 config should be a hash of key value pairs") end.to raise_error(GitlabCiYamlProcessor::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 it "returns errors if job when is not on_success, on_failure or always" do
...@@ -1174,21 +1174,21 @@ EOT ...@@ -1174,21 +1174,21 @@ EOT
config = YAML.dump({ cache: { untracked: "string" }, rspec: { script: "test" } }) config = YAML.dump({ cache: { untracked: "string" }, rspec: { script: "test" } })
expect do expect do
GitlabCiYamlProcessor.new(config) GitlabCiYamlProcessor.new(config)
end.to raise_error(GitlabCiYamlProcessor::ValidationError, "cache:untracked parameter should be an boolean") end.to raise_error(GitlabCiYamlProcessor::ValidationError, "cache:untracked config should be a boolean value")
end end
it "returns errors if cache:paths is not an array of strings" do it "returns errors if cache:paths is not an array of strings" do
config = YAML.dump({ cache: { paths: "string" }, rspec: { script: "test" } }) config = YAML.dump({ cache: { paths: "string" }, rspec: { script: "test" } })
expect do expect do
GitlabCiYamlProcessor.new(config) GitlabCiYamlProcessor.new(config)
end.to raise_error(GitlabCiYamlProcessor::ValidationError, "cache:paths parameter should be an array of strings") end.to raise_error(GitlabCiYamlProcessor::ValidationError, "cache:paths config should be an array of strings")
end end
it "returns errors if cache:key is not a string" do it "returns errors if cache:key is not a string" do
config = YAML.dump({ cache: { key: 1 }, rspec: { script: "test" } }) config = YAML.dump({ cache: { key: 1 }, rspec: { script: "test" } })
expect do expect do
GitlabCiYamlProcessor.new(config) GitlabCiYamlProcessor.new(config)
end.to raise_error(GitlabCiYamlProcessor::ValidationError, "cache:key parameter should be a string") end.to raise_error(GitlabCiYamlProcessor::ValidationError, "cache:key config should be a string or symbol")
end end
it "returns errors if job cache:key is not an a string" do it "returns errors if job cache:key is not an a string" do
......
...@@ -26,7 +26,7 @@ describe Gitlab::Ci::Config::Node::Boolean do ...@@ -26,7 +26,7 @@ describe Gitlab::Ci::Config::Node::Boolean do
describe '#errors' do describe '#errors' do
it 'saves errors' do it 'saves errors' do
expect(entry.errors) expect(entry.errors)
.to include 'Boolean config should be a boolean value' .to include 'boolean config should be a boolean value'
end end
end end
end end
......
...@@ -33,7 +33,7 @@ describe Gitlab::Ci::Config::Node::Cache do ...@@ -33,7 +33,7 @@ describe Gitlab::Ci::Config::Node::Cache do
it 'reports errors with config value' do it 'reports errors with config value' do
expect(entry.errors) expect(entry.errors)
.to include 'Cache config should be a hash' .to include 'cache config should be a hash'
end end
end end
...@@ -42,7 +42,7 @@ describe Gitlab::Ci::Config::Node::Cache do ...@@ -42,7 +42,7 @@ describe Gitlab::Ci::Config::Node::Cache do
it 'reports error with descendants' do it 'reports error with descendants' do
expect(entry.errors) expect(entry.errors)
.to include 'Key config should be a string or symbol' .to include 'key config should be a string or symbol'
end end
end end
...@@ -51,7 +51,7 @@ describe Gitlab::Ci::Config::Node::Cache do ...@@ -51,7 +51,7 @@ describe Gitlab::Ci::Config::Node::Cache do
it 'reports error with descendants' do it 'reports error with descendants' do
expect(entry.errors) expect(entry.errors)
.to include 'Cache config contains unknown keys [:invalid]' .to include 'cache config contains unknown keys: invalid'
end end
end end
end end
......
...@@ -21,7 +21,8 @@ describe Gitlab::Ci::Config::Node::Global do ...@@ -21,7 +21,8 @@ describe Gitlab::Ci::Config::Node::Global do
services: ['postgres:9.1', 'mysql:5.5'], services: ['postgres:9.1', 'mysql:5.5'],
variables: { VAR: 'value' }, variables: { VAR: 'value' },
after_script: ['make clean'], after_script: ['make clean'],
stages: ['build', 'pages'] } stages: ['build', 'pages'],
cache: { key: 'k', untracked: true, paths: ['public/'] } }
end end
describe '#process!' do describe '#process!' do
...@@ -32,7 +33,7 @@ describe Gitlab::Ci::Config::Node::Global do ...@@ -32,7 +33,7 @@ describe Gitlab::Ci::Config::Node::Global do
end end
it 'creates node object for each entry' do it 'creates node object for each entry' do
expect(global.nodes.count).to eq 7 expect(global.nodes.count).to eq 8
end end
it 'creates node object using valid class' do it 'creates node object using valid class' do
...@@ -112,20 +113,27 @@ describe Gitlab::Ci::Config::Node::Global do ...@@ -112,20 +113,27 @@ describe Gitlab::Ci::Config::Node::Global do
end end
end end
end end
describe '#cache' do
it 'returns cache configuration' do
expect(global.cache)
.to eq(key: 'k', untracked: true, paths: ['public/'])
end
end
end end
end end
context 'when most of entires not defined' do context 'when most of entires not defined' do
let(:hash) { { rspec: {} } } let(:hash) { { cache: { key: 'a' }, rspec: {} } }
before { global.process! } before { global.process! }
describe '#nodes' do describe '#nodes' do
it 'instantizes all nodes' do it 'instantizes all nodes' do
expect(global.nodes.count).to eq 7 expect(global.nodes.count).to eq 8
end end
it 'contains undefined nodes' do it 'contains undefined nodes' do
expect(global.nodes.last) expect(global.nodes.first)
.to be_an_instance_of Gitlab::Ci::Config::Node::Undefined .to be_an_instance_of Gitlab::Ci::Config::Node::Undefined
end end
end end
...@@ -141,6 +149,12 @@ describe Gitlab::Ci::Config::Node::Global do ...@@ -141,6 +149,12 @@ describe Gitlab::Ci::Config::Node::Global do
expect(global.stages).to eq %w[build test deploy] expect(global.stages).to eq %w[build test deploy]
end end
end end
describe '#cache' do
it 'returns correct cache definition' do
expect(global.cache).to eq(key: 'a')
end
end
end end
## ##
...@@ -177,7 +191,7 @@ describe Gitlab::Ci::Config::Node::Global do ...@@ -177,7 +191,7 @@ describe Gitlab::Ci::Config::Node::Global do
describe '#errors' do describe '#errors' do
it 'reports errors from child nodes' do it 'reports errors from child nodes' do
expect(global.errors) expect(global.errors)
.to include 'Before script config should be an array of strings' .to include 'before_script config should be an array of strings'
end end
end end
......
...@@ -32,7 +32,7 @@ describe Gitlab::Ci::Config::Node::Image do ...@@ -32,7 +32,7 @@ describe Gitlab::Ci::Config::Node::Image do
describe '#errors' do describe '#errors' do
it 'saves errors' do it 'saves errors' do
expect(entry.errors) expect(entry.errors)
.to include 'Image config should be a string' .to include 'image config should be a string'
end end
end end
......
...@@ -26,7 +26,7 @@ describe Gitlab::Ci::Config::Node::Key do ...@@ -26,7 +26,7 @@ describe Gitlab::Ci::Config::Node::Key do
describe '#errors' do describe '#errors' do
it 'saves errors' do it 'saves errors' do
expect(entry.errors) expect(entry.errors)
.to include 'Key config should be a string or symbol' .to include 'key config should be a string or symbol'
end end
end end
end end
......
...@@ -26,7 +26,7 @@ describe Gitlab::Ci::Config::Node::Paths do ...@@ -26,7 +26,7 @@ describe Gitlab::Ci::Config::Node::Paths do
describe '#errors' do describe '#errors' do
it 'saves errors' do it 'saves errors' do
expect(entry.errors) expect(entry.errors)
.to include 'Paths config should be an array of strings' .to include 'paths config should be an array of strings'
end end
end end
end end
......
...@@ -34,7 +34,7 @@ describe Gitlab::Ci::Config::Node::Script do ...@@ -34,7 +34,7 @@ describe Gitlab::Ci::Config::Node::Script do
describe '#errors' do describe '#errors' do
it 'saves errors' do it 'saves errors' do
expect(entry.errors) expect(entry.errors)
.to include 'Script config should be an array of strings' .to include 'script config should be an array of strings'
end end
end end
......
...@@ -26,7 +26,7 @@ describe Gitlab::Ci::Config::Node::Services do ...@@ -26,7 +26,7 @@ describe Gitlab::Ci::Config::Node::Services do
describe '#errors' do describe '#errors' do
it 'saves errors' do it 'saves errors' do
expect(entry.errors) expect(entry.errors)
.to include 'Services config should be an array of strings' .to include 'services config should be an array of strings'
end end
end end
......
...@@ -26,7 +26,7 @@ describe Gitlab::Ci::Config::Node::Stages do ...@@ -26,7 +26,7 @@ describe Gitlab::Ci::Config::Node::Stages do
describe '#errors' do describe '#errors' do
it 'saves errors' do it 'saves errors' do
expect(entry.errors) expect(entry.errors)
.to include 'Stages config should be an array of strings' .to include 'stages config should be an array of strings'
end end
end end
......
...@@ -7,6 +7,7 @@ describe Gitlab::Ci::Config::Node::Validator do ...@@ -7,6 +7,7 @@ describe Gitlab::Ci::Config::Node::Validator do
before do before do
allow(node).to receive(:key).and_return('node') allow(node).to receive(:key).and_return('node')
allow(node).to receive(:ancestors).and_return([])
end end
describe 'delegated validator' do describe 'delegated validator' do
...@@ -47,7 +48,7 @@ describe Gitlab::Ci::Config::Node::Validator do ...@@ -47,7 +48,7 @@ describe Gitlab::Ci::Config::Node::Validator do
validator_instance.validate validator_instance.validate
expect(validator_instance.messages) expect(validator_instance.messages)
.to include "Node test attribute can't be blank" .to include "node test attribute can't be blank"
end 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