summaryrefslogtreecommitdiff
path: root/spec/lib
diff options
context:
space:
mode:
authorGrzegorz Bizon <grzesiek.bizon@gmail.com>2016-06-22 11:22:53 +0200
committerGrzegorz Bizon <grzesiek.bizon@gmail.com>2016-06-22 11:22:53 +0200
commit05ce8a118743a5d896b6b8cc99b40af214ac8cd1 (patch)
tree8ddad8e7a7c75c274404c62d3ed583ad1a0c0b71 /spec/lib
parent04ecfca386b70800d3876d3f11ff7451e95d9087 (diff)
downloadgitlab-ce-05ce8a118743a5d896b6b8cc99b40af214ac8cd1.tar.gz
Handle CI environment variables in a new CI config
Diffstat (limited to 'spec/lib')
-rw-r--r--spec/lib/ci/gitlab_ci_yaml_processor_spec.rb4
-rw-r--r--spec/lib/gitlab/ci/config/node/global_spec.rb9
-rw-r--r--spec/lib/gitlab/ci/config/node/variables_spec.rb67
3 files changed, 77 insertions, 3 deletions
diff --git a/spec/lib/ci/gitlab_ci_yaml_processor_spec.rb b/spec/lib/ci/gitlab_ci_yaml_processor_spec.rb
index 35309eec597..97a08758c04 100644
--- a/spec/lib/ci/gitlab_ci_yaml_processor_spec.rb
+++ b/spec/lib/ci/gitlab_ci_yaml_processor_spec.rb
@@ -1098,14 +1098,14 @@ EOT
config = YAML.dump({ variables: "test", rspec: { script: "test" } })
expect do
GitlabCiYamlProcessor.new(config, path)
- end.to raise_error(GitlabCiYamlProcessor::ValidationError, "variables should be a map of key-value strings")
+ end.to raise_error(GitlabCiYamlProcessor::ValidationError, "Variables value should be a hash of key value pairs")
end
it "returns errors if variables is not a map of key-value strings" do
config = YAML.dump({ variables: { test: false }, rspec: { script: "test" } })
expect do
GitlabCiYamlProcessor.new(config, path)
- end.to raise_error(GitlabCiYamlProcessor::ValidationError, "variables should be a map of key-value strings")
+ end.to raise_error(GitlabCiYamlProcessor::ValidationError, "Variables value should be a hash of key value pairs")
end
it "returns errors if job when is not on_success, on_failure or always" do
diff --git a/spec/lib/gitlab/ci/config/node/global_spec.rb b/spec/lib/gitlab/ci/config/node/global_spec.rb
index 84ab1d49d0b..ef4b669c403 100644
--- a/spec/lib/gitlab/ci/config/node/global_spec.rb
+++ b/spec/lib/gitlab/ci/config/node/global_spec.rb
@@ -24,6 +24,7 @@ describe Gitlab::Ci::Config::Node::Global do
{ before_script: ['ls', 'pwd'],
image: 'ruby:2.2',
services: ['postgres:9.1', 'mysql:5.5'],
+ variables: { VAR: 'value' },
after_script: ['make clean'] }
end
@@ -35,7 +36,7 @@ describe Gitlab::Ci::Config::Node::Global do
end
it 'creates node object for each entry' do
- expect(global.nodes.count).to eq 4
+ expect(global.nodes.count).to eq 5
end
it 'creates node object using valid class' do
@@ -93,6 +94,12 @@ describe Gitlab::Ci::Config::Node::Global do
expect(global.after_script).to eq ['make clean']
end
end
+
+ describe '#variables' do
+ it 'returns variables' do
+ expect(global.variables).to eq(VAR: 'value')
+ end
+ end
end
end
diff --git a/spec/lib/gitlab/ci/config/node/variables_spec.rb b/spec/lib/gitlab/ci/config/node/variables_spec.rb
new file mode 100644
index 00000000000..67df70992b4
--- /dev/null
+++ b/spec/lib/gitlab/ci/config/node/variables_spec.rb
@@ -0,0 +1,67 @@
+require 'spec_helper'
+
+describe Gitlab::Ci::Config::Node::Variables do
+ let(:entry) { described_class.new(config) }
+
+ describe 'validations' do
+ context 'when entry config value is correct' do
+ let(:config) do
+ { 'VARIABLE_1' => 'value 1', 'VARIABLE_2' => 'value 2' }
+ end
+
+ describe '#value' do
+ it 'returns hash with key value strings' do
+ expect(entry.value).to eq config
+ end
+ end
+
+ describe '#errors' do
+ it 'does not append errors' do
+ expect(entry.errors).to be_empty
+ 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) { [ :VAR, 'test' ] }
+
+ describe '#errors' do
+ it 'saves errors' do
+ expect(entry.errors)
+ .to include /should be a hash of key value pairs/
+ end
+ end
+
+ describe '#valid?' do
+ it 'is not valid' do
+ expect(entry).not_to be_valid
+ end
+ end
+ end
+
+ ##
+ # See #18775
+ #
+ context 'when entry value is not defined' do
+ let(:config) { nil }
+
+ describe '#valid?' do
+ it 'is valid' do
+ expect(entry).to be_valid
+ end
+ end
+
+ describe '#values' do
+ it 'returns an empty hash' do
+ expect(entry.value).to eq({})
+ end
+ end
+ end
+ end
+end