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
path: root/spec
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-03-04 03:07:52 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2020-03-04 03:07:52 +0300
commit4fe93274dec62ff7361a67be88e320131d66b788 (patch)
tree98ae79e3101ffd6569fc48bb4c7ad8808540ceb8 /spec
parentbbaf2bb0438b1c71020d9d216feb528add225a7f (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
-rw-r--r--spec/factories/ci/builds.rb3
-rw-r--r--spec/graphql/types/base_field_spec.rb2
-rw-r--r--spec/lib/gitlab/ci/pipeline/seed/build_spec.rb88
-rw-r--r--spec/lib/gitlab/ci/pipeline/seed/deployment_spec.rb11
-rw-r--r--spec/lib/gitlab/ci/pipeline/seed/environment_spec.rb59
-rw-r--r--spec/models/ci/build_spec.rb30
-rw-r--r--spec/models/concerns/issuable_spec.rb2
-rw-r--r--spec/services/ci/retry_build_service_spec.rb4
8 files changed, 176 insertions, 23 deletions
diff --git a/spec/factories/ci/builds.rb b/spec/factories/ci/builds.rb
index 5127d55645c..b6f18240b9e 100644
--- a/spec/factories/ci/builds.rb
+++ b/spec/factories/ci/builds.rb
@@ -230,8 +230,9 @@ FactoryBot.define do
# Build deployment/environment relations if environment name is set
# to the job. If `build.deployment` has already been set, it doesn't
# build a new instance.
+ environment = Gitlab::Ci::Pipeline::Seed::Environment.new(build).to_resource
build.deployment =
- Gitlab::Ci::Pipeline::Seed::Deployment.new(build).to_resource
+ Gitlab::Ci::Pipeline::Seed::Deployment.new(build, environment).to_resource
end
end
diff --git a/spec/graphql/types/base_field_spec.rb b/spec/graphql/types/base_field_spec.rb
index 9e5f6dd2037..2547d39bcb2 100644
--- a/spec/graphql/types/base_field_spec.rb
+++ b/spec/graphql/types/base_field_spec.rb
@@ -174,7 +174,7 @@ describe Types::BaseField do
let(:flag) { :test_flag }
it 'prepends the description' do
- expect(field.description). to eq 'Test description. Available only when feature flag test_flag is enabled.'
+ expect(field.description). to eq 'Test description. Available only when feature flag `test_flag` is enabled.'
end
context 'falsey feature_flag values' do
diff --git a/spec/lib/gitlab/ci/pipeline/seed/build_spec.rb b/spec/lib/gitlab/ci/pipeline/seed/build_spec.rb
index 1f5fc000832..01f65939da7 100644
--- a/spec/lib/gitlab/ci/pipeline/seed/build_spec.rb
+++ b/spec/lib/gitlab/ci/pipeline/seed/build_spec.rb
@@ -214,24 +214,98 @@ describe Gitlab::Ci::Pipeline::Seed::Build do
it { is_expected.to be_a(::Ci::Build) }
it { is_expected.to be_valid }
- context 'when job has environment name' do
- let(:attributes) { { name: 'rspec', ref: 'master', environment: 'production' } }
-
+ shared_examples_for 'deployment job' do
it 'returns a job with deployment' do
expect(subject.deployment).not_to be_nil
expect(subject.deployment.deployable).to eq(subject)
- expect(subject.deployment.environment.name).to eq('production')
+ expect(subject.deployment.environment.name).to eq(expected_environment_name)
end
+ end
+
+ shared_examples_for 'non-deployment job' do
+ it 'returns a job without deployment' do
+ expect(subject.deployment).to be_nil
+ end
+ end
+
+ shared_examples_for 'ensures environment existence' do
+ it 'has environment' do
+ expect(subject).to be_has_environment
+ expect(subject.environment).to eq(environment_name)
+ expect(subject.metadata.expanded_environment_name).to eq(expected_environment_name)
+ expect(Environment.exists?(name: expected_environment_name)).to eq(true)
+ end
+ end
+
+ shared_examples_for 'ensures environment inexistence' do
+ it 'does not have environment' do
+ expect(subject).not_to be_has_environment
+ expect(subject.environment).to be_nil
+ expect(subject.metadata.expanded_environment_name).to be_nil
+ expect(Environment.exists?(name: expected_environment_name)).to eq(false)
+ end
+ end
+
+ context 'when job deploys to production' do
+ let(:environment_name) { 'production' }
+ let(:expected_environment_name) { 'production' }
+ let(:attributes) { { name: 'deploy', ref: 'master', environment: 'production' } }
+
+ it_behaves_like 'deployment job'
+ it_behaves_like 'ensures environment existence'
context 'when the environment name is invalid' do
- let(:attributes) { { name: 'rspec', ref: 'master', environment: '!!!' } }
+ let(:attributes) { { name: 'deploy', ref: 'master', environment: '!!!' } }
- it 'returns a job without deployment' do
- expect(subject.deployment).to be_nil
+ it_behaves_like 'non-deployment job'
+ it_behaves_like 'ensures environment inexistence'
+
+ it 'tracks an exception' do
+ expect(Gitlab::ErrorTracking).to receive(:track_exception)
+ .with(an_instance_of(described_class::EnvironmentCreationFailure),
+ project_id: project.id,
+ reason: %q{Name can contain only letters, digits, '-', '_', '/', '$', '{', '}', '.', and spaces, but it cannot start or end with '/'})
+ .once
+
+ subject
end
end
end
+ context 'when job starts a review app' do
+ let(:environment_name) { 'review/$CI_COMMIT_REF_NAME' }
+ let(:expected_environment_name) { "review/#{pipeline.ref}" }
+
+ let(:attributes) do
+ {
+ name: 'deploy', ref: 'master', environment: environment_name,
+ options: { environment: { name: environment_name } }
+ }
+ end
+
+ it_behaves_like 'deployment job'
+ it_behaves_like 'ensures environment existence'
+ end
+
+ context 'when job stops a review app' do
+ let(:environment_name) { 'review/$CI_COMMIT_REF_NAME' }
+ let(:expected_environment_name) { "review/#{pipeline.ref}" }
+
+ let(:attributes) do
+ {
+ name: 'deploy', ref: 'master', environment: environment_name,
+ options: { environment: { name: environment_name, action: 'stop' } }
+ }
+ end
+
+ it 'returns a job without deployment' do
+ expect(subject.deployment).to be_nil
+ end
+
+ it_behaves_like 'non-deployment job'
+ it_behaves_like 'ensures environment existence'
+ end
+
context 'when job belongs to a resource group' do
let(:attributes) { { name: 'rspec', ref: 'master', resource_group_key: 'iOS' } }
diff --git a/spec/lib/gitlab/ci/pipeline/seed/deployment_spec.rb b/spec/lib/gitlab/ci/pipeline/seed/deployment_spec.rb
index c5c91135f60..8d097bdd740 100644
--- a/spec/lib/gitlab/ci/pipeline/seed/deployment_spec.rb
+++ b/spec/lib/gitlab/ci/pipeline/seed/deployment_spec.rb
@@ -10,7 +10,8 @@ describe Gitlab::Ci::Pipeline::Seed::Deployment do
end
let(:job) { build(:ci_build, project: project, pipeline: pipeline) }
- let(:seed) { described_class.new(job) }
+ let(:environment) { Gitlab::Ci::Pipeline::Seed::Environment.new(job).to_resource }
+ let(:seed) { described_class.new(job, environment) }
let(:attributes) { {} }
before do
@@ -82,5 +83,13 @@ describe Gitlab::Ci::Pipeline::Seed::Deployment do
is_expected.to be_nil
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
index 71389999c6e..4c0464e5e7c 100644
--- a/spec/lib/gitlab/ci/pipeline/seed/environment_spec.rb
+++ b/spec/lib/gitlab/ci/pipeline/seed/environment_spec.rb
@@ -15,29 +15,68 @@ describe Gitlab::Ci::Pipeline::Seed::Environment do
describe '#to_resource' do
subject { seed.to_resource }
- context 'when job has environment attribute' do
- let(:attributes) do
- {
- environment: 'production',
- options: { environment: { name: 'production' } }
- }
- end
-
+ shared_examples_for 'returning a correct environment' do
it 'returns a persisted environment object' 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('production')
+ expect(subject.name).to eq(expected_environment_name)
end
context 'when environment has already existed' do
- let!(:environment) { create(:environment, project: project, name: 'production') }
+ let!(:environment) { create(:environment, project: project, name: expected_environment_name) }
it 'returns the existing environment object' do
+ expect { subject }.not_to change { Environment.count }
+
expect(subject).to be_persisted
expect(subject).to eq(environment)
end
end
end
+
+ context 'when job has environment attribute' do
+ let(:environment_name) { 'production' }
+ let(:expected_environment_name) { 'production' }
+
+ let(:attributes) do
+ {
+ environment: environment_name,
+ options: { environment: { name: environment_name } }
+ }
+ end
+
+ it_behaves_like 'returning a correct environment'
+ 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(: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(:attributes) do
+ {
+ environment: environment_name,
+ options: { environment: { name: environment_name, action: 'stop' } }
+ }
+ end
+
+ it_behaves_like 'returning a correct environment'
+ end
end
end
diff --git a/spec/models/ci/build_spec.rb b/spec/models/ci/build_spec.rb
index 37219365ecf..757c158e16a 100644
--- a/spec/models/ci/build_spec.rb
+++ b/spec/models/ci/build_spec.rb
@@ -1293,7 +1293,35 @@ describe Ci::Build do
environment: 'review/$APP_HOST')
end
- it { is_expected.to eq('review/host') }
+ it 'returns an expanded environment name with a list of variables' do
+ expect(build).to receive(:simple_variables).once.and_call_original
+
+ is_expected.to eq('review/host')
+ end
+
+ context 'when build metadata has already persisted the expanded environment name' do
+ before do
+ build.metadata.expanded_environment_name = 'review/host'
+ end
+
+ it 'returns a persisted expanded environment name without a list of variables' do
+ expect(build).not_to receive(:simple_variables)
+
+ is_expected.to eq('review/host')
+ end
+
+ context 'when ci_persisted_expanded_environment_name feature flag is disabled' do
+ before do
+ stub_feature_flags(ci_persisted_expanded_environment_name: false)
+ end
+
+ it 'returns an expanded environment name with a list of variables' do
+ expect(build).to receive(:simple_variables).once.and_call_original
+
+ is_expected.to eq('review/host')
+ end
+ end
+ end
end
context 'when using persisted variables' do
diff --git a/spec/models/concerns/issuable_spec.rb b/spec/models/concerns/issuable_spec.rb
index 3e5c16c2491..4ecbc671c72 100644
--- a/spec/models/concerns/issuable_spec.rb
+++ b/spec/models/concerns/issuable_spec.rb
@@ -56,8 +56,6 @@ describe Issuable do
end
describe "Scope" do
- subject { build(:issue) }
-
it { expect(issuable_class).to respond_to(:opened) }
it { expect(issuable_class).to respond_to(:closed) }
it { expect(issuable_class).to respond_to(:assigned) }
diff --git a/spec/services/ci/retry_build_service_spec.rb b/spec/services/ci/retry_build_service_spec.rb
index 188271f4a75..8a22b2c8da3 100644
--- a/spec/services/ci/retry_build_service_spec.rb
+++ b/spec/services/ci/retry_build_service_spec.rb
@@ -238,6 +238,10 @@ describe Ci::RetryBuildService do
it 'creates a new deployment' do
expect { new_build }.to change { Deployment.count }.by(1)
end
+
+ it 'persists expanded environment name' do
+ expect(new_build.metadata.expanded_environment_name).to eq('production')
+ end
end
context 'when scheduling_type of build is nil' do