summaryrefslogtreecommitdiff
path: root/spec/presenters
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2021-03-16 15:11:17 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2021-03-16 15:11:17 +0000
commitdad48b4af20204db430a6c62c4641283e24dd89a (patch)
treec8b4644cf30e2babe572f20b89257bcd8fa4b6d6 /spec/presenters
parente2999d09ec050b12b6de9121d9aedc38c12477fd (diff)
downloadgitlab-ce-dad48b4af20204db430a6c62c4641283e24dd89a.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/presenters')
-rw-r--r--spec/presenters/ci/build_runner_presenter_spec.rb83
1 files changed, 69 insertions, 14 deletions
diff --git a/spec/presenters/ci/build_runner_presenter_spec.rb b/spec/presenters/ci/build_runner_presenter_spec.rb
index 1eecc9d1ce6..bc09b9db5f1 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
{
@@ -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