Test for Pruner
This commit is contained in:
@@ -3,31 +3,36 @@ require 'retries'
|
||||
require 'json'
|
||||
require_relative '../exceptions'
|
||||
|
||||
|
||||
NUMBER_OF_RETRIES = 3
|
||||
|
||||
module Pruning
|
||||
module Repos
|
||||
# Handles communication with origin server
|
||||
# and all its problems
|
||||
class Tree
|
||||
def initialize(client=RestClient, base_url)
|
||||
def initialize(client, base_url)
|
||||
@client = client
|
||||
@base_url = base_url
|
||||
end
|
||||
|
||||
def get(name)
|
||||
with_retries(max_tries: 3, rescue: [Pruning::Exceptions::ServerErrorOnOrigin]) do
|
||||
with_retries(max_tries: NUMBER_OF_RETRIES, rescue: [Pruning::Exceptions::ServerErrorOnOrigin]) do
|
||||
begin
|
||||
resp = @client.get(url(name))
|
||||
rescue RestClient::ExceptionWithResponse => e
|
||||
if e.response.code != 404
|
||||
raise Pruning::Exceptions::ServerErrorOnOrigin
|
||||
else
|
||||
raise Pruning::Exceptions::OriginCannotFindTheResource
|
||||
end
|
||||
rescue RestClient::ExceptionWithResponse => e
|
||||
raise Pruning::Exceptions::ServerErrorOnOrigin if e.response.code != 404
|
||||
raise Pruning::Exceptions::OriginCannotFindTheResource
|
||||
end
|
||||
|
||||
return JSON(resp.body)
|
||||
end
|
||||
return JSON(resp.body)
|
||||
end
|
||||
raise Pruning::Exceptions::UnexpectedError
|
||||
raise Pruning::Exceptions::UnexpectedError
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
private
|
||||
|
||||
def url(name)
|
||||
"#{@base_url}/tree/#{name}"
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user