Commit c215c6f6 authored by David Kim's avatar David Kim

Use a shared example for handling Gitaly exceptions

parent 2d9fa318
......@@ -22,6 +22,21 @@ describe AvatarsHelper do
end
end
shared_examples 'Gitaly exception handling' do
before do
allow(resource).to receive(:avatar_url).and_raise(error_class)
end
it 'handles Gitaly exception gracefully' do
expect(Gitlab::ErrorTracking).to receive(:track_exception).with(
an_instance_of(error_class), source_type: 'Project', source_id: resource.id
)
expect { project_icon(resource) }.not_to raise_error
end
it_behaves_like 'resource with a default avatar', 'project'
end
context 'when providing a project' do
let(:helper_args) { [resource] }
let(:resource) { create(:project, name: 'foo') }
......@@ -33,33 +48,15 @@ describe AvatarsHelper do
end
context 'when Gitaly is unavailable' do
before do
allow(resource).to receive(:avatar_url).and_raise(GRPC::Unavailable)
end
it 'handles Gitaly unavailable exceptions gracefully' do
expect(Gitlab::ErrorTracking).to receive(:track_exception).with(
an_instance_of(GRPC::Unavailable), source_type: 'Project', source_id: resource.id
)
expect { project_icon(resource) }.not_to raise_error
end
let(:error_class) { GRPC::Unavailable }
it_behaves_like 'resource with a default avatar', 'project'
include_examples 'Gitaly exception handling'
end
context 'when Gitaly request is taking too long' do
before do
allow(resource).to receive(:avatar_url).and_raise(GRPC::DeadlineExceeded)
end
it 'handles Gitaly timeout exceptions gracefully' do
expect(Gitlab::ErrorTracking).to receive(:track_exception).with(
an_instance_of(GRPC::DeadlineExceeded), source_type: 'Project', source_id: resource.id
)
expect { project_icon(resource) }.not_to raise_error
end
let(:error_class) { GRPC::DeadlineExceeded }
it_behaves_like 'resource with a default avatar', 'project'
include_examples 'Gitaly exception handling'
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