Test for Pruner

This commit is contained in:
Senad Uka
2018-08-13 18:54:12 +02:00
parent 5684e58826
commit 973f1e1093
15 changed files with 2888 additions and 53 deletions

View File

@@ -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