From d59510b4c54a9c2451f6644fa27fb2d2ba4c866d Mon Sep 17 00:00:00 2001 From: Douglas Barbosa Alexandre <dbalexandre@gmail.com> Date: Mon, 10 May 2021 20:22:54 -0300 Subject: [PATCH] Fix update_root_ref with inmemory feature disabled --- .../services/geo/repository_sync_service.rb | 4 +- .../geo/repository_sync_service_spec.rb | 122 ++++++++++++++---- 2 files changed, 96 insertions(+), 30 deletions(-) diff --git a/ee/app/services/geo/repository_sync_service.rb b/ee/app/services/geo/repository_sync_service.rb index b450f996d33..4b9e2e84b7c 100644 --- a/ee/app/services/geo/repository_sync_service.rb +++ b/ee/app/services/geo/repository_sync_service.rb @@ -57,8 +57,8 @@ module Geo project.update_root_ref(GEO_REMOTE_NAME, remote_url, authorization) else - repository_with_config(jwt_authentication_header) do - project.update_root_ref(GEO_REMOTE_NAME, remote_url) + repository.with_config(jwt_authentication_header) do + project.update_root_ref(GEO_REMOTE_NAME, remote_url, nil) end end end diff --git a/ee/spec/services/geo/repository_sync_service_spec.rb b/ee/spec/services/geo/repository_sync_service_spec.rb index 2f4a37df7e6..dc753ec9f2e 100644 --- a/ee/spec/services/geo/repository_sync_service_spec.rb +++ b/ee/spec/services/geo/repository_sync_service_spec.rb @@ -233,53 +233,119 @@ RSpec.describe Geo::RepositorySyncService, :geo do context 'with non empty repositories' do let(:project) { create(:project, :repository) } - context 'when when HEAD change' do + context 'with inmemory feature disabled' do before do - allow(project.repository) - .to receive(:find_remote_root_ref) - .with('geo', url_to_repo, anything) - .and_return('feature') + stub_feature_flags(find_remote_root_refs_inmemory: false) end - it 'syncs gitattributes to info/attributes' do - expect(repository).to receive(:copy_gitattributes) + context 'when HEAD change' do + before do + allow(project.repository) + .to receive(:find_remote_root_ref) + .with('geo', url_to_repo, nil) + .and_return('feature') + end - subject.execute + it 'syncs gitattributes to info/attributes' do + expect(repository).to receive(:copy_gitattributes) + + subject.execute + end + + it 'updates the default branch with JWT credentials' do + expect(repository).to receive(:with_config) + .with("http.#{url_to_repo}.extraHeader" => anything) + .and_call_original + .twice + + expect(project).to receive(:change_head).with('feature').once + + subject.execute + end end - it 'updates the default branch with JWT credentials' do - expect(repository).to receive(:with_config) - .with("http.#{url_to_repo}.extraHeader" => anything) - .and_call_original + context 'when HEAD does not change' do + before do + allow(project.repository) + .to receive(:find_remote_root_ref) + .with('geo', url_to_repo, nil) + .and_return(project.default_branch) + end + + it 'syncs gitattributes to info/attributes' do + expect(repository).to receive(:copy_gitattributes) + + subject.execute + end + + it 'updates the default branch with JWT credentials' do + expect(repository).to receive(:with_config) + .with("http.#{url_to_repo}.extraHeader" => anything) + .and_call_original + .twice - expect(project).to receive(:change_head).with('feature').once + expect(project).to receive(:change_head).with('master').once - subject.execute + subject.execute + end end end - context 'when HEAD does not change' do + context 'with inmemory feature enabled' do before do - allow(project.repository) - .to receive(:find_remote_root_ref) - .with('geo', url_to_repo, anything) - .and_return(project.default_branch) + stub_feature_flags(find_remote_root_refs_inmemory: true) end - it 'syncs gitattributes to info/attributes' do - expect(repository).to receive(:copy_gitattributes) + context 'when HEAD change' do + before do + allow(project.repository) + .to receive(:find_remote_root_ref) + .with('geo', url_to_repo, anything) + .and_return('feature') + end - subject.execute + it 'syncs gitattributes to info/attributes' do + expect(repository).to receive(:copy_gitattributes) + + subject.execute + end + + it 'updates the default branch' do + expect(repository).to receive(:with_config) + .with("http.#{url_to_repo}.extraHeader" => anything) + .and_call_original + .once + + expect(project).to receive(:change_head).with('feature').once + + subject.execute + end end - it 'updates the default branch with JWT credentials' do - expect(repository).to receive(:with_config) - .with("http.#{url_to_repo}.extraHeader" => anything) - .and_call_original + context 'when HEAD does not change' do + before do + allow(project.repository) + .to receive(:find_remote_root_ref) + .with('geo', url_to_repo, anything) + .and_return(project.default_branch) + end + + it 'syncs gitattributes to info/attributes' do + expect(repository).to receive(:copy_gitattributes) + + subject.execute + end + + it 'updates the default branch' do + expect(repository).to receive(:with_config) + .with("http.#{url_to_repo}.extraHeader" => anything) + .and_call_original + .once - expect(project).to receive(:change_head).with('master').once + expect(project).to receive(:change_head).with('master').once - subject.execute + subject.execute + end end end end -- 2.30.9