From a1363d39c6fe79d830dbce468c02880d2a5d7996 Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Fri, 8 Apr 2016 11:02:26 +0200 Subject: Add `variables` keyword to job in CI config YAML --- spec/models/build_spec.rb | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'spec/models/build_spec.rb') diff --git a/spec/models/build_spec.rb b/spec/models/build_spec.rb index b7457808040..ee44a4c5f12 100644 --- a/spec/models/build_spec.rb +++ b/spec/models/build_spec.rb @@ -238,6 +238,22 @@ describe Ci::Build, models: true do it { is_expected.to eq(predefined_variables + predefined_trigger_variable + yaml_variables + secure_variables + trigger_variables) } end + + context 'when job variables are defined' do + before { build.update_attribute(:options, variables: job_variables) } + + context 'when job variables are unique' do + let(:job_variables) { { KEY1: 'value1', KEY2: 'value2' } } + let(:resulting_variables) do + [{ key: :KEY1, value: 'value1', public: true }, + { key: :KEY2, value: 'value2', public: true }] + end + + it 'includes job variables' do + expect(subject).to include(*resulting_variables) + end + end + end end end end -- cgit v1.2.1 From b578fbfb8572860490cdfd0163bfbf5f999bb1e6 Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Mon, 11 Apr 2016 13:09:46 +0200 Subject: Make it possible to override build variables --- spec/models/build_spec.rb | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) (limited to 'spec/models/build_spec.rb') diff --git a/spec/models/build_spec.rb b/spec/models/build_spec.rb index ee44a4c5f12..94d51435f37 100644 --- a/spec/models/build_spec.rb +++ b/spec/models/build_spec.rb @@ -240,17 +240,31 @@ describe Ci::Build, models: true do end context 'when job variables are defined' do + def result_variables + job_variables.map do |key, value| + { key: key, value: value, public: true } + end + end + before { build.update_attribute(:options, variables: job_variables) } context 'when job variables are unique' do let(:job_variables) { { KEY1: 'value1', KEY2: 'value2' } } - let(:resulting_variables) do - [{ key: :KEY1, value: 'value1', public: true }, - { key: :KEY2, value: 'value2', public: true }] - end it 'includes job variables' do - expect(subject).to include(*resulting_variables) + expect(subject).to include(*result_variables) + end + end + + context 'when job variable has same key other variable has' do + let(:job_variables) { { CI_BUILD_NAME: 'overridden' } } + + it 'contains job yaml variable' do + expect(subject).to include(*result_variables) + end + + it 'contains only one variable with this key' do + expect(subject.count { |var| var[:key] == :CI_BUILD_NAME } ).to eq 1 end end end -- cgit v1.2.1 From b7946b50fc1b23b1974f7d0306c06f6d92cc8466 Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Fri, 15 Apr 2016 12:18:46 +0200 Subject: Read job variables directly from gitlab CI config --- spec/models/build_spec.rb | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) (limited to 'spec/models/build_spec.rb') diff --git a/spec/models/build_spec.rb b/spec/models/build_spec.rb index 94d51435f37..26a063de1e1 100644 --- a/spec/models/build_spec.rb +++ b/spec/models/build_spec.rb @@ -240,31 +240,27 @@ describe Ci::Build, models: true do end context 'when job variables are defined' do - def result_variables - job_variables.map do |key, value| - { key: key, value: value, public: true } - end - end - - before { build.update_attribute(:options, variables: job_variables) } - context 'when job variables are unique' do - let(:job_variables) { { KEY1: 'value1', KEY2: 'value2' } } + before { allow(build).to receive(:name) { 'staging' } } it 'includes job variables' do - expect(subject).to include(*result_variables) + expect(subject).to include( + { key: :KEY1, value: 'value1', public: true }, + { key: :KEY2, value: 'value2', public: true } + ) end end context 'when job variable has same key other variable has' do - let(:job_variables) { { CI_BUILD_NAME: 'overridden' } } + before { allow(build).to receive(:name) { 'production' } } it 'contains job yaml variable' do - expect(subject).to include(*result_variables) + expect(subject).to include(key: :DB_NAME, value: 'mysql', + public: true) end it 'contains only one variable with this key' do - expect(subject.count { |var| var[:key] == :CI_BUILD_NAME } ).to eq 1 + expect(subject.count { |var| var[:key] == :DB_NAME } ).to eq 1 end end end -- cgit v1.2.1 From bdb06fa0437ebc1b03377d95763d1fefdcfd0441 Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Fri, 15 Apr 2016 20:43:23 +0200 Subject: Improve build specs for job environment variables --- spec/models/build_spec.rb | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'spec/models/build_spec.rb') diff --git a/spec/models/build_spec.rb b/spec/models/build_spec.rb index 26a063de1e1..5ee40c22536 100644 --- a/spec/models/build_spec.rb +++ b/spec/models/build_spec.rb @@ -240,8 +240,11 @@ describe Ci::Build, models: true do end context 'when job variables are defined' do + ## + # Job-level variables are defined in gitlab_ci.yml fixture + # context 'when job variables are unique' do - before { allow(build).to receive(:name) { 'staging' } } + let(:build) { create(:ci_build, name: 'staging') } it 'includes job variables' do expect(subject).to include( @@ -252,7 +255,7 @@ describe Ci::Build, models: true do end context 'when job variable has same key other variable has' do - before { allow(build).to receive(:name) { 'production' } } + let(:build) { create(:ci_build, name: 'production') } it 'contains job yaml variable' do expect(subject).to include(key: :DB_NAME, value: 'mysql', -- cgit v1.2.1 From a6260b1eb7b4f30817d0cc5dbd80c860b5ed8a31 Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Sat, 16 Apr 2016 20:21:01 +0200 Subject: Remove code that removes duplicate CI variables At this point this is being handled by GitLab Runner and we need to introduce this as a separate merge request. --- spec/models/build_spec.rb | 13 ------------- 1 file changed, 13 deletions(-) (limited to 'spec/models/build_spec.rb') diff --git a/spec/models/build_spec.rb b/spec/models/build_spec.rb index 5ee40c22536..b5d356aa066 100644 --- a/spec/models/build_spec.rb +++ b/spec/models/build_spec.rb @@ -253,19 +253,6 @@ describe Ci::Build, models: true do ) end end - - context 'when job variable has same key other variable has' do - let(:build) { create(:ci_build, name: 'production') } - - it 'contains job yaml variable' do - expect(subject).to include(key: :DB_NAME, value: 'mysql', - public: true) - end - - it 'contains only one variable with this key' do - expect(subject.count { |var| var[:key] == :DB_NAME } ).to eq 1 - end - end end end end -- cgit v1.2.1