From 4f472d49b52452b0377fa0701dfe970f3e83bb85 Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Tue, 27 Feb 2018 12:24:16 +0100 Subject: Make pipeline priority variables concept explicit --- spec/models/ci/pipeline_spec.rb | 43 +++++++++++++++++++++++++++++++++++------ 1 file changed, 37 insertions(+), 6 deletions(-) (limited to 'spec/models/ci/pipeline_spec.rb') diff --git a/spec/models/ci/pipeline_spec.rb b/spec/models/ci/pipeline_spec.rb index 14d234f6aab..4d5fc1dfcd8 100644 --- a/spec/models/ci/pipeline_spec.rb +++ b/spec/models/ci/pipeline_spec.rb @@ -167,15 +167,46 @@ describe Ci::Pipeline, :mailer do end end - describe '#predefined_variables' do - subject { pipeline.predefined_variables } + describe 'pipeline variables' do + describe '#predefined_variables' do + subject { pipeline.predefined_variables } - it { is_expected.to be_an(Array) } + it { is_expected.to be_an(Array) } + + it 'includes the defined keys' do + keys = subject.map { |v| v.fetch(:key) } + + expect(keys).to include('CI_PIPELINE_ID', 'CI_CONFIG_PATH', 'CI_PIPELINE_SOURCE') + end + + it 'includes project-level predefined variables' do + keys = subject.map { |v| v.fetch(:key) } + + expect(keys).to include('CI_PROJECT_NAME') + end + end + + describe '#priority_variables' do + before do + pipeline.variables.build(key: 'MY_VAR', value: 'my var') + end - it 'includes the defined keys' do - keys = subject.map { |v| v[:key] } + it 'returns trigger variables' do + expect(pipeline.priority_variables) + .to include(key: 'MY_VAR', value: 'my var', public: false) + end + end - expect(keys).to include('CI_PIPELINE_ID', 'CI_CONFIG_PATH', 'CI_PIPELINE_SOURCE') + describe '#runtime_variables' do + before do + pipeline.variables.build(key: 'MY_VAR', value: 'my var') + end + + it 'includes predefined and priority variables' do + variables = pipeline.runtime_variables.map { |v| v.fetch(:key) } + + expect(variables).to include('MY_VAR', 'CI_PIPELINE_ID', 'CI_PROJECT_ID') + end end end -- cgit v1.2.1 From a032c296cc58b9ac95478f9ba3b49fee0cf6575e Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Wed, 28 Feb 2018 15:10:09 +0100 Subject: Move pipeline-level variables from build to pipeline --- spec/models/ci/pipeline_spec.rb | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'spec/models/ci/pipeline_spec.rb') diff --git a/spec/models/ci/pipeline_spec.rb b/spec/models/ci/pipeline_spec.rb index 4d5fc1dfcd8..082d3262d9d 100644 --- a/spec/models/ci/pipeline_spec.rb +++ b/spec/models/ci/pipeline_spec.rb @@ -1280,6 +1280,28 @@ describe Ci::Pipeline, :mailer do end end + describe '#ref_slug' do + { + 'master' => 'master', + '1-foo' => '1-foo', + 'fix/1-foo' => 'fix-1-foo', + 'fix-1-foo' => 'fix-1-foo', + 'a' * 63 => 'a' * 63, + 'a' * 64 => 'a' * 63, + 'FOO' => 'foo', + '-' + 'a' * 61 + '-' => 'a' * 61, + '-' + 'a' * 62 + '-' => 'a' * 62, + '-' + 'a' * 63 + '-' => 'a' * 62, + 'a' * 62 + ' ' => 'a' * 62 + }.each do |ref, slug| + it "transforms #{ref} to #{slug}" do + pipeline.ref = ref + + expect(pipeline.ref_slug).to eq(slug) + end + end + end + describe '#execute_hooks' do let!(:build_a) { create_build('a', 0) } let!(:build_b) { create_build('b', 0) } -- cgit v1.2.1 From a648209a07704d08e2a2faa9059d7b6e912bda62 Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Thu, 1 Mar 2018 12:44:23 +0100 Subject: Revert changes to predefined variables hierarchy --- spec/models/ci/pipeline_spec.rb | 65 ++++------------------------------------- 1 file changed, 6 insertions(+), 59 deletions(-) (limited to 'spec/models/ci/pipeline_spec.rb') diff --git a/spec/models/ci/pipeline_spec.rb b/spec/models/ci/pipeline_spec.rb index 082d3262d9d..14d234f6aab 100644 --- a/spec/models/ci/pipeline_spec.rb +++ b/spec/models/ci/pipeline_spec.rb @@ -167,46 +167,15 @@ describe Ci::Pipeline, :mailer do end end - describe 'pipeline variables' do - describe '#predefined_variables' do - subject { pipeline.predefined_variables } + describe '#predefined_variables' do + subject { pipeline.predefined_variables } - it { is_expected.to be_an(Array) } - - it 'includes the defined keys' do - keys = subject.map { |v| v.fetch(:key) } - - expect(keys).to include('CI_PIPELINE_ID', 'CI_CONFIG_PATH', 'CI_PIPELINE_SOURCE') - end - - it 'includes project-level predefined variables' do - keys = subject.map { |v| v.fetch(:key) } - - expect(keys).to include('CI_PROJECT_NAME') - end - end - - describe '#priority_variables' do - before do - pipeline.variables.build(key: 'MY_VAR', value: 'my var') - end - - it 'returns trigger variables' do - expect(pipeline.priority_variables) - .to include(key: 'MY_VAR', value: 'my var', public: false) - end - end - - describe '#runtime_variables' do - before do - pipeline.variables.build(key: 'MY_VAR', value: 'my var') - end + it { is_expected.to be_an(Array) } - it 'includes predefined and priority variables' do - variables = pipeline.runtime_variables.map { |v| v.fetch(:key) } + it 'includes the defined keys' do + keys = subject.map { |v| v[:key] } - expect(variables).to include('MY_VAR', 'CI_PIPELINE_ID', 'CI_PROJECT_ID') - end + expect(keys).to include('CI_PIPELINE_ID', 'CI_CONFIG_PATH', 'CI_PIPELINE_SOURCE') end end @@ -1280,28 +1249,6 @@ describe Ci::Pipeline, :mailer do end end - describe '#ref_slug' do - { - 'master' => 'master', - '1-foo' => '1-foo', - 'fix/1-foo' => 'fix-1-foo', - 'fix-1-foo' => 'fix-1-foo', - 'a' * 63 => 'a' * 63, - 'a' * 64 => 'a' * 63, - 'FOO' => 'foo', - '-' + 'a' * 61 + '-' => 'a' * 61, - '-' + 'a' * 62 + '-' => 'a' * 62, - '-' + 'a' * 63 + '-' => 'a' * 62, - 'a' * 62 + ' ' => 'a' * 62 - }.each do |ref, slug| - it "transforms #{ref} to #{slug}" do - pipeline.ref = ref - - expect(pipeline.ref_slug).to eq(slug) - end - end - end - describe '#execute_hooks' do let!(:build_a) { create_build('a', 0) } let!(:build_b) { create_build('b', 0) } -- cgit v1.2.1 From b6e4e449fbd2f844736e9121067c3cfea2cb2933 Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Fri, 23 Mar 2018 13:56:16 +0100 Subject: Integrate build seeds with variables expressions policy --- spec/models/ci/pipeline_spec.rb | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'spec/models/ci/pipeline_spec.rb') diff --git a/spec/models/ci/pipeline_spec.rb b/spec/models/ci/pipeline_spec.rb index 92f00cfbc19..dd94515b0a4 100644 --- a/spec/models/ci/pipeline_spec.rb +++ b/spec/models/ci/pipeline_spec.rb @@ -346,6 +346,20 @@ describe Ci::Pipeline, :mailer do end end end + + context 'when variables policy is specified' do + let(:config) do + { unit: { script: 'minitest', only: { variables: ['$CI_PIPELINE_SOURCE'] } }, + feature: { script: 'spinach', only: { variables: ['$UNDEFINED'] } } } + end + + it 'returns stage seeds only when variables expression is truthy' do + seeds = pipeline.stage_seeds + + expect(seeds.size).to eq 1 + expect(seeds.dig(0, 0, :name)).to eq 'unit' + end + end end describe '#seeds_size' do -- cgit v1.2.1