Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGrzegorz Bizon <grzesiek.bizon@gmail.com>2016-06-21 13:40:52 +0300
committerGrzegorz Bizon <grzesiek.bizon@gmail.com>2016-06-21 13:40:52 +0300
commitfc00c545b27ab2f4bf713ae246c197f809dd4c11 (patch)
tree39afd58eb9469a314aedca39a02b8f91ba63e927
parentcd6a2afbbb508e96f67c1f192cee2c1d379b1749 (diff)
Handle CI services config in new CI config classes
-rw-r--r--lib/ci/gitlab_ci_yaml_processor.rb8
-rw-r--r--lib/gitlab/ci/config.rb2
-rw-r--r--lib/gitlab/ci/config/node/global.rb3
-rw-r--r--lib/gitlab/ci/config/node/services.rb22
-rw-r--r--spec/lib/ci/gitlab_ci_yaml_processor_spec.rb4
-rw-r--r--spec/lib/gitlab/ci/config/node/global_spec.rb12
-rw-r--r--spec/lib/gitlab/ci/config/node/services_spec.rb42
7 files changed, 82 insertions, 11 deletions
diff --git a/lib/ci/gitlab_ci_yaml_processor.rb b/lib/ci/gitlab_ci_yaml_processor.rb
index f4ef449c84c..2cb46448e76 100644
--- a/lib/ci/gitlab_ci_yaml_processor.rb
+++ b/lib/ci/gitlab_ci_yaml_processor.rb
@@ -14,7 +14,7 @@ module Ci
ALLOWED_CACHE_KEYS = [:key, :untracked, :paths]
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)
@ci_config = Gitlab::Ci::Config.new(config)
@@ -68,7 +68,7 @@ module Ci
@after_script = @config[:after_script]
@image = @config[:image]
- @services = @config[:services]
+ @services = @ci_config.services
@stages = @config[:stages] || @config[:types]
@variables = @config[:variables] || {}
@cache = @config[:cache]
@@ -127,10 +127,6 @@ module Ci
raise ValidationError, "after_script should be an array of strings"
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)
raise ValidationError, "stages should be an array of strings"
end
diff --git a/lib/gitlab/ci/config.rb b/lib/gitlab/ci/config.rb
index d02902a110a..fb93d36c48f 100644
--- a/lib/gitlab/ci/config.rb
+++ b/lib/gitlab/ci/config.rb
@@ -7,7 +7,7 @@ module Gitlab
##
# Temporary delegations that should be removed after refactoring
#
- delegate :before_script, :image, to: :@global
+ delegate :before_script, :image, :services, to: :@global
def initialize(config)
@config = Loader.new(config).load!
diff --git a/lib/gitlab/ci/config/node/global.rb b/lib/gitlab/ci/config/node/global.rb
index fa5f75beb9f..03ed7808d2f 100644
--- a/lib/gitlab/ci/config/node/global.rb
+++ b/lib/gitlab/ci/config/node/global.rb
@@ -14,6 +14,9 @@ module Gitlab
allow_node :image, Image,
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
diff --git a/lib/gitlab/ci/config/node/services.rb b/lib/gitlab/ci/config/node/services.rb
new file mode 100644
index 00000000000..d9898d9a4a1
--- /dev/null
+++ b/lib/gitlab/ci/config/node/services.rb
@@ -0,0 +1,22 @@
+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
diff --git a/spec/lib/ci/gitlab_ci_yaml_processor_spec.rb b/spec/lib/ci/gitlab_ci_yaml_processor_spec.rb
index 4c7070ad058..bed174e2495 100644
--- a/spec/lib/ci/gitlab_ci_yaml_processor_spec.rb
+++ b/spec/lib/ci/gitlab_ci_yaml_processor_spec.rb
@@ -1007,14 +1007,14 @@ EOT
config = YAML.dump({ services: "test", rspec: { script: "test" } })
expect do
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
it "returns errors if services parameter is not an array of strings" do
config = YAML.dump({ services: [10, "test"], rspec: { script: "test" } })
expect do
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
it "returns errors if job services parameter is not an array" do
diff --git a/spec/lib/gitlab/ci/config/node/global_spec.rb b/spec/lib/gitlab/ci/config/node/global_spec.rb
index ae911d81c49..7c8ddffc086 100644
--- a/spec/lib/gitlab/ci/config/node/global_spec.rb
+++ b/spec/lib/gitlab/ci/config/node/global_spec.rb
@@ -22,7 +22,8 @@ describe Gitlab::Ci::Config::Node::Global do
context 'when hash is valid' do
let(:hash) do
{ before_script: ['ls', 'pwd'],
- image: 'ruby:2.2' }
+ image: 'ruby:2.2',
+ services: ['postgres:9.1', 'mysql:5.5'] }
end
describe '#process!' do
@@ -33,7 +34,7 @@ describe Gitlab::Ci::Config::Node::Global do
end
it 'creates node object for each entry' do
- expect(global.nodes.count).to eq 2
+ expect(global.nodes.count).to eq 3
end
it 'creates node object using valid class' do
@@ -56,6 +57,7 @@ describe Gitlab::Ci::Config::Node::Global do
expect(global).not_to be_leaf
end
end
+
context 'when not processed' do
describe '#before_script' do
it 'returns nil' do
@@ -78,6 +80,12 @@ describe Gitlab::Ci::Config::Node::Global do
expect(global.image).to eq 'ruby:2.2'
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
diff --git a/spec/lib/gitlab/ci/config/node/services_spec.rb b/spec/lib/gitlab/ci/config/node/services_spec.rb
new file mode 100644
index 00000000000..bda4b976cb9
--- /dev/null
+++ b/spec/lib/gitlab/ci/config/node/services_spec.rb
@@ -0,0 +1,42 @@
+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