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:
Diffstat (limited to 'spec/presenters/ci/build_runner_presenter_spec.rb')
-rw-r--r--spec/presenters/ci/build_runner_presenter_spec.rb87
1 files changed, 71 insertions, 16 deletions
diff --git a/spec/presenters/ci/build_runner_presenter_spec.rb b/spec/presenters/ci/build_runner_presenter_spec.rb
index 1eecc9d1ce6..9cb00781e99 100644
--- a/spec/presenters/ci/build_runner_presenter_spec.rb
+++ b/spec/presenters/ci/build_runner_presenter_spec.rb
@@ -85,7 +85,7 @@ RSpec.describe Ci::BuildRunnerPresenter do
Ci::JobArtifact::DEFAULT_FILE_NAMES.each do |file_type, filename|
context file_type.to_s do
let(:report) { { "#{file_type}": [filename] } }
- let(:build) { create(:ci_build, options: { artifacts: { reports: report } } ) }
+ let(:build) { create(:ci_build, options: { artifacts: { reports: report } }) }
let(:report_expectation) do
{
@@ -106,7 +106,7 @@ RSpec.describe Ci::BuildRunnerPresenter do
context "when option has both archive and reports specification" do
let(:report) { { junit: ['junit.xml'] } }
- let(:build) { create(:ci_build, options: { script: 'echo', artifacts: { **archive, reports: report } } ) }
+ let(:build) { create(:ci_build, options: { script: 'echo', artifacts: { **archive, reports: report } }) }
let(:report_expectation) do
{
@@ -223,7 +223,7 @@ RSpec.describe Ci::BuildRunnerPresenter do
let(:build) { create(:ci_build, ref: pipeline.ref, pipeline: pipeline) }
before do
- pipeline.persistent_ref.create
+ pipeline.persistent_ref.create # rubocop:disable Rails/SaveBang
end
it 'returns the correct refspecs' do
@@ -261,7 +261,7 @@ RSpec.describe Ci::BuildRunnerPresenter do
let(:build) { create(:ci_build, pipeline: pipeline) }
before do
- pipeline.persistent_ref.create
+ pipeline.persistent_ref.create # rubocop:disable Rails/SaveBang
end
it 'exposes the persistent pipeline ref' do
@@ -272,27 +272,82 @@ RSpec.describe Ci::BuildRunnerPresenter do
end
end
- describe '#variables' do
- subject { presenter.variables }
+ describe '#runner_variables' do
+ subject { presenter.runner_variables }
- let(:build) { create(:ci_build) }
+ let_it_be(:project_with_flag_disabled) { create(:project, :repository) }
+ let_it_be(:project_with_flag_enabled) { create(:project, :repository) }
+
+ before do
+ stub_feature_flags(variable_inside_variable: [project_with_flag_enabled])
+ end
+
+ shared_examples 'returns an array with the expected variables' do
+ it 'returns an array' do
+ is_expected.to be_an_instance_of(Array)
+ end
+
+ it 'returns the expected variables' do
+ is_expected.to eq(presenter.variables.to_runner_variables)
+ end
+ end
+
+ context 'when FF :variable_inside_variable is disabled' do
+ let(:sha) { project_with_flag_disabled.repository.commit.sha }
+ let(:pipeline) { create(:ci_pipeline, sha: sha, project: project_with_flag_disabled) }
+ let(:build) { create(:ci_build, pipeline: pipeline) }
+
+ it_behaves_like 'returns an array with the expected variables'
+ end
+
+ context 'when FF :variable_inside_variable is enabled' do
+ let(:sha) { project_with_flag_enabled.repository.commit.sha }
+ let(:pipeline) { create(:ci_pipeline, sha: sha, project: project_with_flag_enabled) }
+ let(:build) { create(:ci_build, pipeline: pipeline) }
- it 'returns a Collection' do
- is_expected.to be_an_instance_of(Gitlab::Ci::Variables::Collection)
+ it_behaves_like 'returns an array with the expected variables'
end
end
- describe '#runner_variables' do
- subject { presenter.runner_variables }
+ describe '#runner_variables subset' do
+ subject { presenter.runner_variables.select { |v| %w[A B C].include?(v.fetch(:key)) } }
let(:build) { create(:ci_build) }
- it 'returns an array' do
- is_expected.to be_an_instance_of(Array)
- end
+ context 'with references in pipeline variables' do
+ before do
+ create(:ci_pipeline_variable, key: 'A', value: 'refA-$B', pipeline: build.pipeline)
+ create(:ci_pipeline_variable, key: 'B', value: 'refB-$C-$D', pipeline: build.pipeline)
+ create(:ci_pipeline_variable, key: 'C', value: 'value', pipeline: build.pipeline)
+ end
+
+ context 'when FF :variable_inside_variable is disabled' do
+ before do
+ stub_feature_flags(variable_inside_variable: false)
+ end
- it 'returns the expected variables' do
- is_expected.to eq(presenter.variables.to_runner_variables)
+ it 'returns non-expanded variables' do
+ is_expected.to eq [
+ { key: 'A', value: 'refA-$B', public: false, masked: false },
+ { key: 'B', value: 'refB-$C-$D', public: false, masked: false },
+ { key: 'C', value: 'value', public: false, masked: false }
+ ]
+ end
+ end
+
+ context 'when FF :variable_inside_variable is enabled' do
+ before do
+ stub_feature_flags(variable_inside_variable: [build.project])
+ end
+
+ it 'returns expanded and sorted variables' do
+ is_expected.to eq [
+ { key: 'C', value: 'value', public: false, masked: false },
+ { key: 'B', value: 'refB-value-$D', public: false, masked: false },
+ { key: 'A', value: 'refA-refB-value-$D', public: false, masked: false }
+ ]
+ end
+ end
end
end
end