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/models/ci/build_spec.rb')
-rw-r--r--spec/models/ci/build_spec.rb179
1 files changed, 79 insertions, 100 deletions
diff --git a/spec/models/ci/build_spec.rb b/spec/models/ci/build_spec.rb
index a556244ae00..2a5d781edc7 100644
--- a/spec/models/ci/build_spec.rb
+++ b/spec/models/ci/build_spec.rb
@@ -3,6 +3,7 @@
require 'spec_helper'
RSpec.describe Ci::Build, feature_category: :continuous_integration, factory_default: :keep do
+ using RSpec::Parameterized::TableSyntax
include Ci::TemplateHelpers
include AfterNextHelpers
@@ -1493,8 +1494,6 @@ RSpec.describe Ci::Build, feature_category: :continuous_integration, factory_def
end
describe 'state transition metrics' do
- using RSpec::Parameterized::TableSyntax
-
subject { build.send(event) }
where(:state, :report_count, :trait) do
@@ -2129,8 +2128,6 @@ RSpec.describe Ci::Build, feature_category: :continuous_integration, factory_def
end
describe '#ref_slug' do
- using RSpec::Parameterized::TableSyntax
-
where(:ref, :slug) do
'master' | 'master'
'1-foo' | '1-foo'
@@ -2468,8 +2465,7 @@ RSpec.describe Ci::Build, feature_category: :continuous_integration, factory_def
context 'when build has environment and user-provided variables' do
let(:expected_variables) do
predefined_variables.map { |variable| variable.fetch(:key) } +
- %w[YAML_VARIABLE CI_ENVIRONMENT_NAME CI_ENVIRONMENT_SLUG
- CI_ENVIRONMENT_ACTION CI_ENVIRONMENT_TIER CI_ENVIRONMENT_URL]
+ %w[YAML_VARIABLE CI_ENVIRONMENT_SLUG CI_ENVIRONMENT_URL]
end
before do
@@ -2478,8 +2474,14 @@ RSpec.describe Ci::Build, feature_category: :continuous_integration, factory_def
build.yaml_variables = [{ key: 'YAML_VARIABLE', value: 'var', public: true }]
build.environment = 'staging'
- # CI_ENVIRONMENT_NAME is set in predefined_variables when job environment is provided
- predefined_variables.insert(18, { key: 'CI_ENVIRONMENT_NAME', value: 'staging', public: true, masked: false })
+ insert_expected_predefined_variables(
+ [
+ { key: 'CI_ENVIRONMENT_NAME', value: 'staging', public: true, masked: false },
+ { key: 'CI_ENVIRONMENT_ACTION', value: 'start', public: true, masked: false },
+ { key: 'CI_ENVIRONMENT_TIER', value: 'staging', public: true, masked: false },
+ { key: 'CI_ENVIRONMENT_URL', value: 'https://gitlab.com', public: true, masked: false }
+ ],
+ after: 'CI_NODE_TOTAL')
end
it 'matches explicit variables ordering' do
@@ -2550,6 +2552,11 @@ RSpec.describe Ci::Build, feature_category: :continuous_integration, factory_def
expect(runner_vars).not_to include('CI_JOB_JWT_V2')
end
end
+
+ def insert_expected_predefined_variables(variables, after:)
+ index = predefined_variables.index { |h| h[:key] == after }
+ predefined_variables.insert(index + 1, *variables)
+ end
end
context 'when build has user' do
@@ -2583,34 +2590,28 @@ RSpec.describe Ci::Build, feature_category: :continuous_integration, factory_def
end
context 'when build has an environment' do
- let(:environment_variables) do
+ let(:expected_environment_variables) do
[
{ key: 'CI_ENVIRONMENT_NAME', value: 'production', public: true, masked: false },
- { key: 'CI_ENVIRONMENT_SLUG', value: 'prod-slug', public: true, masked: false },
- { key: 'CI_ENVIRONMENT_TIER', value: 'production', public: true, masked: false }
+ { key: 'CI_ENVIRONMENT_ACTION', value: 'start', public: true, masked: false },
+ { key: 'CI_ENVIRONMENT_TIER', value: 'production', public: true, masked: false },
+ { key: 'CI_ENVIRONMENT_URL', value: 'http://prd.example.com/$CI_JOB_NAME', public: true, masked: false }
]
end
- let!(:environment) do
- create(
- :environment,
- project: build.project,
- name: 'production',
- slug: 'prod-slug',
- tier: 'production',
- external_url: ''
- )
- end
-
- before do
- build.update!(environment: 'production')
- end
+ let(:build) { create(:ci_build, :with_deployment, :deploy_to_production, ref: pipeline.ref, pipeline: pipeline) }
shared_examples 'containing environment variables' do
- it { is_expected.to include(*environment_variables) }
+ it { is_expected.to include(*expected_environment_variables) }
end
context 'when no URL was set' do
+ before do
+ build.update!(options: { environment: { url: nil } })
+ build.persisted_environment.update!(external_url: nil)
+ expected_environment_variables.delete_if { |var| var[:key] == 'CI_ENVIRONMENT_URL' }
+ end
+
it_behaves_like 'containing environment variables'
it 'does not have CI_ENVIRONMENT_URL' do
@@ -2620,12 +2621,26 @@ RSpec.describe Ci::Build, feature_category: :continuous_integration, factory_def
end
end
+ context 'when environment is created dynamically' do
+ let(:build) { create(:ci_build, :with_deployment, :start_review_app, ref: pipeline.ref, pipeline: pipeline) }
+
+ let(:expected_environment_variables) do
+ [
+ { key: 'CI_ENVIRONMENT_NAME', value: 'review/master', public: true, masked: false },
+ { key: 'CI_ENVIRONMENT_ACTION', value: 'start', public: true, masked: false },
+ { key: 'CI_ENVIRONMENT_TIER', value: 'development', public: true, masked: false },
+ { key: 'CI_ENVIRONMENT_URL', value: 'http://staging.example.com/$CI_JOB_NAME', public: true, masked: false }
+ ]
+ end
+
+ it_behaves_like 'containing environment variables'
+ end
+
context 'when an URL was set' do
let(:url) { 'http://host/test' }
before do
- environment_variables <<
- { key: 'CI_ENVIRONMENT_URL', value: url, public: true, masked: false }
+ expected_environment_variables.find { |var| var[:key] == 'CI_ENVIRONMENT_URL' }[:value] = url
end
context 'when the URL was set from the job' do
@@ -2641,14 +2656,15 @@ RSpec.describe Ci::Build, feature_category: :continuous_integration, factory_def
it_behaves_like 'containing environment variables'
it 'puts $CI_ENVIRONMENT_URL in the last so all other variables are available to be used when runners are trying to expand it' do
- expect(subject.to_runner_variables.last).to eq(environment_variables.last)
+ expect(subject.to_runner_variables.last).to eq(expected_environment_variables.last)
end
end
end
context 'when the URL was not set from the job, but environment' do
before do
- environment.update!(external_url: url)
+ build.update!(options: { environment: { url: nil } })
+ build.persisted_environment.update!(external_url: url)
end
it_behaves_like 'containing environment variables'
@@ -2682,10 +2698,7 @@ RSpec.describe Ci::Build, feature_category: :continuous_integration, factory_def
end
context 'when environment scope matches build environment' do
- before do
- create(:environment, name: 'staging', project: project)
- build.update!(environment: 'staging')
- end
+ let(:build) { create(:ci_build, :with_deployment, :start_staging, ref: pipeline.ref, pipeline: pipeline) }
it { is_expected.to include(environment_specific_variable) }
end
@@ -4001,73 +4014,61 @@ RSpec.describe Ci::Build, feature_category: :continuous_integration, factory_def
end
end
- describe 'pages deployments' do
- let_it_be(:build, reload: true) { create(:ci_build, pipeline: pipeline, user: user) }
+ describe '#pages_generator?', feature_category: :pages do
+ where(:name, :enabled, :result) do
+ 'foo' | false | false
+ 'pages' | false | false
+ 'pages:preview' | true | false
+ 'pages' | true | true
+ end
- context 'when job is "pages"' do
+ with_them do
before do
- build.name = 'pages'
+ stub_pages_setting(enabled: enabled)
+ build.update!(name: name)
end
- context 'when pages are enabled' do
- before do
- allow(Gitlab.config.pages).to receive_messages(enabled: true)
- end
-
- it 'is marked as pages generator' do
- expect(build).to be_pages_generator
- end
-
- context 'job succeeds' do
- it "calls pages worker" do
- expect(PagesWorker).to receive(:perform_async).with(:deploy, build.id)
+ subject { build.pages_generator? }
- build.success!
- end
- end
+ it { is_expected.to eq(result) }
+ end
+ end
- context 'job fails' do
- it "does not call pages worker" do
- expect(PagesWorker).not_to receive(:perform_async)
+ describe 'pages deployments', feature_category: :pages do
+ let_it_be(:build, reload: true) { create(:ci_build, name: 'pages', pipeline: pipeline, user: user) }
- build.drop!
- end
- end
+ context 'when pages are enabled' do
+ before do
+ stub_pages_setting(enabled: true)
end
- context 'when pages are disabled' do
- before do
- allow(Gitlab.config.pages).to receive_messages(enabled: false)
- end
+ context 'and job succeeds' do
+ it "calls pages worker" do
+ expect(PagesWorker).to receive(:perform_async).with(:deploy, build.id)
- it 'is not marked as pages generator' do
- expect(build).not_to be_pages_generator
+ build.success!
end
+ end
- context 'job succeeds' do
- it "does not call pages worker" do
- expect(PagesWorker).not_to receive(:perform_async)
+ context 'and job fails' do
+ it "does not call pages worker" do
+ expect(PagesWorker).not_to receive(:perform_async)
- build.success!
- end
+ build.drop!
end
end
end
- context 'when job is not "pages"' do
+ context 'when pages are disabled' do
before do
- build.name = 'other-job'
+ stub_pages_setting(enabled: false)
end
- it 'is not marked as pages generator' do
- expect(build).not_to be_pages_generator
- end
-
- context 'job succeeds' do
+ context 'and job succeeds' do
it "does not call pages worker" do
expect(PagesWorker).not_to receive(:perform_async)
- build.success
+ build.success!
end
end
end
@@ -5604,26 +5605,4 @@ RSpec.describe Ci::Build, feature_category: :continuous_integration, factory_def
end
end
end
-
- describe 'routing table switch' do
- context 'with ff disabled' do
- before do
- stub_feature_flags(ci_partitioning_use_ci_builds_routing_table: false)
- end
-
- it 'uses the legacy table' do
- expect(described_class.table_name).to eq('ci_builds')
- end
- end
-
- context 'with ff enabled' do
- before do
- stub_feature_flags(ci_partitioning_use_ci_builds_routing_table: true)
- end
-
- it 'uses the routing table' do
- expect(described_class.table_name).to eq('p_ci_builds')
- end
- end
- end
end