Handle when server info doesn't have the storage in question

This commit is contained in:
John Cai 2019-08-19 15:14:15 -07:00
parent fc9ad598af
commit ebbd2aeb5f
2 changed files with 12 additions and 1 deletions

View File

@ -406,7 +406,8 @@ module Gitlab
def self.filesystem_id(storage)
response = Gitlab::GitalyClient::ServerService.new(storage).info
storage_status = response.storage_statuses.find { |status| status.storage_name == storage }
storage_status.filesystem_id
storage_status&.filesystem_id
end
def self.filesystem_id_from_disk(storage)

View File

@ -27,6 +27,16 @@ describe Gitlab::GitalyClient do
end
end
describe '.filesystem_id' do
it 'returns an empty string when the storage is not found in the response' do
response = double("response")
allow(response).to receive(:storage_statuses).and_return([])
allow_any_instance_of(Gitlab::GitalyClient::ServerService).to receive(:info).and_return(response)
expect(described_class.filesystem_id('default')).to eq(nil)
end
end
describe '.stub_class' do
it 'returns the gRPC health check stub' do
expect(described_class.stub_class(:health_check)).to eq(::Grpc::Health::V1::Health::Stub)