summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2022-09-21 09:14:34 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2022-09-21 09:14:34 +0000
commit7e5c81990bbb0b78542092b0a92e159a677375d4 (patch)
tree1f151fbb2a2e11bf7d7718fc04ec6ef4bb4552dd /spec
parent935dea5995316a570bf9204d00f9bf30466cb2c9 (diff)
downloadgitlab-ce-7e5c81990bbb0b78542092b0a92e159a677375d4.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
-rw-r--r--spec/lib/container_registry/gitlab_api_client_spec.rb11
-rw-r--r--spec/migrations/finalize_invalid_group_member_cleanup_spec.rb72
-rw-r--r--spec/migrations/finalize_invalid_project_member_cleanup_spec.rb72
-rw-r--r--spec/requests/api/admin/batched_background_migrations_spec.rb22
-rw-r--r--spec/serializers/deployment_entity_spec.rb68
-rw-r--r--spec/serializers/environment_status_entity_spec.rb35
-rw-r--r--spec/support/rspec_order_todo.yml2
7 files changed, 226 insertions, 56 deletions
diff --git a/spec/lib/container_registry/gitlab_api_client_spec.rb b/spec/lib/container_registry/gitlab_api_client_spec.rb
index f19bedbda0e..7d78aad8b13 100644
--- a/spec/lib/container_registry/gitlab_api_client_spec.rb
+++ b/spec/lib/container_registry/gitlab_api_client_spec.rb
@@ -307,7 +307,16 @@ RSpec.describe ContainerRegistry::GitlabApiClient do
stub_tags(path, page_size: page_size, status_code: 404)
end
- it { is_expected.to eq({}) }
+ it 'logs an error and returns an empty hash' do
+ expect(Gitlab::ErrorTracking)
+ .to receive(:log_exception).with(
+ instance_of(described_class::UnsuccessfulResponseError),
+ class: described_class.name,
+ url: "/gitlab/v1/repositories/#{path}/tags/list/",
+ status_code: 404
+ )
+ expect(subject).to eq({})
+ end
end
end
diff --git a/spec/migrations/finalize_invalid_group_member_cleanup_spec.rb b/spec/migrations/finalize_invalid_group_member_cleanup_spec.rb
new file mode 100644
index 00000000000..c63f0035643
--- /dev/null
+++ b/spec/migrations/finalize_invalid_group_member_cleanup_spec.rb
@@ -0,0 +1,72 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+require_migration!
+
+RSpec.describe FinalizeInvalidGroupMemberCleanup, :migration do
+ let(:batched_migrations) { table(:batched_background_migrations) }
+
+ let_it_be(:migration) { described_class::MIGRATION }
+
+ describe '#up' do
+ shared_examples 'finalizes the migration' do
+ it 'finalizes the migration' do
+ allow_next_instance_of(Gitlab::Database::BackgroundMigration::BatchedMigrationRunner) do |runner|
+ expect(runner).to receive(:finalize).with('DestroyInvalidGroupMembers', :members, :id, [])
+ end
+ end
+ end
+
+ context 'when migration is missing' do
+ it 'warns migration not found' do
+ expect(Gitlab::AppLogger)
+ .to receive(:warn).with(/Could not find batched background migration for the given configuration:/)
+
+ migrate!
+ end
+ end
+
+ context 'with migration present' do
+ let!(:destroy_invalid_group_member_migration) do
+ batched_migrations.create!(
+ job_class_name: 'DestroyInvalidGroupMembers',
+ table_name: :members,
+ column_name: :id,
+ job_arguments: [],
+ interval: 2.minutes,
+ min_value: 1,
+ max_value: 2,
+ batch_size: 1000,
+ sub_batch_size: 200,
+ gitlab_schema: :gitlab_main,
+ status: 3 # finished
+ )
+ end
+
+ context 'when migration finished successfully' do
+ it 'does not raise exception' do
+ expect { migrate! }.not_to raise_error
+ end
+ end
+
+ context 'with different migration statuses' do
+ using RSpec::Parameterized::TableSyntax
+
+ where(:status, :description) do
+ 0 | 'paused'
+ 1 | 'active'
+ 4 | 'failed'
+ 5 | 'finalizing'
+ end
+
+ with_them do
+ before do
+ destroy_invalid_group_member_migration.update!(status: status)
+ end
+
+ it_behaves_like 'finalizes the migration'
+ end
+ end
+ end
+ end
+end
diff --git a/spec/migrations/finalize_invalid_project_member_cleanup_spec.rb b/spec/migrations/finalize_invalid_project_member_cleanup_spec.rb
new file mode 100644
index 00000000000..a5d3467bb5b
--- /dev/null
+++ b/spec/migrations/finalize_invalid_project_member_cleanup_spec.rb
@@ -0,0 +1,72 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+require_migration!
+
+RSpec.describe FinalizeInvalidProjectMemberCleanup, :migration do
+ let(:batched_migrations) { table(:batched_background_migrations) }
+
+ let_it_be(:migration) { described_class::MIGRATION }
+
+ describe '#up' do
+ shared_examples 'finalizes the migration' do
+ it 'finalizes the migration' do
+ allow_next_instance_of(Gitlab::Database::BackgroundMigration::BatchedMigrationRunner) do |runner|
+ expect(runner).to receive(:finalize).with('DestroyInvalidProjectMembers', :members, :id, [])
+ end
+ end
+ end
+
+ context 'when migration is missing' do
+ it 'warns migration not found' do
+ expect(Gitlab::AppLogger)
+ .to receive(:warn).with(/Could not find batched background migration for the given configuration:/)
+
+ migrate!
+ end
+ end
+
+ context 'with migration present' do
+ let!(:destroy_invalid_project_member_migration) do
+ batched_migrations.create!(
+ job_class_name: 'DestroyInvalidProjectMembers',
+ table_name: :members,
+ column_name: :id,
+ job_arguments: [],
+ interval: 2.minutes,
+ min_value: 1,
+ max_value: 2,
+ batch_size: 1000,
+ sub_batch_size: 200,
+ gitlab_schema: :gitlab_main,
+ status: 3 # finished
+ )
+ end
+
+ context 'when migration finished successfully' do
+ it 'does not raise exception' do
+ expect { migrate! }.not_to raise_error
+ end
+ end
+
+ context 'with different migration statuses' do
+ using RSpec::Parameterized::TableSyntax
+
+ where(:status, :description) do
+ 0 | 'paused'
+ 1 | 'active'
+ 4 | 'failed'
+ 5 | 'finalizing'
+ end
+
+ with_them do
+ before do
+ destroy_invalid_project_member_migration.update!(status: status)
+ end
+
+ it_behaves_like 'finalizes the migration'
+ end
+ end
+ end
+ end
+end
diff --git a/spec/requests/api/admin/batched_background_migrations_spec.rb b/spec/requests/api/admin/batched_background_migrations_spec.rb
index c99b21c0c27..f4767a87d30 100644
--- a/spec/requests/api/admin/batched_background_migrations_spec.rb
+++ b/spec/requests/api/admin/batched_background_migrations_spec.rb
@@ -158,6 +158,17 @@ RSpec.describe API::Admin::BatchedBackgroundMigrations do
end
end
+ context 'when the migration is not paused' do
+ let!(:migration) { create(:batched_background_migration, :failed) }
+ let(:params) { { database: database } }
+
+ it 'returns 422' do
+ put api("/admin/batched_background_migrations/#{migration.id}/resume", admin), params: params
+
+ expect(response).to have_gitlab_http_status(:unprocessable_entity)
+ end
+ end
+
context 'when multiple database is enabled' do
let(:ci_model) { Ci::ApplicationRecord }
let(:database) { :ci }
@@ -205,6 +216,17 @@ RSpec.describe API::Admin::BatchedBackgroundMigrations do
end
end
+ context 'when the migration is not active' do
+ let!(:migration) { create(:batched_background_migration, :failed) }
+ let(:params) { { database: :main } }
+
+ it 'returns 422' do
+ put api("/admin/batched_background_migrations/#{migration.id}/pause", admin), params: params
+
+ expect(response).to have_gitlab_http_status(:unprocessable_entity)
+ end
+ end
+
context 'when multiple database is enabled' do
let(:ci_model) { Ci::ApplicationRecord }
diff --git a/spec/serializers/deployment_entity_spec.rb b/spec/serializers/deployment_entity_spec.rb
index 433ce344680..d95aa882a64 100644
--- a/spec/serializers/deployment_entity_spec.rb
+++ b/spec/serializers/deployment_entity_spec.rb
@@ -3,56 +3,47 @@
require 'spec_helper'
RSpec.describe DeploymentEntity do
- let(:user) { developer }
- let(:developer) { create(:user) }
- let(:reporter) { create(:user) }
- let(:project) { create(:project, :repository) }
+ let_it_be(:developer) { create(:user) }
+ let_it_be(:reporter) { create(:user) }
+ let_it_be(:user) { developer }
+ let_it_be(:project) { create(:project, :repository) }
+ let_it_be(:environment) { create(:environment, project: project) }
+ let_it_be_with_reload(:pipeline) { create(:ci_pipeline, project: project, user: user) }
+ let_it_be_with_reload(:build) { create(:ci_build, :manual, :environment_with_deployment_tier, pipeline: pipeline) }
+
+ let_it_be_with_refind(:deployment) { create(:deployment, deployable: build, environment: environment) }
+
let(:request) { double('request') }
- let(:deployment) { create(:deployment, deployable: build, project: project) }
- let(:build) { create(:ci_build, :manual, :environment_with_deployment_tier, pipeline: pipeline) }
- let(:pipeline) { create(:ci_pipeline, project: project, user: user) }
let(:entity) { described_class.new(deployment, request: request) }
subject { entity.as_json }
- before do
+ before_all do
project.add_developer(developer)
project.add_reporter(reporter)
+ end
+
+ before do
allow(request).to receive(:current_user).and_return(user)
allow(request).to receive(:project).and_return(project)
end
- it 'exposes internal deployment id' do
+ it 'exposes fields', :aggregate_failures do
expect(subject).to include(:iid)
- end
-
- it 'exposes nested information about branch' do
expect(subject[:ref][:name]).to eq 'master'
- end
-
- it 'exposes status' do
expect(subject).to include(:status)
- end
-
- it 'exposes creation date' do
expect(subject).to include(:created_at)
- end
-
- it 'exposes deployed_at' do
expect(subject).to include(:deployed_at)
- end
-
- it 'exposes last? as is_last' do
expect(subject).to include(:is_last)
- end
-
- it 'exposes deployment tier in yaml' do
expect(subject).to include(:tier_in_yaml)
end
context 'when deployable is nil' do
let(:entity) { described_class.new(deployment, request: request, deployment_details: false) }
- let(:deployment) { create(:deployment, deployable: nil, project: project) }
+
+ before do
+ deployment.update!(deployable: nil)
+ end
it 'does not expose deployable entry' do
expect(subject).not_to include(:deployable)
@@ -60,11 +51,11 @@ RSpec.describe DeploymentEntity do
end
context 'when the pipeline has another manual action' do
- let!(:other_build) do
+ let_it_be(:other_build) do
create(:ci_build, :manual, name: 'another deploy', pipeline: pipeline, environment: build.environment)
end
- let!(:other_deployment) { create(:deployment, deployable: build) }
+ let_it_be(:other_deployment) { create(:deployment, deployable: build, environment: environment) }
it 'returns another manual action' do
expect(subject[:manual_actions].count).to eq(2)
@@ -72,7 +63,7 @@ RSpec.describe DeploymentEntity do
end
context 'when user is a reporter' do
- let(:user) { reporter }
+ let_it_be(:user) { reporter }
it 'returns another manual action' do
expect(subject[:manual_actions]).not_to be_present
@@ -91,14 +82,15 @@ RSpec.describe DeploymentEntity do
end
describe 'scheduled_actions' do
- let(:project) { create(:project, :repository) }
- let(:pipeline) { create(:ci_pipeline, project: project, user: user) }
let(:build) { create(:ci_build, :success, pipeline: pipeline) }
- let(:deployment) { create(:deployment, deployable: build) }
+
+ before do
+ deployment.update!(deployable: build)
+ end
context 'when the same pipeline has a scheduled action' do
let(:other_build) { create(:ci_build, :schedulable, :success, pipeline: pipeline, name: 'other build') }
- let!(:other_deployment) { create(:deployment, deployable: other_build) }
+ let!(:other_deployment) { create(:deployment, deployable: other_build, environment: environment) }
it 'returns other scheduled actions' do
expect(subject[:scheduled_actions][0][:name]).to eq 'other build'
@@ -123,7 +115,9 @@ RSpec.describe DeploymentEntity do
end
describe 'playable_build' do
- let_it_be(:project) { create(:project, :repository) }
+ before do
+ deployment.update!(deployable: build)
+ end
context 'when the deployment has a playable deployable' do
context 'when this build is ready to be played' do
@@ -144,7 +138,7 @@ RSpec.describe DeploymentEntity do
end
context 'when the deployment does not have a playable deployable' do
- let(:build) { create(:ci_build) }
+ let(:build) { create(:ci_build, pipeline: pipeline) }
it 'is not exposed' do
expect(subject[:playable_build]).to be_nil
diff --git a/spec/serializers/environment_status_entity_spec.rb b/spec/serializers/environment_status_entity_spec.rb
index 77ef06f90c2..2ee4e8ade8f 100644
--- a/spec/serializers/environment_status_entity_spec.rb
+++ b/spec/serializers/environment_status_entity_spec.rb
@@ -3,21 +3,26 @@
require 'spec_helper'
RSpec.describe EnvironmentStatusEntity do
- let(:user) { create(:user) }
+ let_it_be(:non_member) { create(:user) }
+ let_it_be(:maintainer) { create(:user) }
+ let_it_be(:deployment) { create(:deployment, :succeed, :review_app) }
+ let_it_be(:merge_request) { create(:merge_request, :deployed_review_app, deployment: deployment) }
+ let_it_be(:environment) { deployment.environment }
+ let_it_be(:project) { deployment.project }
+
+ let(:user) { non_member }
let(:request) { double('request', project: project) }
-
- let(:deployment) { create(:deployment, :succeed, :review_app) }
- let(:environment) { deployment.environment }
- let(:project) { deployment.project }
- let(:merge_request) { create(:merge_request, :deployed_review_app, deployment: deployment) }
-
let(:environment_status) { EnvironmentStatus.new(project, environment, merge_request, merge_request.diff_head_sha) }
- let(:entity) { described_class.new(environment_status, request: request) }
+ let(:entity) { described_class.new(environment_status, request: request) }
subject { entity.as_json }
- before do
+ before_all do
+ project.add_maintainer(maintainer)
deployment.update!(sha: merge_request.diff_head_sha)
+ end
+
+ before do
allow(request).to receive(:current_user).and_return(user)
end
@@ -37,14 +42,13 @@ RSpec.describe EnvironmentStatusEntity do
it { is_expected.not_to include(:metrics_monitoring_url) }
context 'when the user is project maintainer' do
- before do
- project.add_maintainer(user)
- end
+ let(:user) { maintainer }
it { is_expected.to include(:stop_url) }
end
context 'when deployment has metrics' do
+ let(:user) { maintainer }
let(:prometheus_adapter) { double('prometheus_adapter', can_query?: true, configured?: true) }
let(:simple_metrics) do
@@ -56,7 +60,6 @@ RSpec.describe EnvironmentStatusEntity do
end
before do
- project.add_maintainer(user)
allow(deployment).to receive(:prometheus_adapter).and_return(prometheus_adapter)
allow(entity).to receive(:deployment).and_return(deployment)
@@ -69,8 +72,6 @@ RSpec.describe EnvironmentStatusEntity do
end
context 'when deployment succeeded' do
- let(:deployment) { create(:deployment, :succeed, :review_app) }
-
it 'returns metrics url' do
expect(subject[:metrics_url])
.to eq("/#{project.full_path}/-/environments/#{environment.id}/deployments/#{deployment.iid}/metrics")
@@ -78,7 +79,9 @@ RSpec.describe EnvironmentStatusEntity do
end
context 'when deployment is running' do
- let(:deployment) { create(:deployment, :running, :review_app) }
+ before do
+ deployment.update!(status: :running)
+ end
it 'does not return metrics url' do
expect(subject[:metrics_url]).to be_nil
diff --git a/spec/support/rspec_order_todo.yml b/spec/support/rspec_order_todo.yml
index 83981e6fb6d..b5ab6c51a7c 100644
--- a/spec/support/rspec_order_todo.yml
+++ b/spec/support/rspec_order_todo.yml
@@ -9533,7 +9533,6 @@
- './spec/serializers/deploy_keys/basic_deploy_key_entity_spec.rb'
- './spec/serializers/deploy_keys/deploy_key_entity_spec.rb'
- './spec/serializers/deployment_cluster_entity_spec.rb'
-- './spec/serializers/deployment_entity_spec.rb'
- './spec/serializers/deployment_serializer_spec.rb'
- './spec/serializers/detailed_status_entity_spec.rb'
- './spec/serializers/diff_file_base_entity_spec.rb'
@@ -9550,7 +9549,6 @@
- './spec/serializers/entity_request_spec.rb'
- './spec/serializers/environment_entity_spec.rb'
- './spec/serializers/environment_serializer_spec.rb'
-- './spec/serializers/environment_status_entity_spec.rb'
- './spec/serializers/evidences/evidence_entity_spec.rb'
- './spec/serializers/evidences/evidence_serializer_spec.rb'
- './spec/serializers/evidences/issue_entity_spec.rb'