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

Handle CI services config in new CI config classes

上级 cd6a2afb
...@@ -14,7 +14,7 @@ module Ci ...@@ -14,7 +14,7 @@ module Ci
ALLOWED_CACHE_KEYS = [:key, :untracked, :paths] ALLOWED_CACHE_KEYS = [:key, :untracked, :paths]
ALLOWED_ARTIFACTS_KEYS = [:name, :untracked, :paths, :when, :expire_in] ALLOWED_ARTIFACTS_KEYS = [:name, :untracked, :paths, :when, :expire_in]
attr_reader :after_script, :services, :path, :cache attr_reader :after_script, :path, :cache
def initialize(config, path = nil) def initialize(config, path = nil)
@ci_config = Gitlab::Ci::Config.new(config) @ci_config = Gitlab::Ci::Config.new(config)
...@@ -68,7 +68,7 @@ module Ci ...@@ -68,7 +68,7 @@ module Ci
@after_script = @config[:after_script] @after_script = @config[:after_script]
@image = @config[:image] @image = @config[:image]
@services = @config[:services] @services = @ci_config.services
@stages = @config[:stages] || @config[:types] @stages = @config[:stages] || @config[:types]
@variables = @config[:variables] || {} @variables = @config[:variables] || {}
@cache = @config[:cache] @cache = @config[:cache]
...@@ -127,10 +127,6 @@ module Ci ...@@ -127,10 +127,6 @@ module Ci
raise ValidationError, "after_script should be an array of strings" raise ValidationError, "after_script should be an array of strings"
end end
unless @services.nil? || validate_array_of_strings(@services)
raise ValidationError, "services should be an array of strings"
end
unless @stages.nil? || validate_array_of_strings(@stages) unless @stages.nil? || validate_array_of_strings(@stages)
raise ValidationError, "stages should be an array of strings" raise ValidationError, "stages should be an array of strings"
end end
......
...@@ -7,7 +7,7 @@ module Gitlab ...@@ -7,7 +7,7 @@ module Gitlab
## ##
# Temporary delegations that should be removed after refactoring # Temporary delegations that should be removed after refactoring
# #
delegate :before_script, :image, to: :@global delegate :before_script, :image, :services, to: :@global
def initialize(config) def initialize(config)
@config = Loader.new(config).load! @config = Loader.new(config).load!
......
...@@ -14,6 +14,9 @@ module Gitlab ...@@ -14,6 +14,9 @@ module Gitlab
allow_node :image, Image, allow_node :image, Image,
description: 'Docker image that will be used to execute jobs.' description: 'Docker image that will be used to execute jobs.'
allow_node :services, Services,
description: 'Docker images that will be linked to the container.'
end end
end end
end end
......
module Gitlab
module Ci
class Config
module Node
##
# Entry that represents a configuration of Docker services.
#
class Services < Entry
include Validatable
validations do
validates :config, array_of_strings: true
end
def value
@config
end
end
end
end
end
end
...@@ -1007,14 +1007,14 @@ EOT ...@@ -1007,14 +1007,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 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 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
......
...@@ -22,7 +22,8 @@ describe Gitlab::Ci::Config::Node::Global do ...@@ -22,7 +22,8 @@ describe Gitlab::Ci::Config::Node::Global do
context 'when hash is valid' do context 'when hash is valid' do
let(:hash) do let(:hash) do
{ before_script: ['ls', 'pwd'], { before_script: ['ls', 'pwd'],
image: 'ruby:2.2' } image: 'ruby:2.2',
services: ['postgres:9.1', 'mysql:5.5'] }
end end
describe '#process!' do describe '#process!' do
...@@ -33,7 +34,7 @@ describe Gitlab::Ci::Config::Node::Global do ...@@ -33,7 +34,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 2 expect(global.nodes.count).to eq 3
end end
it 'creates node object using valid class' do it 'creates node object using valid class' do
...@@ -56,6 +57,7 @@ describe Gitlab::Ci::Config::Node::Global do ...@@ -56,6 +57,7 @@ describe Gitlab::Ci::Config::Node::Global do
expect(global).not_to be_leaf expect(global).not_to be_leaf
end end
end end
context 'when not processed' do context 'when not processed' do
describe '#before_script' do describe '#before_script' do
it 'returns nil' do it 'returns nil' do
...@@ -78,6 +80,12 @@ describe Gitlab::Ci::Config::Node::Global do ...@@ -78,6 +80,12 @@ describe Gitlab::Ci::Config::Node::Global do
expect(global.image).to eq 'ruby:2.2' expect(global.image).to eq 'ruby:2.2'
end end
end end
describe '#services' do
it 'returns array of services' do
expect(global.services).to eq ['postgres:9.1', 'mysql:5.5']
end
end
end end
end end
......
require 'spec_helper'
describe Gitlab::Ci::Config::Node::Services do
let(:entry) { described_class.new(config) }
describe '#process!' do
before { entry.process! }
context 'when entry config value is correct' do
let(:config) { ['postgres:9.1', 'mysql:5.5'] }
describe '#value' do
it 'returns array of services as is' do
expect(entry.value).to eq config
end
end
describe '#valid?' do
it 'is valid' do
expect(entry).to be_valid
end
end
end
context 'when entry value is not correct' do
let(:config) { 'ls' }
describe '#errors' do
it 'saves errors' do
expect(entry.errors)
.to include 'Services config should be an array of strings'
end
end
describe '#valid?' do
it 'is not valid' do
expect(entry).not_to be_valid
end
end
end
end
end
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册