summaryrefslogtreecommitdiff
path: root/spec/requests/api/admin/batched_background_migrations_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/requests/api/admin/batched_background_migrations_spec.rb')
-rw-r--r--spec/requests/api/admin/batched_background_migrations_spec.rb88
1 files changed, 76 insertions, 12 deletions
diff --git a/spec/requests/api/admin/batched_background_migrations_spec.rb b/spec/requests/api/admin/batched_background_migrations_spec.rb
index c99b21c0c27..3b396a91d3e 100644
--- a/spec/requests/api/admin/batched_background_migrations_spec.rb
+++ b/spec/requests/api/admin/batched_background_migrations_spec.rb
@@ -9,6 +9,7 @@ RSpec.describe API::Admin::BatchedBackgroundMigrations do
describe 'GET /admin/batched_background_migrations/:id' do
let!(:migration) { create(:batched_background_migration, :paused) }
let(:database) { :main }
+ let(:params) { { database: database } }
subject(:show_migration) do
get api("/admin/batched_background_migrations/#{migration.id}", admin), params: { database: database }
@@ -27,10 +28,8 @@ RSpec.describe API::Admin::BatchedBackgroundMigrations do
end
context 'when the batched background migration does not exist' do
- let(:params) { { database: database } }
-
it 'returns 404' do
- put api("/admin/batched_background_migrations/#{non_existing_record_id}", admin), params: params
+ get api("/admin/batched_background_migrations/#{non_existing_record_id}", admin), params: params
expect(response).to have_gitlab_http_status(:not_found)
end
@@ -58,6 +57,17 @@ RSpec.describe API::Admin::BatchedBackgroundMigrations do
expect(response).to have_gitlab_http_status(:forbidden)
end
end
+
+ context 'when the database name does not exist' do
+ let(:database) { :wrong_database }
+
+ it 'returns bad request' do
+ get api("/admin/batched_background_migrations/#{migration.id}", admin), params: params
+
+ expect(response).to have_gitlab_http_status(:bad_request)
+ expect(response.body).to include('database does not have a valid value')
+ end
+ end
end
describe 'GET /admin/batched_background_migrations' do
@@ -82,6 +92,7 @@ RSpec.describe API::Admin::BatchedBackgroundMigrations do
let(:database) { :ci }
let(:schema) { :gitlab_ci }
let(:ci_model) { Ci::ApplicationRecord }
+ let(:params) { { database: database } }
context 'when CI database is provided' do
let(:db_config) { instance_double(ActiveRecord::DatabaseConfigurations::HashConfig, name: 'fake_db') }
@@ -94,7 +105,18 @@ RSpec.describe API::Admin::BatchedBackgroundMigrations do
expect(Gitlab::Database::SharedModel).to receive(:using_connection).with(ci_model.connection).and_yield
- get api('/admin/batched_background_migrations', admin), params: { database: :ci }
+ get api('/admin/batched_background_migrations', admin), params: params
+ end
+
+ context 'when the database name does not exist' do
+ let(:database) { :wrong_database }
+
+ it 'returns bad request' do
+ get api("/admin/batched_background_migrations", admin), params: params
+
+ expect(response).to have_gitlab_http_status(:bad_request)
+ expect(response.body).to include('database does not have a valid value')
+ end
end
it 'returns CI database records' do
@@ -105,7 +127,7 @@ RSpec.describe API::Admin::BatchedBackgroundMigrations do
create(:batched_background_migration, :active, gitlab_schema: schema)
end
- get api('/admin/batched_background_migrations', admin), params: { database: :ci }
+ get api('/admin/batched_background_migrations', admin), params: params
aggregate_failures "testing response" do
expect(response).to have_gitlab_http_status(:ok)
@@ -133,9 +155,10 @@ RSpec.describe API::Admin::BatchedBackgroundMigrations do
describe 'PUT /admin/batched_background_migrations/:id/resume' do
let!(:migration) { create(:batched_background_migration, :paused) }
let(:database) { :main }
+ let(:params) { { database: database } }
subject(:resume) do
- put api("/admin/batched_background_migrations/#{migration.id}/resume", admin), params: { database: database }
+ put api("/admin/batched_background_migrations/#{migration.id}/resume", admin), params: params
end
it 'pauses the batched background migration' do
@@ -149,8 +172,6 @@ RSpec.describe API::Admin::BatchedBackgroundMigrations do
end
context 'when the batched background migration does not exist' do
- let(:params) { { database: database } }
-
it 'returns 404' do
put api("/admin/batched_background_migrations/#{non_existing_record_id}/resume", admin), params: params
@@ -158,6 +179,16 @@ RSpec.describe API::Admin::BatchedBackgroundMigrations do
end
end
+ context 'when the migration is not paused' do
+ let!(:migration) { create(:batched_background_migration, :failed) }
+
+ 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 }
@@ -171,6 +202,17 @@ RSpec.describe API::Admin::BatchedBackgroundMigrations do
resume
end
+
+ context 'when the database name does not exist' do
+ let(:database) { :wrong_database }
+
+ it 'returns bad request' do
+ put api("/admin/batched_background_migrations/#{migration.id}/resume", admin), params: params
+
+ expect(response).to have_gitlab_http_status(:bad_request)
+ expect(response.body).to include('database does not have a valid value')
+ end
+ end
end
context 'when authenticated as a non-admin user' do
@@ -184,9 +226,11 @@ RSpec.describe API::Admin::BatchedBackgroundMigrations do
describe 'PUT /admin/batched_background_migrations/:id/pause' do
let!(:migration) { create(:batched_background_migration, :active) }
+ let(:database) { :main }
+ let(:params) { { database: database } }
it 'pauses the batched background migration' do
- put api("/admin/batched_background_migrations/#{migration.id}/pause", admin), params: { database: :main }
+ put api("/admin/batched_background_migrations/#{migration.id}/pause", admin), params: params
aggregate_failures "testing response" do
expect(response).to have_gitlab_http_status(:ok)
@@ -196,8 +240,6 @@ RSpec.describe API::Admin::BatchedBackgroundMigrations do
end
context 'when the batched background migration does not exist' do
- let(:params) { { database: :main } }
-
it 'returns 404' do
put api("/admin/batched_background_migrations/#{non_existing_record_id}/pause", admin), params: params
@@ -205,8 +247,19 @@ RSpec.describe API::Admin::BatchedBackgroundMigrations do
end
end
+ context 'when the migration is not active' do
+ let!(:migration) { create(:batched_background_migration, :failed) }
+
+ 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 }
+ let(:database) { :ci }
before do
skip_if_multiple_databases_not_setup
@@ -215,7 +268,18 @@ RSpec.describe API::Admin::BatchedBackgroundMigrations do
it 'uses the correct connection' do
expect(Gitlab::Database::SharedModel).to receive(:using_connection).with(ci_model.connection).and_yield
- put api("/admin/batched_background_migrations/#{migration.id}/pause", admin), params: { database: :ci }
+ put api("/admin/batched_background_migrations/#{migration.id}/pause", admin), params: params
+ end
+
+ context 'when the database name does not exist' do
+ let(:database) { :wrong_database }
+
+ it 'returns bad request' do
+ put api("/admin/batched_background_migrations/#{migration.id}/pause", admin), params: params
+
+ expect(response).to have_gitlab_http_status(:bad_request)
+ expect(response.body).to include('database does not have a valid value')
+ end
end
end