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:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-06-18 14:18:50 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2020-06-18 14:18:50 +0300
commit8c7f4e9d5f36cff46365a7f8c4b9c21578c1e781 (patch)
treea77e7fe7a93de11213032ed4ab1f33a3db51b738 /spec/lib/gitlab/ci
parent00b35af3db1abfe813a778f643dad221aad51fca (diff)
Add latest changes from gitlab-org/gitlab@13-1-stable-ee
Diffstat (limited to 'spec/lib/gitlab/ci')
-rw-r--r--spec/lib/gitlab/ci/build/credentials/factory_spec.rb10
-rw-r--r--spec/lib/gitlab/ci/build/releaser_spec.rb51
-rw-r--r--spec/lib/gitlab/ci/build/step_spec.rb26
-rw-r--r--spec/lib/gitlab/ci/config/entry/reports_spec.rb1
-rw-r--r--spec/lib/gitlab/ci/config/entry/retry_spec.rb4
-rw-r--r--spec/lib/gitlab/ci/parsers/terraform/tfplan_spec.rb72
-rw-r--r--spec/lib/gitlab/ci/pipeline/chain/seed_spec.rb4
-rw-r--r--spec/lib/gitlab/ci/pipeline/chain/sequence_spec.rb15
-rw-r--r--spec/lib/gitlab/ci/pipeline/seed/build/cache_spec.rb2
-rw-r--r--spec/lib/gitlab/ci/reports/terraform_reports_spec.rb14
-rw-r--r--spec/lib/gitlab/ci/status/bridge/factory_spec.rb3
-rw-r--r--spec/lib/gitlab/ci/status/stage/play_manual_spec.rb2
-rw-r--r--spec/lib/gitlab/ci/yaml_processor_spec.rb2
13 files changed, 169 insertions, 37 deletions
diff --git a/spec/lib/gitlab/ci/build/credentials/factory_spec.rb b/spec/lib/gitlab/ci/build/credentials/factory_spec.rb
index 848adb2e6e5..159f89f4985 100644
--- a/spec/lib/gitlab/ci/build/credentials/factory_spec.rb
+++ b/spec/lib/gitlab/ci/build/credentials/factory_spec.rb
@@ -7,11 +7,13 @@ describe Gitlab::Ci::Build::Credentials::Factory do
subject { described_class.new(build).create! }
- class TestProvider
- def initialize(build); end
- end
-
before do
+ stub_const('TestProvider', Class.new)
+
+ TestProvider.class_eval do
+ def initialize(build); end
+ end
+
allow_next_instance_of(described_class) do |instance|
allow(instance).to receive(:providers).and_return([TestProvider])
end
diff --git a/spec/lib/gitlab/ci/build/releaser_spec.rb b/spec/lib/gitlab/ci/build/releaser_spec.rb
new file mode 100644
index 00000000000..2f7bca777dd
--- /dev/null
+++ b/spec/lib/gitlab/ci/build/releaser_spec.rb
@@ -0,0 +1,51 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+describe Gitlab::Ci::Build::Releaser do
+ subject { described_class.new(config: config[:release]).script }
+
+ describe '#script' do
+ context 'all nodes' do
+ let(:config) do
+ {
+ release: {
+ name: 'Release $CI_COMMIT_SHA',
+ description: 'Created using the release-cli $EXTRA_DESCRIPTION',
+ tag_name: 'release-$CI_COMMIT_SHA',
+ ref: '$CI_COMMIT_SHA'
+ }
+ }
+ end
+
+ it 'generates the script' do
+ expect(subject).to eq('release-cli create --name "Release $CI_COMMIT_SHA" --description "Created using the release-cli $EXTRA_DESCRIPTION" --tag-name "release-$CI_COMMIT_SHA" --ref "$CI_COMMIT_SHA"')
+ end
+ end
+
+ context 'individual nodes' do
+ using RSpec::Parameterized::TableSyntax
+
+ where(:node_name, :node_value, :result) do
+ 'name' | 'Release $CI_COMMIT_SHA' | 'release-cli create --name "Release $CI_COMMIT_SHA"'
+ 'description' | 'Release-cli $EXTRA_DESCRIPTION' | 'release-cli create --description "Release-cli $EXTRA_DESCRIPTION"'
+ 'tag_name' | 'release-$CI_COMMIT_SHA' | 'release-cli create --tag-name "release-$CI_COMMIT_SHA"'
+ 'ref' | '$CI_COMMIT_SHA' | 'release-cli create --ref "$CI_COMMIT_SHA"'
+ end
+
+ with_them do
+ let(:config) do
+ {
+ release: {
+ node_name => node_value
+ }
+ }
+ end
+
+ it 'generates the script' do
+ expect(subject).to eq(result)
+ end
+ end
+ end
+ end
+end
diff --git a/spec/lib/gitlab/ci/build/step_spec.rb b/spec/lib/gitlab/ci/build/step_spec.rb
index 9c1a8cf5e91..1cebda2cc7e 100644
--- a/spec/lib/gitlab/ci/build/step_spec.rb
+++ b/spec/lib/gitlab/ci/build/step_spec.rb
@@ -51,6 +51,30 @@ describe Gitlab::Ci::Build::Step do
end
end
+ describe '#from_release' do
+ subject { described_class.from_release(job) }
+
+ before do
+ job.run!
+ end
+
+ context 'with release' do
+ let(:job) { create(:ci_build, :release_options) }
+
+ it 'returns the release-cli command line' do
+ expect(subject.script).to eq("release-cli create --name \"Release $CI_COMMIT_SHA\" --description \"Created using the release-cli $EXTRA_DESCRIPTION\" --tag-name \"release-$CI_COMMIT_SHA\" --ref \"$CI_COMMIT_SHA\"")
+ end
+ end
+
+ context 'when release is empty' do
+ let(:job) { create(:ci_build) }
+
+ it 'does not fabricate an object' do
+ is_expected.to be_nil
+ end
+ end
+ end
+
describe '#from_after_script' do
let(:job) { create(:ci_build) }
@@ -61,7 +85,7 @@ describe Gitlab::Ci::Build::Step do
end
context 'when after_script is empty' do
- it 'doesn not fabricate an object' do
+ it 'does not fabricate an object' do
is_expected.to be_nil
end
end
diff --git a/spec/lib/gitlab/ci/config/entry/reports_spec.rb b/spec/lib/gitlab/ci/config/entry/reports_spec.rb
index 8c6c91d919e..2c12a88dedb 100644
--- a/spec/lib/gitlab/ci/config/entry/reports_spec.rb
+++ b/spec/lib/gitlab/ci/config/entry/reports_spec.rb
@@ -37,6 +37,7 @@ describe Gitlab::Ci::Config::Entry::Reports do
:junit | 'junit.xml'
:codequality | 'gl-code-quality-report.json'
:sast | 'gl-sast-report.json'
+ :secret_detection | 'gl-secret-detection-report.json'
:dependency_scanning | 'gl-dependency-scanning-report.json'
:container_scanning | 'gl-container-scanning-report.json'
:dast | 'gl-dast-report.json'
diff --git a/spec/lib/gitlab/ci/config/entry/retry_spec.rb b/spec/lib/gitlab/ci/config/entry/retry_spec.rb
index bb3c0b0004d..67253c71f6b 100644
--- a/spec/lib/gitlab/ci/config/entry/retry_spec.rb
+++ b/spec/lib/gitlab/ci/config/entry/retry_spec.rb
@@ -94,7 +94,7 @@ describe Gitlab::Ci::Config::Entry::Retry do
# sure this is catched, check explicitly that all of the documented
# values are valid. If they are not it means the documentation and this
# array must be updated.
- RETRY_WHEN_IN_DOCUMENTATION = %w[
+ retry_when_in_documentation = %w[
always
unknown_failure
script_failure
@@ -111,7 +111,7 @@ describe Gitlab::Ci::Config::Entry::Retry do
data_integrity_failure
].freeze
- RETRY_WHEN_IN_DOCUMENTATION.each do |reason|
+ retry_when_in_documentation.each do |reason|
context "with when from documentation `#{reason}`" do
let(:when) { reason }
diff --git a/spec/lib/gitlab/ci/parsers/terraform/tfplan_spec.rb b/spec/lib/gitlab/ci/parsers/terraform/tfplan_spec.rb
index 19cd75e586c..fec27c0f31a 100644
--- a/spec/lib/gitlab/ci/parsers/terraform/tfplan_spec.rb
+++ b/spec/lib/gitlab/ci/parsers/terraform/tfplan_spec.rb
@@ -8,7 +8,7 @@ describe Gitlab::Ci::Parsers::Terraform::Tfplan do
let(:reports) { Gitlab::Ci::Reports::TerraformReports.new }
- context 'when data is tfplan.json' do
+ context 'when data is invalid' do
context 'when there is no data' do
it 'raises an error' do
plan = '{}'
@@ -19,31 +19,67 @@ describe Gitlab::Ci::Parsers::Terraform::Tfplan do
end
end
- context 'when there is data' do
- it 'parses JSON and returns a report' do
- plan = '{ "create": 0, "update": 1, "delete": 0 }'
+ context 'when data is not a JSON file' do
+ it 'raises an error' do
+ plan = { 'create' => 0, 'update' => 1, 'delete' => 0 }.to_s
- expect { subject.parse!(plan, reports, artifact: artifact) }.not_to raise_error
+ expect { subject.parse!(plan, reports, artifact: artifact) }.to raise_error(
+ described_class::TfplanParserError
+ )
+ end
+ end
- expect(reports.plans).to match(
- a_hash_including(
- 'tfplan.json' => a_hash_including(
- 'create' => 0,
- 'update' => 1,
- 'delete' => 0
- )
- )
+ context 'when JSON is missing a required key' do
+ it 'raises an error' do
+ plan = '{ "wrong_key": 1 }'
+
+ expect { subject.parse!(plan, reports, artifact: artifact) }.to raise_error(
+ described_class::TfplanParserError
)
end
end
end
- context 'when data is not tfplan.json' do
- it 'raises an error' do
- plan = { 'create' => 0, 'update' => 1, 'delete' => 0 }.to_s
+ context 'when data is valid' do
+ it 'parses JSON and returns a report' do
+ plan = '{ "create": 0, "update": 1, "delete": 0 }'
+
+ expect { subject.parse!(plan, reports, artifact: artifact) }.not_to raise_error
- expect { subject.parse!(plan, reports, artifact: artifact) }.to raise_error(
- described_class::TfplanParserError
+ reports.plans.each do |key, hash_value|
+ expect(hash_value.keys).to match_array(%w[create delete job_name job_path update])
+ end
+
+ expect(reports.plans).to match(
+ a_hash_including(
+ artifact.job.id.to_s => a_hash_including(
+ 'create' => 0,
+ 'update' => 1,
+ 'delete' => 0,
+ 'job_name' => artifact.job.options.dig(:artifacts, :name).to_s
+ )
+ )
+ )
+ end
+
+ it 'parses JSON when extra keys are present' do
+ plan = '{ "create": 0, "update": 1, "delete": 0, "extra_key": 4 }'
+
+ expect { subject.parse!(plan, reports, artifact: artifact) }.not_to raise_error
+
+ reports.plans.each do |key, hash_value|
+ expect(hash_value.keys).to match_array(%w[create delete job_name job_path update])
+ end
+
+ expect(reports.plans).to match(
+ a_hash_including(
+ artifact.job.id.to_s => a_hash_including(
+ 'create' => 0,
+ 'update' => 1,
+ 'delete' => 0,
+ 'job_name' => artifact.job.options.dig(:artifacts, :name).to_s
+ )
+ )
)
end
end
diff --git a/spec/lib/gitlab/ci/pipeline/chain/seed_spec.rb b/spec/lib/gitlab/ci/pipeline/chain/seed_spec.rb
index aa54f19b26c..1e1d5c2a724 100644
--- a/spec/lib/gitlab/ci/pipeline/chain/seed_spec.rb
+++ b/spec/lib/gitlab/ci/pipeline/chain/seed_spec.rb
@@ -39,6 +39,10 @@ describe Gitlab::Ci::Pipeline::Chain::Seed do
expect(pipeline.iid).to be_present
end
+ it 'ensures ci_ref' do
+ expect(pipeline.ci_ref).to be_present
+ end
+
it 'sets the seeds in the command object' do
expect(command.stage_seeds).to all(be_a Gitlab::Ci::Pipeline::Seed::Base)
expect(command.stage_seeds.count).to eq 1
diff --git a/spec/lib/gitlab/ci/pipeline/chain/sequence_spec.rb b/spec/lib/gitlab/ci/pipeline/chain/sequence_spec.rb
index f82e49f9323..ea04862ed74 100644
--- a/spec/lib/gitlab/ci/pipeline/chain/sequence_spec.rb
+++ b/spec/lib/gitlab/ci/pipeline/chain/sequence_spec.rb
@@ -56,11 +56,24 @@ describe Gitlab::Ci::Pipeline::Chain::Sequence do
end
it 'adds sequence duration to duration histogram' do
- allow(command).to receive(:duration_histogram).and_return(histogram)
+ allow(command.metrics)
+ .to receive(:pipeline_creation_duration_histogram)
+ .and_return(histogram)
subject.build!
expect(histogram).to have_received(:observe)
end
+
+ it 'records pipeline size by pipeline source in a histogram' do
+ allow(command.metrics)
+ .to receive(:pipeline_size_histogram)
+ .and_return(histogram)
+
+ subject.build!
+
+ expect(histogram).to have_received(:observe)
+ .with({ source: 'push' }, 0)
+ end
end
end
diff --git a/spec/lib/gitlab/ci/pipeline/seed/build/cache_spec.rb b/spec/lib/gitlab/ci/pipeline/seed/build/cache_spec.rb
index fe19244659f..f5b43b5aeab 100644
--- a/spec/lib/gitlab/ci/pipeline/seed/build/cache_spec.rb
+++ b/spec/lib/gitlab/ci/pipeline/seed/build/cache_spec.rb
@@ -134,7 +134,7 @@ describe Gitlab::Ci::Pipeline::Seed::Build::Cache do
it_behaves_like 'foo/bar directory key'
end
- context 'with directories ending in slash star' do
+ context 'with directories ending in slash star', quarantine: 'https://gitlab.com/gitlab-org/gitlab/-/issues/222356' do
let(:files) { ['foo/bar/*'] }
it_behaves_like 'foo/bar directory key'
diff --git a/spec/lib/gitlab/ci/reports/terraform_reports_spec.rb b/spec/lib/gitlab/ci/reports/terraform_reports_spec.rb
index 061029299ac..bfab30543ed 100644
--- a/spec/lib/gitlab/ci/reports/terraform_reports_spec.rb
+++ b/spec/lib/gitlab/ci/reports/terraform_reports_spec.rb
@@ -10,23 +10,23 @@ describe Gitlab::Ci::Reports::TerraformReports do
describe '#add_plan' do
context 'when providing two unique plans' do
it 'returns two plans' do
- subject.add_plan('a/tfplan.json', { 'create' => 0, 'update' => 1, 'delete' => 0 })
- subject.add_plan('b/tfplan.json', { 'create' => 0, 'update' => 1, 'delete' => 0 })
+ subject.add_plan('123', { 'create' => 1, 'update' => 2, 'delete' => 3 })
+ subject.add_plan('456', { 'create' => 4, 'update' => 5, 'delete' => 6 })
expect(subject.plans).to eq({
- 'a/tfplan.json' => { 'create' => 0, 'update' => 1, 'delete' => 0 },
- 'b/tfplan.json' => { 'create' => 0, 'update' => 1, 'delete' => 0 }
+ '123' => { 'create' => 1, 'update' => 2, 'delete' => 3 },
+ '456' => { 'create' => 4, 'update' => 5, 'delete' => 6 }
})
end
end
context 'when providing the same plan twice' do
it 'returns the last added plan' do
- subject.add_plan('tfplan.json', { 'create' => 0, 'update' => 0, 'delete' => 0 })
- subject.add_plan('tfplan.json', { 'create' => 0, 'update' => 1, 'delete' => 0 })
+ subject.add_plan('123', { 'create' => 0, 'update' => 0, 'delete' => 0 })
+ subject.add_plan('123', { 'create' => 1, 'update' => 2, 'delete' => 3 })
expect(subject.plans).to eq({
- 'tfplan.json' => { 'create' => 0, 'update' => 1, 'delete' => 0 }
+ '123' => { 'create' => 1, 'update' => 2, 'delete' => 3 }
})
end
end
diff --git a/spec/lib/gitlab/ci/status/bridge/factory_spec.rb b/spec/lib/gitlab/ci/status/bridge/factory_spec.rb
index 1f417781988..6c67864855d 100644
--- a/spec/lib/gitlab/ci/status/bridge/factory_spec.rb
+++ b/spec/lib/gitlab/ci/status/bridge/factory_spec.rb
@@ -59,12 +59,13 @@ describe Gitlab::Ci::Status::Bridge::Factory do
context 'failed with downstream_pipeline_creation_failed' do
before do
+ bridge.options = { downstream_errors: ['No stages / jobs for this pipeline.', 'other error'] }
bridge.failure_reason = 'downstream_pipeline_creation_failed'
end
it 'fabricates correct status_tooltip' do
expect(status.status_tooltip).to eq(
- "#{s_('CiStatusText|failed')} - (downstream pipeline can not be created)"
+ "#{s_('CiStatusText|failed')} - (downstream pipeline can not be created, No stages / jobs for this pipeline., other error)"
)
end
end
diff --git a/spec/lib/gitlab/ci/status/stage/play_manual_spec.rb b/spec/lib/gitlab/ci/status/stage/play_manual_spec.rb
index b0113b00ef0..bdcbfed918f 100644
--- a/spec/lib/gitlab/ci/status/stage/play_manual_spec.rb
+++ b/spec/lib/gitlab/ci/status/stage/play_manual_spec.rb
@@ -31,7 +31,7 @@ describe Gitlab::Ci::Status::Stage::PlayManual do
subject { play_manual.action_path }
- it { is_expected.to eq("/#{pipeline.project.full_path}/pipelines/#{pipeline.id}/stages/#{stage.name}/play_manual") }
+ it { is_expected.to eq("/#{pipeline.project.full_path}/-/pipelines/#{pipeline.id}/stages/#{stage.name}/play_manual") }
end
describe '#action_method' do
diff --git a/spec/lib/gitlab/ci/yaml_processor_spec.rb b/spec/lib/gitlab/ci/yaml_processor_spec.rb
index c93bb901981..1668149d8f5 100644
--- a/spec/lib/gitlab/ci/yaml_processor_spec.rb
+++ b/spec/lib/gitlab/ci/yaml_processor_spec.rb
@@ -1388,7 +1388,7 @@ module Gitlab
let(:processor) { Gitlab::Ci::YamlProcessor.new(YAML.dump(config)) }
let(:config) do
{
- stages: ["build", "test", "release"], # rubocop:disable Style/WordArray
+ stages: %w[build test release],
release: {
stage: "release",
only: ["tags"],