Skip to content

Commit

Permalink
pass TestSession object to the ApiClient together with runtime inform…
Browse files Browse the repository at this point in the history
…ation included
  • Loading branch information
anmarchenko committed Mar 4, 2024
1 parent e67b976 commit 4842bba
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 19 deletions.
6 changes: 3 additions & 3 deletions lib/datadog/ci/test_visibility/recorder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def start_test_session(service: nil, tags: {})

test_session = build_test_session(tracer_span, tags)

configure_library(service: service)
configure_library(test_session)

test_session
end
Expand Down Expand Up @@ -190,12 +190,12 @@ def itr_enabled?

private

def configure_library(service:)
def configure_library(test_session)
return unless itr_enabled?
# TODO: error handling when request failed - disable ITR runner
# TODO: need to pass runtime information
# TODO: disable ITR runner if itr_enabled is false in settings
@api_client.fetch_library_settings(service: service)
@api_client.fetch_library_settings(test_session)
end

def skip_tracing(block = nil)
Expand Down
4 changes: 2 additions & 2 deletions lib/datadog/ci/transport/api_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def initialize(api: nil, dd_env: nil)
@dd_env = dd_env
end

def fetch_library_settings(service:)
def fetch_library_settings(test_session)
# TODO: return error response if api is not present
api = @api
return {} unless api
Expand All @@ -24,7 +24,7 @@ def fetch_library_settings(service:)
# TODO: return error response - use some wrapper from ddtrace as an example
api.api_request(
path: Ext::Transport::DD_API_SETTINGS_PATH,
payload: settings_payload(service: service)
payload: settings_payload(service: test_session.service)
)
end

Expand Down
2 changes: 1 addition & 1 deletion sig/datadog/ci/test_visibility/recorder.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ module Datadog

private

def configure_library: (service: String?) -> void
def configure_library: (Datadog::CI::TestSession test_session) -> void

def create_datadog_span: (String span_name, ?span_options: Hash[untyped, untyped], ?tags: Hash[untyped, untyped]) ?{ (Datadog::CI::Span span) -> untyped } -> untyped

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

def initialize: (?api: Datadog::CI::Transport::Api::Base?, ?dd_env: String?) -> void

def fetch_library_settings: (service: String?) -> untyped
def fetch_library_settings: (Datadog::CI::TestSession test_session) -> untyped

private

Expand Down
16 changes: 4 additions & 12 deletions spec/datadog/ci/transport/api_client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,13 @@

describe "#fetch_library_settings" do
let(:service) { "service" }
let(:tracer_span) { double("tracer_span", service: service) }
let(:test_session) { Datadog::CI::TestSession.new(tracer_span) }

let(:path) { Datadog::CI::Ext::Transport::DD_API_SETTINGS_PATH }
let(:payload) do
{
data: {
id: "change_me",
type: Datadog::CI::Ext::Transport::DD_API_SETTINGS_TYPE,
attributes: {
service: service
}
}
}.to_json
end

it "requests the settings" do
subject.fetch_library_settings(service: service)
subject.fetch_library_settings(test_session)

expect(api).to have_received(:api_request) do |args|
expect(args[:path]).to eq(path)
Expand Down

0 comments on commit 4842bba

Please sign in to comment.