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
diff options
context:
space:
mode:
Diffstat (limited to 'spec/models/remote_mirror_spec.rb')
-rw-r--r--spec/models/remote_mirror_spec.rb108
1 files changed, 16 insertions, 92 deletions
diff --git a/spec/models/remote_mirror_spec.rb b/spec/models/remote_mirror_spec.rb
index a64b01967ef..382359ccb17 100644
--- a/spec/models/remote_mirror_spec.rb
+++ b/spec/models/remote_mirror_spec.rb
@@ -93,51 +93,14 @@ RSpec.describe RemoteMirror, :mailer do
expect(mirror.credentials).to eq({ user: 'foo', password: 'bar' })
end
- it 'updates the remote config if credentials changed' do
+ it 'does not update the repository config if credentials changed' do
mirror = create_mirror(url: 'http://foo:bar@test.com')
repo = mirror.project.repository
+ old_config = rugged_repo(repo).config
mirror.update_attribute(:url, 'http://foo:baz@test.com')
- config = rugged_repo(repo).config
- expect(config["remote.#{mirror.remote_name}.url"]).to eq('http://foo:baz@test.com')
- end
-
- it 'removes previous remote' do
- mirror = create_mirror(url: 'http://foo:bar@test.com')
-
- expect(RepositoryRemoveRemoteWorker).to receive(:perform_async).with(mirror.project.id, mirror.remote_name).and_call_original
-
- mirror.update(url: 'http://test.com')
- end
- end
- end
-
- describe '#remote_name' do
- context 'when remote name is persisted in the database' do
- it 'returns remote name with random value' do
- allow(SecureRandom).to receive(:hex).and_return('secret')
-
- remote_mirror = create(:remote_mirror)
-
- expect(remote_mirror.remote_name).to eq('remote_mirror_secret')
- end
- end
-
- context 'when remote name is not persisted in the database' do
- it 'returns remote name with remote mirror id' do
- remote_mirror = create(:remote_mirror)
- remote_mirror.remote_name = nil
-
- expect(remote_mirror.remote_name).to eq("remote_mirror_#{remote_mirror.id}")
- end
- end
-
- context 'when remote is not persisted in the database' do
- it 'returns nil' do
- remote_mirror = build(:remote_mirror, remote_name: nil)
-
- expect(remote_mirror.remote_name).to be_nil
+ expect(rugged_repo(repo).config.to_hash).to eq(old_config.to_hash)
end
end
end
@@ -157,34 +120,19 @@ RSpec.describe RemoteMirror, :mailer do
end
describe '#update_repository' do
- shared_examples 'an update' do
- it 'performs update including options' do
- git_remote_mirror = stub_const('Gitlab::Git::RemoteMirror', spy)
- mirror = build(:remote_mirror)
-
- expect(mirror).to receive(:options_for_update).and_return(keep_divergent_refs: true)
- mirror.update_repository(inmemory_remote: inmemory)
-
- expect(git_remote_mirror).to have_received(:new).with(
- mirror.project.repository.raw,
- mirror.remote_name,
- inmemory ? mirror.url : nil,
- keep_divergent_refs: true
- )
- expect(git_remote_mirror).to have_received(:update)
- end
- end
+ it 'performs update including options' do
+ git_remote_mirror = stub_const('Gitlab::Git::RemoteMirror', spy)
+ mirror = build(:remote_mirror)
- context 'with inmemory remote' do
- let(:inmemory) { true }
+ expect(mirror).to receive(:options_for_update).and_return(keep_divergent_refs: true)
+ mirror.update_repository
- it_behaves_like 'an update'
- end
-
- context 'with on-disk remote' do
- let(:inmemory) { false }
-
- it_behaves_like 'an update'
+ expect(git_remote_mirror).to have_received(:new).with(
+ mirror.project.repository.raw,
+ mirror.url,
+ keep_divergent_refs: true
+ )
+ expect(git_remote_mirror).to have_received(:update)
end
end
@@ -303,10 +251,10 @@ RSpec.describe RemoteMirror, :mailer do
end
context 'when remote mirror gets destroyed' do
- it 'removes remote' do
+ it 'does not remove the remote' do
mirror = create_mirror(url: 'http://foo:bar@test.com')
- expect(RepositoryRemoveRemoteWorker).to receive(:perform_async).with(mirror.project.id, mirror.remote_name).and_call_original
+ expect(RepositoryRemoveRemoteWorker).not_to receive(:perform_async)
mirror.destroy!
end
@@ -402,30 +350,6 @@ RSpec.describe RemoteMirror, :mailer do
end
end
- describe '#ensure_remote!' do
- let(:remote_mirror) { create(:project, :repository, :remote_mirror).remote_mirrors.first }
- let(:project) { remote_mirror.project }
- let(:repository) { project.repository }
-
- it 'adds a remote multiple times with no errors' do
- expect(repository).to receive(:add_remote).with(remote_mirror.remote_name, remote_mirror.url).twice.and_call_original
-
- 2.times do
- remote_mirror.ensure_remote!
- end
- end
-
- context 'SSH public-key authentication' do
- it 'omits the password from the URL' do
- remote_mirror.update!(auth_method: 'ssh_public_key', url: 'ssh://git:pass@example.com')
-
- expect(repository).to receive(:add_remote).with(remote_mirror.remote_name, 'ssh://git@example.com')
-
- remote_mirror.ensure_remote!
- end
- end
- end
-
describe '#url=' do
let(:remote_mirror) { create(:project, :repository, :remote_mirror).remote_mirrors.first }