Skip to content

Commit

Permalink
feat: Flag Evaluation Requirement 1.1.4 and 1.1.5 and Provider Requir…
Browse files Browse the repository at this point in the history
…ement 2.1.1 (#112)
  • Loading branch information
maxveldink authored Apr 2, 2024
1 parent 3fe0123 commit aac74b1
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 5 deletions.
2 changes: 1 addition & 1 deletion lib/open_feature/sdk/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def initialize
end

def provider(domain: nil)
@providers[domain]
@providers[domain] || @providers[nil]
end

# When switching providers, there are a few lifecycle methods that need to be taken care of.
Expand Down
2 changes: 2 additions & 0 deletions lib/open_feature/sdk/provider/in_memory_provider.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ module Provider
class InMemoryProvider
NAME = "In-memory Provider"

attr_reader :metadata

def initialize(flags = {})
@metadata = Metadata.new(name: NAME).freeze
@flags = flags
Expand Down
4 changes: 2 additions & 2 deletions spec/open_feature/sdk/configuration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
end
end

context "when name is given" do
it "binds the provider to that name" do
context "when domain is given" do
it "binds the provider to that domain" do
provider = OpenFeature::SDK::Provider::InMemoryProvider.new
expect(provider).to receive(:init)

Expand Down
32 changes: 30 additions & 2 deletions spec/specification/flag_evaluation_api_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
end

context "Requirement 1.1.3" do
specify "the API must provide a function to bind a given provider to one or more client names" do
specify "the API must provide a function to bind a given provider to one or more client domains" do
first_provider = OpenFeature::SDK::Provider::InMemoryProvider.new
second_provider = OpenFeature::SDK::Provider::InMemoryProvider.new

Expand All @@ -54,7 +54,7 @@
expect(OpenFeature::SDK.provider(domain: "second")).to be(second_provider)
end

specify "if client name is already bound, it is overwritten" do
specify "if client domain is already bound, it is overwritten" do
previous_provider = OpenFeature::SDK::Provider::InMemoryProvider.new
new_provider = OpenFeature::SDK::Provider::InMemoryProvider.new

Expand All @@ -65,5 +65,33 @@
expect(OpenFeature::SDK.provider(domain: "testing")).to be(new_provider)
end
end

context "Requirement 1.1.4" do
pending "The API must provide a function to add hooks which accepts one or more API-conformant hooks, and appends them to the collection of any previously added hooks."

pending "When new hooks are added, previously added hooks are not removed."
end

context "Requirement 1.1.5" do
before do
default_provider = OpenFeature::SDK::Provider::InMemoryProvider.new
OpenFeature::SDK.set_provider(default_provider)

domain_1_provider = OpenFeature::SDK::Provider::NoOpProvider.new
OpenFeature::SDK.set_provider(domain_1_provider, domain: "domain_1")
end

specify "The API MUST provide a function for retrieving the metadata field of the configured provider." do
expect(OpenFeature::SDK.provider.metadata.name).to eq("In-memory Provider")
end

specify "It's possible to access provider metadata using a domain." do
expect(OpenFeature::SDK.provider(domain: "domain_1").metadata.name).to eq("No-op Provider")
end

specify "If a provider has not be registered under the requested domain, the default provider metadata is returned." do
expect(OpenFeature::SDK.provider(domain: "not_here").metadata.name).to eq("In-memory Provider")
end
end
end
end
15 changes: 15 additions & 0 deletions spec/specification/provider_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# frozen_string_literal: true

require "spec_helper"

RSpec.describe "Provider" do
context "2.1 - Feature Provider Interface" do
context "Requirement 2.1.1" do
specify "The provider interface MUST define a metadata member or accessor, containing a name field or accessor of type string, which identifies the provider implementation." do
provider = OpenFeature::SDK::Provider::NoOpProvider.new

expect(provider.metadata.name).to eq("No-op Provider")
end
end
end
end

0 comments on commit aac74b1

Please sign in to comment.