Skip to content

Commit

Permalink
add Core::Remote::Client specs
Browse files Browse the repository at this point in the history
  • Loading branch information
GustavoCaso committed Mar 17, 2023
1 parent 95f687f commit db9c31e
Show file tree
Hide file tree
Showing 4 changed files with 348 additions and 15 deletions.
25 changes: 12 additions & 13 deletions lib/datadog/core/remote/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ module Remote
class Client
attr_reader :transport, :repository, :id

def initialize(transport)
def initialize(transport, repository: Configuration::Repository.new)
@transport = transport

@repository = Configuration::Repository.new
@repository = repository
@id = SecureRandom.uuid
end

Expand Down Expand Up @@ -57,18 +57,18 @@ def sync
# skip if unchanged
same = !new && !changed

unless same
# match content with path and target
content = contents.find_content(path, target)
next if same

# abort entirely if matching content not found
raise SyncError, "no valid content for target at path '#{path}'" if content.nil?
# match content with path and target
content = contents.find_content(path, target)

# to be added or updated << config
# TODO: metadata (hash, version, etc...)
transaction.insert(path, target, content) if new
transaction.update(path, target, content) if changed
end
# abort entirely if matching content not found
raise SyncError, "no valid content for target at path '#{path}'" if content.nil?

# to be added or updated << config
# TODO: metadata (hash, version, etc...)
transaction.insert(path, target, content) if new
transaction.update(path, target, content) if changed
end

# save backend opaque backend state
Expand Down Expand Up @@ -161,7 +161,6 @@ def products
CAP_ASM_DD_RULES,
].freeze


# TODO: as a declaration, this should go in the AppSec namepsace
# TODO: as serialization, this should go in the request serializer/encoder
# TODO: condition by active configuration
Expand Down
2 changes: 1 addition & 1 deletion lib/datadog/core/transport/http/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def initialize(http_response, options = {}) # rubocop:disable Metrics/AbcSize,Me

begin
payload = JSON.parse(http_response.payload, symbolize_names: true)
rescue JSON::ParseError => e
rescue JSON::ParserError => e
raise ParseError.new(:roots, e)
end

Expand Down
2 changes: 1 addition & 1 deletion sig/datadog/core/remote/client.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module Datadog

attr_reader id: ::String

def initialize: (Datadog::Core::Transport::Config::Transport transport) -> void
def initialize: (Datadog::Core::Transport::Config::Transport transport, ?repository: Configuration::Repository) -> void

def sync: () -> void

Expand Down
Loading

0 comments on commit db9c31e

Please sign in to comment.