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
path: root/spec
diff options
context:
space:
mode:
authorAlejandro Rodríguez <alejorro70@gmail.com>2018-12-05 18:22:52 +0300
committerAlejandro Rodríguez <alejorro70@gmail.com>2018-12-12 05:08:17 +0300
commitb65cb237cee0b1a8dfdc21a09f2b181d0edf5bde (patch)
treedffc212c6e7ca84c1e61ec1625e53548c0b6de18 /spec
parent80eebd8e33c5f2f26bc0fdd233d9d92c51edd242 (diff)
Send a notification email on mirror update errors
The email is sent to project maintainers containing the last mirror update error. This will allow maintainers to set alarms and react accordingly.
Diffstat (limited to 'spec')
-rw-r--r--spec/models/remote_mirror_spec.rb39
-rw-r--r--spec/services/notification_service_spec.rb33
-rw-r--r--spec/workers/repository_update_remote_mirror_worker_spec.rb13
3 files changed, 81 insertions, 4 deletions
diff --git a/spec/models/remote_mirror_spec.rb b/spec/models/remote_mirror_spec.rb
index b12ca79847c..5d3c25062d5 100644
--- a/spec/models/remote_mirror_spec.rb
+++ b/spec/models/remote_mirror_spec.rb
@@ -1,6 +1,6 @@
require 'rails_helper'
-describe RemoteMirror do
+describe RemoteMirror, :mailer do
include GitHelpers
describe 'URL validation' do
@@ -137,6 +137,43 @@ describe RemoteMirror do
end
end
+ describe '#mark_as_failed' do
+ let(:remote_mirror) { create(:remote_mirror) }
+ let(:error_message) { 'http://user:pass@test.com/root/repoC.git/' }
+ let(:sanitized_error_message) { 'http://*****:*****@test.com/root/repoC.git/' }
+
+ subject do
+ remote_mirror.update_start
+ remote_mirror.mark_as_failed(error_message)
+ end
+
+ it 'sets the update_status to failed' do
+ subject
+
+ expect(remote_mirror.reload.update_status).to eq('failed')
+ end
+
+ it 'saves the sanitized error' do
+ subject
+
+ expect(remote_mirror.last_error).to eq(sanitized_error_message)
+ end
+
+ context 'notifications' do
+ let(:user) { create(:user) }
+
+ before do
+ remote_mirror.project.add_maintainer(user)
+ end
+
+ it 'notifies the project maintainers' do
+ perform_enqueued_jobs { subject }
+
+ should_email(user)
+ end
+ end
+ end
+
context 'when remote mirror gets destroyed' do
it 'removes remote' do
mirror = create_mirror(url: 'http://foo:bar@test.com')
diff --git a/spec/services/notification_service_spec.rb b/spec/services/notification_service_spec.rb
index 0f6c2604984..68ac3a00ab0 100644
--- a/spec/services/notification_service_spec.rb
+++ b/spec/services/notification_service_spec.rb
@@ -2167,6 +2167,39 @@ describe NotificationService, :mailer do
end
end
+ context 'Remote mirror notifications' do
+ describe '#remote_mirror_update_failed' do
+ let(:project) { create(:project) }
+ let(:remote_mirror) { create(:remote_mirror, project: project) }
+ let(:u_blocked) { create(:user, :blocked) }
+ let(:u_silence) { create_user_with_notification(:disabled, 'silent-maintainer', project) }
+ let(:u_owner) { project.owner }
+ let(:u_maintainer1) { create(:user) }
+ let(:u_maintainer2) { create(:user) }
+ let(:u_developer) { create(:user) }
+
+ before do
+ project.add_maintainer(u_blocked)
+ project.add_maintainer(u_silence)
+ project.add_maintainer(u_maintainer1)
+ project.add_maintainer(u_maintainer2)
+ project.add_developer(u_developer)
+
+ # Mock remote update
+ allow(project.repository).to receive(:async_remove_remote)
+ allow(project.repository).to receive(:add_remote)
+
+ reset_delivered_emails!
+ end
+
+ it 'emails current watching maintainers' do
+ notification.remote_mirror_update_failed(remote_mirror)
+
+ should_only_email(u_maintainer1, u_maintainer2, u_owner)
+ end
+ end
+ end
+
def build_team(project)
@u_watcher = create_global_setting_for(create(:user), :watch)
@u_participating = create_global_setting_for(create(:user), :participating)
diff --git a/spec/workers/repository_update_remote_mirror_worker_spec.rb b/spec/workers/repository_update_remote_mirror_worker_spec.rb
index 4f1ad2474f5..d73b0b53713 100644
--- a/spec/workers/repository_update_remote_mirror_worker_spec.rb
+++ b/spec/workers/repository_update_remote_mirror_worker_spec.rb
@@ -25,12 +25,19 @@ describe RepositoryUpdateRemoteMirrorWorker do
it 'sets status as failed when update remote mirror service executes with errors' do
error_message = 'fail!'
- expect_any_instance_of(Projects::UpdateRemoteMirrorService).to receive(:execute).with(remote_mirror).and_return(status: :error, message: error_message)
+ expect_next_instance_of(Projects::UpdateRemoteMirrorService) do |service|
+ expect(service).to receive(:execute).with(remote_mirror).and_return(status: :error, message: error_message)
+ end
+
+ # Mock the finder so that it returns an object we can set expectations on
+ expect_next_instance_of(RemoteMirrorFinder) do |finder|
+ expect(finder).to receive(:execute).and_return(remote_mirror)
+ end
+ expect(remote_mirror).to receive(:mark_as_failed).with(error_message)
+
expect do
subject.perform(remote_mirror.id, Time.now)
end.to raise_error(RepositoryUpdateRemoteMirrorWorker::UpdateError, error_message)
-
- expect(remote_mirror.reload.update_status).to eq('failed')
end
it 'does nothing if last_update_started_at is higher than the time the job was scheduled in' do