Skip to content
This repository has been archived by the owner on Oct 24, 2024. It is now read-only.

DRAFT: fcrepo_endpoint monitor support #743

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions app/models/fcrepo_endpoint.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,15 @@ def self.reset!
end

def ping
ActiveFedora::Fedora.instance.connection.head(
if ActiveFedora::Fedora.instance.connection.head(
ActiveFedora::Fedora.instance.connection.connection.http.url_prefix.to_s
).response.success?
rescue StandardError
false
"Fedora is OK"
else
"Error checking Fedora status: Fedora is Down"
end
rescue StandardError => e
"Error checking Fedora status: #{e.message}"
end

# Remove the Fedora resource for this endpoint, then destroy the record
Expand Down
38 changes: 25 additions & 13 deletions spec/models/fcrepo_endpoint_spec.rb
Original file line number Diff line number Diff line change
@@ -1,31 +1,43 @@
# frozen_string_literal: true

RSpec.describe FcrepoEndpoint do
subject { described_class.new base_path: base_path }

let(:base_path) { 'foobar' }

describe '.options' do
subject { described_class.new base_path: base_path }

it 'uses the configured application settings' do
expect(subject.options[:base_path]).to eq base_path
end
end

describe '#ping' do
let(:success_response) { double(response: double(success?: true)) }
let(:url_prefix) { ActiveFedora::Fedora.instance.connection.connection.http.url_prefix.to_s }

context 'when Fedora is accessible' do
let(:success_response) { double(response: double(success?: true)) }

it 'returns "Fedora is OK"' do
allow(ActiveFedora::Fedora.instance.connection).to receive(:head).with(url_prefix).and_return(success_response)
expect(subject.ping).to eq("Fedora is OK")
end
end

context 'when Fedora is down' do
let(:failure_response) { double(response: double(success?: false)) }

it 'checks if the service is up' do
allow(ActiveFedora::Fedora.instance.connection).to receive(:head).with(
ActiveFedora::Fedora.instance.connection.connection.http.url_prefix.to_s
).and_return(success_response)
expect(subject.ping).to be_truthy
it 'returns "Fedora is Down"' do
allow(ActiveFedora::Fedora.instance.connection).to receive(:head).with(url_prefix).and_return(failure_response)
expect(subject.ping).to eq("Error checking Fedora status: Fedora is Down")
end
end

it 'is false if the service is down' do
allow(ActiveFedora::Fedora.instance.connection).to receive(:head).with(
ActiveFedora::Fedora.instance.connection.connection.http.url_prefix.to_s
).and_raise(RuntimeError)
expect(subject.ping).to be_falsey
context 'when an error occurs' do
it 'returns a custom error message with the error details' do
error_message = "Network error"
allow(ActiveFedora::Fedora.instance.connection).to receive(:head).and_raise(StandardError.new(error_message))
expect(subject.ping).to eq("Error checking Fedora status: #{error_message}")
end
end
end
end
Loading