Commit 91420cd5 authored by Douglas Barbosa Alexandre's avatar Douglas Barbosa Alexandre

Merge branch 'id-move-ee-post-receive-tests-to-service-spec' into 'master'

Convert request specs to unit for EE::PostReceiveService

See merge request gitlab-org/gitlab!30038
parents 08af9e6a 682b94d1
......@@ -52,53 +52,6 @@ describe API::Internal::Base do
expect(git_push_http).to receive(:fetch_referrer_node).and_return(secondary_node)
end
context 'when the secondary has a GeoNodeStatus' do
context 'when the GeoNodeStatus db_replication_lag_seconds is greater than 0' do
let!(:status) { create(:geo_node_status, geo_node: secondary_node, db_replication_lag_seconds: 17) }
it 'includes current Geo secondary lag in the output' do
post api('/internal/post_receive'), params: valid_params
expect(response).to have_gitlab_http_status(:ok)
expect(json_response['messages']).to include({
'type' => 'basic',
'message' => "Current replication lag: 17 seconds"
})
end
end
context 'when the GeoNodeStatus db_replication_lag_seconds is 0' do
let!(:status) { create(:geo_node_status, geo_node: secondary_node, db_replication_lag_seconds: 0) }
it 'does not include current Geo secondary lag in the output' do
post api('/internal/post_receive'), params: valid_params
expect(response).to have_gitlab_http_status(:ok)
expect(json_response['messages']).not_to include({ 'message' => a_string_matching('replication lag'), 'type' => anything })
end
end
context 'when the GeoNodeStatus db_replication_lag_seconds is nil' do
let!(:status) { create(:geo_node_status, geo_node: secondary_node, db_replication_lag_seconds: nil) }
it 'does not include current Geo secondary lag in the output' do
post api('/internal/post_receive'), params: valid_params
expect(response).to have_gitlab_http_status(:ok)
expect(json_response['messages']).not_to include({ 'message' => a_string_matching('replication lag'), 'type' => anything })
end
end
end
context 'when the secondary does not have a GeoNodeStatus' do
it 'does not include current Geo secondary lag in the output' do
post api('/internal/post_receive'), params: valid_params
expect(response).to have_gitlab_http_status(:ok)
expect(json_response['messages']).not_to include({ 'message' => a_string_matching('replication lag'), 'type' => anything })
end
end
it 'includes a message advising a redirection occurred' do
redirect_message = <<~STR
This request to a Geo secondary node will be forwarded to the
......@@ -116,20 +69,6 @@ describe API::Internal::Base do
})
end
end
context 'when the push was not redirected from a Geo secondary to the primary' do
before do
expect(Gitlab::Geo::GitPushHttp).to receive(:new).with(identifier, gl_repository).and_return(git_push_http)
expect(git_push_http).to receive(:fetch_referrer_node).and_return(nil)
end
it 'does not include current Geo secondary lag in the output' do
post api('/internal/post_receive'), params: valid_params
expect(response).to have_gitlab_http_status(:ok)
expect(json_response['messages']).not_to include({ 'message' => a_string_matching('replication lag'), 'type' => anything })
end
end
end
describe "POST /internal/allowed" do
......
# frozen_string_literal: true
require 'spec_helper'
describe PostReceiveService, :geo do
include EE::GeoHelpers
let_it_be(:primary_url) { 'http://primary.example.com' }
let_it_be(:secondary_url) { 'http://secondary.example.com' }
let_it_be(:primary_node, reload: true) { create(:geo_node, :primary, url: primary_url) }
let_it_be(:secondary_node, reload: true) { create(:geo_node, url: secondary_url) }
let_it_be(:user) { create(:user) }
let_it_be(:project) { create(:project, :repository) }
let(:gl_repository) { "project-#{project.id}" }
let(:repository) { project.repository }
let(:identifier) { 'key-123' }
let(:git_push_http) { double('GitPushHttp') }
let(:params) do
{
gl_repository: gl_repository,
identifier: identifier,
changes: []
}
end
subject do
service = described_class.new(user, repository, project, params)
service.execute.messages.as_json
end
before do
stub_current_geo_node(primary_node)
allow(Gitlab::Geo::GitPushHttp).to receive(:new).with(identifier, gl_repository).and_return(git_push_http)
allow(git_push_http).to receive(:fetch_referrer_node).and_return(node)
end
context 'when the push was redirected from a Geo secondary to the primary' do
let(:node) { secondary_node }
context 'when the secondary has a GeoNodeStatus' do
let!(:status) { create(:geo_node_status, geo_node: secondary_node, db_replication_lag_seconds: db_replication_lag_seconds) }
context 'when the GeoNodeStatus db_replication_lag_seconds is greater than 0' do
let(:db_replication_lag_seconds) { 17 }
it 'includes current Geo secondary lag in the output' do
expect(subject).to include({
'type' => 'basic',
'message' => "Current replication lag: 17 seconds"
})
end
end
context 'when the GeoNodeStatus db_replication_lag_seconds is 0' do
let(:db_replication_lag_seconds) { 0 }
it 'does not include current Geo secondary lag in the output' do
expect(subject).not_to include({ 'message' => a_string_matching('replication lag'), 'type' => anything })
end
end
context 'when the GeoNodeStatus db_replication_lag_seconds is nil' do
let(:db_replication_lag_seconds) { nil }
it 'does not include current Geo secondary lag in the output' do
expect(subject).not_to include({ 'message' => a_string_matching('replication lag'), 'type' => anything })
end
end
end
context 'when the secondary does not have a GeoNodeStatus' do
it 'does not include current Geo secondary lag in the output' do
expect(subject).not_to include({ 'message' => a_string_matching('replication lag'), 'type' => anything })
end
end
it 'includes a message advising a redirection occurred' do
redirect_message = <<~STR
This request to a Geo secondary node will be forwarded to the
Geo primary node:
http://primary.example.com/#{project.full_path}.git
STR
expect(subject).to include({
'type' => 'basic',
'message' => redirect_message
})
end
end
context 'when the push was not redirected from a Geo secondary to the primary' do
let(:node) { nil }
it 'does not include current Geo secondary lag in the output' do
expect(subject).not_to include({ 'message' => a_string_matching('replication lag'), 'type' => anything })
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment