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/lib/gitlab/ci/pipeline')
-rw-r--r--spec/lib/gitlab/ci/pipeline/chain/command_spec.rb17
-rw-r--r--spec/lib/gitlab/ci/pipeline/chain/limit/active_jobs_spec.rb4
-rw-r--r--spec/lib/gitlab/ci/pipeline/chain/populate_metadata_spec.rb136
-rw-r--r--spec/lib/gitlab/ci/pipeline/chain/populate_spec.rb43
-rw-r--r--spec/lib/gitlab/ci/pipeline/chain/sequence_spec.rb2
-rw-r--r--spec/lib/gitlab/ci/pipeline/seed/deployment_spec.rb119
-rw-r--r--spec/lib/gitlab/ci/pipeline/seed/environment_spec.rb224
-rw-r--r--spec/lib/gitlab/ci/pipeline/seed/pipeline_spec.rb12
8 files changed, 168 insertions, 389 deletions
diff --git a/spec/lib/gitlab/ci/pipeline/chain/command_spec.rb b/spec/lib/gitlab/ci/pipeline/chain/command_spec.rb
index 6e8b6e40928..9126c6dab21 100644
--- a/spec/lib/gitlab/ci/pipeline/chain/command_spec.rb
+++ b/spec/lib/gitlab/ci/pipeline/chain/command_spec.rb
@@ -409,4 +409,21 @@ RSpec.describe Gitlab::Ci::Pipeline::Chain::Command do
end
end
end
+
+ describe '#observe_pipeline_size' do
+ let(:command) { described_class.new(project: project) }
+
+ let(:pipeline) { instance_double(Ci::Pipeline, total_size: 5, project: project, source: "schedule") }
+
+ it 'logs the pipeline total size to histogram' do
+ histogram = instance_double(Prometheus::Client::Histogram)
+
+ expect(::Gitlab::Ci::Pipeline::Metrics).to receive(:pipeline_size_histogram)
+ .and_return(histogram)
+ expect(histogram).to receive(:observe)
+ .with({ source: pipeline.source, plan: project.actual_plan_name }, pipeline.total_size)
+
+ command.observe_pipeline_size(pipeline)
+ end
+ end
end
diff --git a/spec/lib/gitlab/ci/pipeline/chain/limit/active_jobs_spec.rb b/spec/lib/gitlab/ci/pipeline/chain/limit/active_jobs_spec.rb
index bc453f1502b..c5a5e905d17 100644
--- a/spec/lib/gitlab/ci/pipeline/chain/limit/active_jobs_spec.rb
+++ b/spec/lib/gitlab/ci/pipeline/chain/limit/active_jobs_spec.rb
@@ -69,7 +69,9 @@ RSpec.describe ::Gitlab::Ci::Pipeline::Chain::Limit::ActiveJobs do
class: described_class.name,
message: described_class::MESSAGE,
project_id: project.id,
- plan: default_plan.name
+ plan: default_plan.name,
+ project_path: project.path,
+ jobs_in_alive_pipelines_count: step.send(:count_jobs_in_alive_pipelines)
)
end
diff --git a/spec/lib/gitlab/ci/pipeline/chain/populate_metadata_spec.rb b/spec/lib/gitlab/ci/pipeline/chain/populate_metadata_spec.rb
new file mode 100644
index 00000000000..ce1ee2fcda0
--- /dev/null
+++ b/spec/lib/gitlab/ci/pipeline/chain/populate_metadata_spec.rb
@@ -0,0 +1,136 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe Gitlab::Ci::Pipeline::Chain::PopulateMetadata do
+ let_it_be(:project) { create(:project, :repository) }
+ let_it_be(:user) { create(:user) }
+
+ let(:pipeline) do
+ build(:ci_pipeline, project: project, ref: 'master', user: user)
+ end
+
+ let(:command) do
+ Gitlab::Ci::Pipeline::Chain::Command.new(
+ project: project,
+ current_user: user,
+ origin_ref: 'master')
+ end
+
+ let(:dependencies) do
+ [
+ Gitlab::Ci::Pipeline::Chain::Config::Content.new(pipeline, command),
+ Gitlab::Ci::Pipeline::Chain::Config::Process.new(pipeline, command),
+ Gitlab::Ci::Pipeline::Chain::EvaluateWorkflowRules.new(pipeline, command),
+ Gitlab::Ci::Pipeline::Chain::SeedBlock.new(pipeline, command),
+ Gitlab::Ci::Pipeline::Chain::Seed.new(pipeline, command),
+ Gitlab::Ci::Pipeline::Chain::Populate.new(pipeline, command)
+ ]
+ end
+
+ let(:step) { described_class.new(pipeline, command) }
+
+ let(:config) do
+ { rspec: { script: 'rspec' } }
+ end
+
+ def run_chain
+ dependencies.map(&:perform!)
+ step.perform!
+ end
+
+ before do
+ stub_ci_pipeline_yaml_file(YAML.dump(config))
+ end
+
+ context 'with pipeline name' do
+ let(:config) do
+ { workflow: { name: ' Pipeline name ' }, rspec: { script: 'rspec' } }
+ end
+
+ it 'does not break the chain' do
+ run_chain
+
+ expect(step.break?).to be false
+ end
+
+ context 'with feature flag disabled' do
+ before do
+ stub_feature_flags(pipeline_name: false)
+ end
+
+ it 'does not build pipeline_metadata' do
+ run_chain
+
+ expect(pipeline.pipeline_metadata).to be_nil
+ end
+ end
+
+ context 'with feature flag enabled' do
+ before do
+ stub_feature_flags(pipeline_name: true)
+ end
+
+ it 'builds pipeline_metadata' do
+ run_chain
+
+ expect(pipeline.pipeline_metadata.name).to eq('Pipeline name')
+ expect(pipeline.pipeline_metadata.project).to eq(pipeline.project)
+ expect(pipeline.pipeline_metadata).not_to be_persisted
+ end
+
+ context 'with empty name' do
+ let(:config) do
+ { workflow: { name: ' ' }, rspec: { script: 'rspec' } }
+ end
+
+ it 'strips whitespace from name' do
+ run_chain
+
+ expect(pipeline.pipeline_metadata).to be_nil
+ end
+ end
+
+ context 'with variables' do
+ let(:config) do
+ {
+ variables: { ROOT_VAR: 'value $WORKFLOW_VAR1' },
+ workflow: {
+ name: 'Pipeline $ROOT_VAR $WORKFLOW_VAR2 $UNKNOWN_VAR',
+ rules: [{ variables: { WORKFLOW_VAR1: 'value1', WORKFLOW_VAR2: 'value2' } }]
+ },
+ rspec: { script: 'rspec' }
+ }
+ end
+
+ it 'substitutes variables' do
+ run_chain
+
+ expect(pipeline.pipeline_metadata.name).to eq('Pipeline value value1 value2 ')
+ end
+ end
+
+ context 'with invalid name' do
+ let(:config) do
+ {
+ variables: { ROOT_VAR: 'a' * 256 },
+ workflow: {
+ name: 'Pipeline $ROOT_VAR'
+ },
+ rspec: { script: 'rspec' }
+ }
+ end
+
+ it 'returns error and breaks chain' do
+ ret = run_chain
+
+ expect(ret)
+ .to match_array(["Failed to build pipeline metadata! Name is too long (maximum is 255 characters)"])
+ expect(pipeline.pipeline_metadata.errors.full_messages)
+ .to match_array(['Name is too long (maximum is 255 characters)'])
+ expect(step.break?).to be true
+ end
+ end
+ end
+ end
+end
diff --git a/spec/lib/gitlab/ci/pipeline/chain/populate_spec.rb b/spec/lib/gitlab/ci/pipeline/chain/populate_spec.rb
index 51d1661b586..62de4d2e96d 100644
--- a/spec/lib/gitlab/ci/pipeline/chain/populate_spec.rb
+++ b/spec/lib/gitlab/ci/pipeline/chain/populate_spec.rb
@@ -236,47 +236,4 @@ RSpec.describe Gitlab::Ci::Pipeline::Chain::Populate do
end
end
end
-
- context 'with pipeline name' do
- let(:config) do
- { workflow: { name: ' Pipeline name ' }, rspec: { script: 'rspec' } }
- end
-
- context 'with feature flag disabled' do
- before do
- stub_feature_flags(pipeline_name: false)
- end
-
- it 'does not build pipeline_metadata' do
- run_chain
-
- expect(pipeline.pipeline_metadata).to be_nil
- end
- end
-
- context 'with feature flag enabled' do
- before do
- stub_feature_flags(pipeline_name: true)
- end
-
- it 'builds pipeline_metadata' do
- run_chain
-
- expect(pipeline.pipeline_metadata.title).to eq('Pipeline name')
- expect(pipeline.pipeline_metadata.project).to eq(pipeline.project)
- end
-
- context 'with empty name' do
- let(:config) do
- { workflow: { name: ' ' }, rspec: { script: 'rspec' } }
- end
-
- it 'strips whitespace from name' do
- run_chain
-
- expect(pipeline.pipeline_metadata).to be_nil
- end
- end
- end
- end
end
diff --git a/spec/lib/gitlab/ci/pipeline/chain/sequence_spec.rb b/spec/lib/gitlab/ci/pipeline/chain/sequence_spec.rb
index c69aa661b05..31086f6ae4a 100644
--- a/spec/lib/gitlab/ci/pipeline/chain/sequence_spec.rb
+++ b/spec/lib/gitlab/ci/pipeline/chain/sequence_spec.rb
@@ -80,7 +80,7 @@ RSpec.describe Gitlab::Ci::Pipeline::Chain::Sequence do
subject.build!
expect(histogram).to have_received(:observe)
- .with({ source: 'push' }, 0)
+ .with({ source: 'push', plan: project.actual_plan_name }, 0)
end
describe 'active jobs by pipeline plan histogram' do
diff --git a/spec/lib/gitlab/ci/pipeline/seed/deployment_spec.rb b/spec/lib/gitlab/ci/pipeline/seed/deployment_spec.rb
deleted file mode 100644
index 6569ce937ac..00000000000
--- a/spec/lib/gitlab/ci/pipeline/seed/deployment_spec.rb
+++ /dev/null
@@ -1,119 +0,0 @@
-# frozen_string_literal: true
-
-require 'spec_helper'
-
-RSpec.describe Gitlab::Ci::Pipeline::Seed::Deployment do
- let_it_be(:project, refind: true) { create(:project, :repository) }
-
- let(:pipeline) do
- create(:ci_pipeline, project: project, sha: 'b83d6e391c22777fca1ed3012fce84f633d7fed0')
- end
-
- let(:job) { build(:ci_build, project: project, pipeline: pipeline) }
- let(:environment) { Gitlab::Ci::Pipeline::Seed::Environment.new(job).to_resource }
- let(:seed) { described_class.new(job, environment) }
- let(:attributes) { {} }
-
- before do
- job.assign_attributes(**attributes)
- end
-
- describe '#to_resource' do
- subject { seed.to_resource }
-
- context 'when job has environment attribute' do
- let(:attributes) do
- {
- environment: 'production',
- options: { environment: { name: 'production', **kubernetes_options } }
- }
- end
-
- let(:kubernetes_options) { {} }
-
- it 'returns a deployment object with environment' do
- expect(subject).to be_a(Deployment)
- expect(subject.iid).to be_present
- expect(subject.environment.name).to eq('production')
- expect(subject.cluster).to be_nil
- expect(subject.deployment_cluster).to be_nil
- end
-
- context 'when environment has deployment platform' do
- let!(:cluster) { create(:cluster, :provided_by_gcp, projects: [project], managed: managed_cluster) }
- let(:managed_cluster) { true }
-
- it 'sets the cluster and deployment_cluster' do
- expect(subject.cluster).to eq(cluster) # until we stop double writing in 12.9: https://gitlab.com/gitlab-org/gitlab/issues/202628
- expect(subject.deployment_cluster.cluster).to eq(cluster)
- end
-
- context 'when a custom namespace is given' do
- let(:kubernetes_options) { { kubernetes: { namespace: 'the-custom-namespace' } } }
-
- context 'when cluster is managed' do
- it 'does not set the custom namespace' do
- expect(subject.deployment_cluster.kubernetes_namespace).not_to eq('the-custom-namespace')
- end
- end
-
- context 'when cluster is not managed' do
- let(:managed_cluster) { false }
-
- it 'sets the custom namespace' do
- expect(subject.deployment_cluster.kubernetes_namespace).to eq('the-custom-namespace')
- end
- end
- end
- end
-
- context 'when environment has an invalid URL' do
- let(:attributes) do
- {
- environment: '!!!',
- options: { environment: { name: '!!!' } }
- }
- end
-
- it 'returns nothing' do
- is_expected.to be_nil
- end
- end
-
- context 'when job has already deployment' do
- let(:job) { build(:ci_build, :with_deployment, project: project, environment: 'production') }
-
- it 'returns the persisted deployment' do
- is_expected.to eq(job.deployment)
- end
- end
- end
-
- context 'when job does not start environment' do
- where(:action) do
- %w(stop prepare verify access)
- end
-
- with_them do
- let(:attributes) do
- {
- environment: 'production',
- options: { environment: { name: 'production', action: action } }
- }
- end
-
- it 'returns nothing' do
- is_expected.to be_nil
- end
- end
- end
-
- context 'when job does not have environment attribute' do
- let(:attributes) { { name: 'test' } }
-
- it 'returns nothing' do
- is_expected.to be_nil
- end
- end
- end
-end
diff --git a/spec/lib/gitlab/ci/pipeline/seed/environment_spec.rb b/spec/lib/gitlab/ci/pipeline/seed/environment_spec.rb
deleted file mode 100644
index 2b9d8127886..00000000000
--- a/spec/lib/gitlab/ci/pipeline/seed/environment_spec.rb
+++ /dev/null
@@ -1,224 +0,0 @@
-# frozen_string_literal: true
-
-require 'spec_helper'
-
-RSpec.describe Gitlab::Ci::Pipeline::Seed::Environment do
- let_it_be(:project) { create(:project) }
-
- let!(:pipeline) { create(:ci_pipeline, project: project) }
-
- let(:job) { build(:ci_build, project: project, pipeline: pipeline) }
- let(:seed) { described_class.new(job) }
- let(:attributes) { {} }
-
- before do
- job.assign_attributes(**attributes)
- end
-
- describe '#to_resource' do
- subject { seed.to_resource }
-
- shared_examples_for 'returning a correct environment' do
- let(:expected_auto_stop_in_seconds) do
- if expected_auto_stop_in
- ChronicDuration.parse(expected_auto_stop_in).seconds
- end
- end
-
- it 'returns a persisted environment object' do
- freeze_time do
- expect { subject }.to change { Environment.count }.by(1)
-
- expect(subject).to be_a(Environment)
- expect(subject).to be_persisted
- expect(subject.project).to eq(project)
- expect(subject.name).to eq(expected_environment_name)
- expect(subject.auto_stop_in).to eq(expected_auto_stop_in_seconds)
- end
- end
-
- context 'when environment has already existed' do
- let!(:environment) do
- create(:environment,
- project: project,
- name: expected_environment_name
- ).tap do |env|
- env.auto_stop_in = expected_auto_stop_in
- end
- end
-
- it 'returns the existing environment object' do
- expect { subject }.not_to change { Environment.count }
- expect { subject }.not_to change { environment.auto_stop_at }
-
- expect(subject).to be_persisted
- expect(subject).to eq(environment)
- end
- end
- end
-
- context 'when job has environment name attribute' do
- let(:environment_name) { 'production' }
- let(:expected_environment_name) { 'production' }
- let(:expected_auto_stop_in) { nil }
-
- let(:attributes) do
- {
- environment: environment_name,
- options: { environment: { name: environment_name } }
- }
- end
-
- it_behaves_like 'returning a correct environment'
-
- context 'and job environment also has an auto_stop_in attribute' do
- let(:environment_auto_stop_in) { '5 minutes' }
- let(:expected_auto_stop_in) { '5 minutes' }
-
- let(:attributes) do
- {
- environment: environment_name,
- options: {
- environment: {
- name: environment_name,
- auto_stop_in: environment_auto_stop_in
- }
- }
- }
- end
-
- it_behaves_like 'returning a correct environment'
- end
-
- context 'and job environment has an auto_stop_in variable attribute' do
- let(:environment_auto_stop_in) { '10 minutes' }
- let(:expected_auto_stop_in) { '10 minutes' }
-
- let(:attributes) do
- {
- environment: environment_name,
- options: {
- environment: {
- name: environment_name,
- auto_stop_in: '$TTL'
- }
- },
- yaml_variables: [
- { key: "TTL", value: environment_auto_stop_in, public: true }
- ]
- }
- end
-
- it_behaves_like 'returning a correct environment'
- end
- end
-
- context 'when job has deployment tier attribute' do
- let(:attributes) do
- {
- environment: 'customer-portal',
- options: {
- environment: {
- name: 'customer-portal',
- deployment_tier: deployment_tier
- }
- }
- }
- end
-
- let(:deployment_tier) { 'production' }
-
- context 'when environment has not been created yet' do
- it 'sets the specified deployment tier' do
- is_expected.to be_production
- end
-
- context 'when deployment tier is staging' do
- let(:deployment_tier) { 'staging' }
-
- it 'sets the specified deployment tier' do
- is_expected.to be_staging
- end
- end
-
- context 'when deployment tier is unknown' do
- let(:deployment_tier) { 'unknown' }
-
- it 'raises an error' do
- expect { subject }.to raise_error(ArgumentError, "'unknown' is not a valid tier")
- end
- end
- end
-
- context 'when environment has already been created' do
- before do
- create(:environment, project: project, name: 'customer-portal', tier: :staging)
- end
-
- it 'does not overwrite the specified deployment tier' do
- # This is to be updated when a deployment succeeded i.e. Deployments::UpdateEnvironmentService.
- is_expected.to be_staging
- end
- end
- end
-
- context 'when job starts a review app' do
- let(:environment_name) { 'review/$CI_COMMIT_REF_NAME' }
- let(:expected_environment_name) { "review/#{job.ref}" }
- let(:expected_auto_stop_in) { nil }
-
- let(:attributes) do
- {
- environment: environment_name,
- options: { environment: { name: environment_name } }
- }
- end
-
- it_behaves_like 'returning a correct environment'
- end
-
- context 'when job stops a review app' do
- let(:environment_name) { 'review/$CI_COMMIT_REF_NAME' }
- let(:expected_environment_name) { "review/#{job.ref}" }
- let(:expected_auto_stop_in) { nil }
-
- let(:attributes) do
- {
- environment: environment_name,
- options: { environment: { name: environment_name, action: 'stop' } }
- }
- end
-
- it_behaves_like 'returning a correct environment'
- end
-
- context 'when merge_request is provided' do
- let(:environment_name) { 'development' }
- let(:attributes) { { environment: environment_name, options: { environment: { name: environment_name } } } }
- let(:merge_request) { create(:merge_request, source_project: project) }
- let(:seed) { described_class.new(job, merge_request: merge_request) }
-
- context 'and environment does not exist' do
- let(:environment_name) { 'review/$CI_COMMIT_REF_NAME' }
-
- it 'creates an environment associated with the merge request' do
- expect { subject }.to change { Environment.count }.by(1)
-
- expect(subject.merge_request).to eq(merge_request)
- end
- end
-
- context 'and environment already exists' do
- before do
- create(:environment, project: project, name: environment_name)
- end
-
- it 'does not change the merge request associated with the environment' do
- expect { subject }.not_to change { Environment.count }
-
- expect(subject.merge_request).to be_nil
- end
- end
- end
- end
-end
diff --git a/spec/lib/gitlab/ci/pipeline/seed/pipeline_spec.rb b/spec/lib/gitlab/ci/pipeline/seed/pipeline_spec.rb
index a76b4874eca..55980ae72a0 100644
--- a/spec/lib/gitlab/ci/pipeline/seed/pipeline_spec.rb
+++ b/spec/lib/gitlab/ci/pipeline/seed/pipeline_spec.rb
@@ -6,7 +6,9 @@ RSpec.describe Gitlab::Ci::Pipeline::Seed::Pipeline do
let_it_be(:project) { create(:project, :repository) }
let_it_be(:pipeline) { create(:ci_pipeline, project: project) }
- let(:seed_context) { Gitlab::Ci::Pipeline::Seed::Context.new(pipeline, root_variables: []) }
+ let(:root_variables) { [] }
+
+ let(:seed_context) { Gitlab::Ci::Pipeline::Seed::Context.new(pipeline, root_variables: root_variables) }
let(:stages_attributes) do
[
@@ -75,4 +77,12 @@ RSpec.describe Gitlab::Ci::Pipeline::Seed::Pipeline do
expect(seed.deployments_count).to eq(2)
end
end
+
+ describe '#root_variables' do
+ let(:root_variables) { %w[var1 value1] }
+
+ it 'returns root_variables' do
+ expect(seed.root_variables).to eq(root_variables)
+ end
+ end
end