Skip to content

Commit fc504e7

Browse files
test: cover domain-aware init paths and fix kwargs-only init dispatch
Signed-off-by: Jonathan Norris <jonathan.norris@dynatrace.com>
1 parent 6cb51fb commit fc504e7

2 files changed

Lines changed: 58 additions & 1 deletion

File tree

lib/open_feature/sdk/configuration.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,6 @@ def init_accepts_domain?(provider)
273273
def init_accepts_evaluation_context?(provider)
274274
init_parameters(provider).any? do |kind, name|
275275
next false if name == :domain
276-
next true if kind == :keyrest
277276

278277
kind == :opt || kind == :req
279278
end

spec/open_feature/sdk/configuration_spec.rb

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,64 @@ def metadata
278278

279279
expect(provider.init_called).to be true
280280
end
281+
282+
it "passes domain to init when init accepts evaluation context and domain" do
283+
provider = Class.new do
284+
attr_reader :init_domain, :init_context
285+
286+
def init(evaluation_context = nil, domain: nil)
287+
@init_context = evaluation_context
288+
@init_domain = domain
289+
end
290+
291+
def metadata
292+
OpenFeature::SDK::Provider::ProviderMetadata.new(name: "DomainAwareProvider")
293+
end
294+
end.new
295+
296+
context = OpenFeature::SDK::EvaluationContext.new(targeting_key: "user")
297+
configuration.evaluation_context = context
298+
configuration.set_provider_and_wait(provider, domain: "billing")
299+
300+
expect(provider.init_context).to eq(context)
301+
expect(provider.init_domain).to eq("billing")
302+
end
303+
304+
it "passes domain to init when init only accepts domain" do
305+
provider = Class.new do
306+
attr_reader :init_domain
307+
308+
def init(domain: nil)
309+
@init_domain = domain
310+
end
311+
312+
def metadata
313+
OpenFeature::SDK::Provider::ProviderMetadata.new(name: "DomainOnlyProvider")
314+
end
315+
end.new
316+
317+
configuration.set_provider_and_wait(provider, domain: "billing")
318+
319+
expect(provider.init_domain).to eq("billing")
320+
end
321+
322+
it "passes domain to init when init accepts keyword rest" do
323+
provider = Class.new do
324+
attr_reader :init_kwargs
325+
326+
def init(**kwargs)
327+
@init_kwargs = kwargs
328+
end
329+
330+
def metadata
331+
OpenFeature::SDK::Provider::ProviderMetadata.new(name: "KwargsProvider")
332+
end
333+
end.new
334+
335+
configuration.set_provider_and_wait(provider, domain: "billing")
336+
337+
expect(provider.init_kwargs[:domain]).to eq("billing")
338+
end
281339
end
282340

283341
describe "event handler error logging" do

0 commit comments

Comments
 (0)