diff --git a/.github/workflows/ruby.yml b/.github/workflows/ruby.yml
index 3de104a..b66c448 100644
--- a/.github/workflows/ruby.yml
+++ b/.github/workflows/ruby.yml
@@ -37,7 +37,7 @@ jobs:
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
working-directory: ./providers/openfeature-flagd-provider
- name: Launch flagd instance
- run: docker-compose up -d flagd
+ run: docker compose up -d flagd
working-directory: ./providers/openfeature-flagd-provider/docker
- name: Check linting
run: bundle exec rubocop
@@ -64,3 +64,25 @@ jobs:
working-directory: ./providers/openfeature-meta_provider
- name: Lint and test
run: bin/rake
+
+ test_go_feature_flag_provider:
+ runs-on: ubuntu-latest
+ defaults:
+ run:
+ working-directory: ./providers/openfeature-go-feature-flag-provider
+ strategy:
+ matrix:
+ ruby-version:
+ - "3.3"
+ - "3.2"
+ - "3.1"
+ steps:
+ - uses: actions/checkout@v4
+ - name: Set up Ruby
+ uses: ruby/setup-ruby@v1
+ with:
+ ruby-version: ${{ matrix.ruby-version }}
+ bundler-cache: true # runs 'bundle install' and caches installed gems automatically
+ working-directory: ./providers/openfeature-go-feature-flag-provider
+ - name: Lint and test
+ run: bin/rake
\ No newline at end of file
diff --git a/.gitignore b/.gitignore
index 71983ae..74d9d73 100644
--- a/.gitignore
+++ b/.gitignore
@@ -56,3 +56,6 @@ build-iPhoneSimulator/
# .rubocop-https?--*
.DS_Store
+
+# Ignore jetbrains files
+.idea/
\ No newline at end of file
diff --git a/.release-please-manifest.json b/.release-please-manifest.json
index a05acb4..cf71449 100644
--- a/.release-please-manifest.json
+++ b/.release-please-manifest.json
@@ -1,4 +1,5 @@
{
"providers/openfeature-flagd-provider": "0.1.1",
- "providers/openfeature-meta_provider": "0.0.3"
+ "providers/openfeature-meta_provider": "0.0.3",
+ "providers/openfeature-go-feature-flag-provider": "0.1.0"
}
diff --git a/providers/openfeature-go-feature-flag-provider/.rubocop.yml b/providers/openfeature-go-feature-flag-provider/.rubocop.yml
new file mode 100644
index 0000000..feec135
--- /dev/null
+++ b/providers/openfeature-go-feature-flag-provider/.rubocop.yml
@@ -0,0 +1,5 @@
+inherit_from: ../../shared_config/.rubocop.yml
+
+inherit_mode:
+ merge:
+ - Exclude
diff --git a/providers/openfeature-go-feature-flag-provider/Gemfile b/providers/openfeature-go-feature-flag-provider/Gemfile
new file mode 100644
index 0000000..b4e2a20
--- /dev/null
+++ b/providers/openfeature-go-feature-flag-provider/Gemfile
@@ -0,0 +1,3 @@
+source "https://rubygems.org"
+
+gemspec
diff --git a/providers/openfeature-go-feature-flag-provider/Gemfile.lock b/providers/openfeature-go-feature-flag-provider/Gemfile.lock
new file mode 100644
index 0000000..0c64b8d
--- /dev/null
+++ b/providers/openfeature-go-feature-flag-provider/Gemfile.lock
@@ -0,0 +1,114 @@
+PATH
+ remote: .
+ specs:
+ openfeature-go-feature-flag-provider (0.1.0)
+ faraday (~> 2.10.1)
+ openfeature-sdk (~> 0.3.1)
+
+GEM
+ remote: https://rubygems.org/
+ specs:
+ addressable (2.8.7)
+ public_suffix (>= 2.0.2, < 7.0)
+ ast (2.4.2)
+ bigdecimal (3.1.8)
+ crack (1.0.0)
+ bigdecimal
+ rexml
+ diff-lcs (1.5.1)
+ docile (1.4.1)
+ faraday (2.10.1)
+ faraday-net_http (>= 2.0, < 3.2)
+ logger
+ faraday-net_http (3.1.1)
+ net-http
+ hashdiff (1.1.1)
+ json (2.7.2)
+ language_server-protocol (3.17.0.3)
+ lint_roller (1.1.0)
+ logger (1.6.0)
+ net-http (0.4.1)
+ uri
+ openfeature-sdk (0.3.1)
+ parallel (1.24.0)
+ parser (3.3.0.5)
+ ast (~> 2.4.1)
+ racc
+ public_suffix (6.0.1)
+ racc (1.7.3)
+ rainbow (3.1.1)
+ rake (13.2.1)
+ regexp_parser (2.9.0)
+ rexml (3.3.4)
+ strscan
+ rspec (3.12.0)
+ rspec-core (~> 3.12.0)
+ rspec-expectations (~> 3.12.0)
+ rspec-mocks (~> 3.12.0)
+ rspec-core (3.12.3)
+ rspec-support (~> 3.12.0)
+ rspec-expectations (3.12.4)
+ diff-lcs (>= 1.2.0, < 2.0)
+ rspec-support (~> 3.12.0)
+ rspec-mocks (3.12.7)
+ diff-lcs (>= 1.2.0, < 2.0)
+ rspec-support (~> 3.12.0)
+ rspec-support (3.12.2)
+ rubocop (1.62.1)
+ json (~> 2.3)
+ language_server-protocol (>= 3.17.0)
+ parallel (~> 1.10)
+ parser (>= 3.3.0.2)
+ rainbow (>= 2.2.2, < 4.0)
+ regexp_parser (>= 1.8, < 3.0)
+ rexml (>= 3.2.5, < 4.0)
+ rubocop-ast (>= 1.31.1, < 2.0)
+ ruby-progressbar (~> 1.7)
+ unicode-display_width (>= 2.4.0, < 3.0)
+ rubocop-ast (1.31.2)
+ parser (>= 3.3.0.4)
+ rubocop-performance (1.20.2)
+ rubocop (>= 1.48.1, < 2.0)
+ rubocop-ast (>= 1.30.0, < 2.0)
+ ruby-progressbar (1.13.0)
+ simplecov (0.22.0)
+ docile (~> 1.1)
+ simplecov-html (~> 0.11)
+ simplecov_json_formatter (~> 0.1)
+ simplecov-html (0.12.3)
+ simplecov_json_formatter (0.1.4)
+ standard (1.35.1)
+ language_server-protocol (~> 3.17.0.2)
+ lint_roller (~> 1.0)
+ rubocop (~> 1.62.0)
+ standard-custom (~> 1.0.0)
+ standard-performance (~> 1.3)
+ standard-custom (1.0.2)
+ lint_roller (~> 1.0)
+ rubocop (~> 1.50)
+ standard-performance (1.3.1)
+ lint_roller (~> 1.1)
+ rubocop-performance (~> 1.20.2)
+ strscan (3.1.0)
+ unicode-display_width (2.5.0)
+ uri (0.13.0)
+ webmock (3.23.1)
+ addressable (>= 2.8.0)
+ crack (>= 0.3.2)
+ hashdiff (>= 0.4.0, < 2.0.0)
+
+PLATFORMS
+ arm64-darwin-23
+ ruby
+
+DEPENDENCIES
+ openfeature-go-feature-flag-provider!
+ rake (~> 13.0)
+ rspec (~> 3.12.0)
+ rubocop
+ simplecov
+ standard
+ webmock
+
+BUNDLED WITH
+ 2.5.11
diff --git a/providers/openfeature-go-feature-flag-provider/README.md b/providers/openfeature-go-feature-flag-provider/README.md
new file mode 100644
index 0000000..274a9fb
--- /dev/null
+++ b/providers/openfeature-go-feature-flag-provider/README.md
@@ -0,0 +1,128 @@
+
+
+
+
+
+# GO Feature Flag - OpenFeature Ruby provider
+
+
+
+
+
+
+
+This repository contains the official Ruby OpenFeature provider for accessing your feature flags with [GO Feature Flag](https://gofeatureflag.org).
+
+In conjunction with the [OpenFeature SDK](https://openfeature.dev/docs/reference/concepts/provider) you will be able
+to evaluate your feature flags in your Ruby applications.
+
+For documentation related to flags management in GO Feature Flag,
+refer to the [GO Feature Flag documentation website](https://gofeatureflag.org/docs).
+
+### Functionalities:
+- Manage the integration of the OpenFeature Ruby SDK and GO Feature Flag relay-proxy.
+
+## Dependency Setup
+
+### Gem Package Manager
+
+Add this line to your application's Gemfile:
+```
+gem 'openfeature-go-feature-flag-provider'
+```
+And then execute:
+```
+bundle install
+```
+Or install it yourself as:
+```
+gem install openfeature-go-feature-flag-provider
+```
+
+## Getting started
+
+### Initialize the provider
+
+The `OpenFeature::GoFeatureFlag::Provider` needs some options to be created and then set in the OpenFeature SDK.
+
+| **Option** | **Description** |
+|------------|---------------------------------------------------------------------------------------------------------------------------------------------|
+| `endpoint` | **(mandatory)** The URL to access to the relay-proxy.
*(example: `https://relay.proxy.gofeatureflag.org/`)* |
+| `headers` | A `Hash` object containing the headers to send to the relay-proxy.
*(example to send APIKey: `{"Authorization" => "Bearer my-api-key"}` |
+
+The only required option to create a `GoFeatureFlagProvider` is the URL _(`endpoint`)_ to your GO Feature Flag relay-proxy instance.
+
+```ruby
+options = OpenFeature::GoFeatureFlag::Options.new(endpoint: "http://localhost:1031")
+provider = OpenFeature::GoFeatureFlag::Provider.new(options:)
+
+evaluation_context = OpenFeature::SDK::EvaluationContext.new(targeting_key: "9b9450f8-ab5c-4dcf-872f-feda3f6ccb16")
+
+OpenFeature::SDK.configure do |config|
+ config.set_provider(provider)
+end
+client = OpenFeature::SDK.build_client
+
+bool_value = client.fetch_boolean_value(
+ flag_key: "my-boolean-flag",
+ default_value: false,
+ evaluation_context:
+)
+
+if bool_value
+ puts "The flag is enabled"
+else
+ puts "The flag is disabled"
+end
+```
+
+The evaluation context is the way for the client to specify contextual data that GO Feature Flag uses to evaluate the feature flags, it allows to define rules on the flag.
+
+The `targeting_key` is mandatory for GO Feature Flag to evaluate the feature flag, it could be the id of a user, a session ID or anything you find relevant to use as identifier during the evaluation.
+
+
+### Evaluate a feature flag
+The client is used to retrieve values for the current `EvaluationContext`.
+For example, retrieving a boolean value for the flag **"my-flag"**:
+
+```ruby
+client = OpenFeature::SDK.build_client
+
+bool_value = client.fetch_boolean_value(
+ flag_key: "my-boolean-flag",
+ default_value: false,
+ evaluation_context: evaluation_context
+)
+```
+
+GO Feature Flag supports different all OpenFeature supported types of feature flags, it means that you can use all the accessor directly
+```ruby
+# Bool
+client.fetch_boolean_value(flag_key: 'my-flag', default_value: false, evaluation_context:)
+
+# String
+client.fetch_string_value(flag_key: 'my-flag', default_value: "default", evaluation_context:)
+
+# Number
+client.fetch_number_value(flag_key: 'my-flag', default_value: 0, evaluation_context:)
+
+# Object
+client.fetch_object_value(flag_key: 'my-flag', default_value: {"default" => true}, evaluation_context:)
+```
+
+## Features status
+
+| Status | Feature | Description |
+|--------|-----------------|----------------------------------------------------------------------------|
+| ✅ | Flag evaluation | It is possible to evaluate all the type of flags |
+| ❌ | Caching | Mechanism is in place to refresh the cache in case of configuration change |
+| ❌ | Event Streaming | Not supported by the SDK |
+| ❌ | Logging | Not supported by the SDK |
+| ✅ | Flag Metadata | You can retrieve your flag metadata directly in the evaluation details. |
+
+
+**Implemented**: ✅ | In-progress: ⚠️ | Not implemented yet: ❌
+
+## Contributing
+This project welcomes contributions from the community.
+If you're interested in contributing, see the [contributors' guide](https://github.com/thomaspoignant/go-feature-flag/blob/main/CONTRIBUTING.md) for some helpful tips.
diff --git a/providers/openfeature-go-feature-flag-provider/Rakefile b/providers/openfeature-go-feature-flag-provider/Rakefile
new file mode 100644
index 0000000..85f5f4d
--- /dev/null
+++ b/providers/openfeature-go-feature-flag-provider/Rakefile
@@ -0,0 +1,10 @@
+# frozen_string_literal: true
+
+require "bundler/gem_tasks"
+require "rspec/core/rake_task"
+
+RSpec::Core::RakeTask.new(:spec)
+
+require "standard/rake"
+
+task default: %i[standard spec]
diff --git a/providers/openfeature-go-feature-flag-provider/bin/rake b/providers/openfeature-go-feature-flag-provider/bin/rake
new file mode 100755
index 0000000..4eb7d7b
--- /dev/null
+++ b/providers/openfeature-go-feature-flag-provider/bin/rake
@@ -0,0 +1,27 @@
+#!/usr/bin/env ruby
+# frozen_string_literal: true
+
+#
+# This file was generated by Bundler.
+#
+# The application 'rake' is installed as part of a gem, and
+# this file is here to facilitate running it.
+#
+
+ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__)
+
+bundle_binstub = File.expand_path("bundle", __dir__)
+
+if File.file?(bundle_binstub)
+ if File.read(bundle_binstub, 300).include?("This file was generated by Bundler")
+ load(bundle_binstub)
+ else
+ abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
+Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
+ end
+end
+
+require "rubygems"
+require "bundler/setup"
+
+load Gem.bin_path("rake", "rake")
diff --git a/providers/openfeature-go-feature-flag-provider/lib/openfeature/go-feature-flag/error/errors.rb b/providers/openfeature-go-feature-flag-provider/lib/openfeature/go-feature-flag/error/errors.rb
new file mode 100644
index 0000000..5900b08
--- /dev/null
+++ b/providers/openfeature-go-feature-flag-provider/lib/openfeature/go-feature-flag/error/errors.rb
@@ -0,0 +1,76 @@
+# Define a custom error class
+require "open_feature/sdk/provider/error_code"
+
+module OpenFeature
+ module GoFeatureFlag
+ class FlagNotFoundError < StandardError
+ attr_reader :response, :error_code, :error_message
+
+ def initialize(response, flag_key)
+ error_message = "Flag not found: #{flag_key}"
+ @response = response
+ @error_code = SDK::Provider::ErrorCode::FLAG_NOT_FOUND
+ @error_message = error_message
+ super(error_message)
+ end
+ end
+
+ class InternalServerError < StandardError
+ attr_reader :response, :error_code, :error_message
+
+ def initialize(response)
+ error_message = "Internal Server Error"
+ @response = response
+ @error_code = SDK::Provider::ErrorCode::GENERAL
+ @error_message = error_message
+ super(error_message)
+ end
+ end
+
+ class InvalidOptionError < StandardError
+ attr_reader :error_code, :error_message
+
+ def initialize(error_code, error_message)
+ @error_code = error_code
+ @error_message = error_message
+ super(error_message)
+ end
+ end
+
+ class UnauthorizedError < StandardError
+ attr_reader :response, :error_code, :error_message
+
+ def initialize(response)
+ error_message = "unauthorized"
+ @response = response
+ @error_code = SDK::Provider::ErrorCode::GENERAL
+ @error_message = error_message
+ super(error_message)
+ end
+ end
+
+ class ParseError < StandardError
+ attr_reader :response, :error_code, :error_message
+
+ def initialize(response)
+ error_message = "Parse error"
+ @response = response
+ @error_code = SDK::Provider::ErrorCode::PARSE_ERROR
+ @error_message = error_message
+ super(error_message)
+ end
+ end
+
+ class RateLimited < StandardError
+ attr_reader :response, :error_code, :error_message
+
+ def initialize(response)
+ error_message = response.nil? ? "Rate limited" : "Rate limited: " + response["Retry-After"].to_s
+ @response = response
+ @error_code = SDK::Provider::ErrorCode::GENERAL
+ @error_message = error_message
+ super(error_message)
+ end
+ end
+ end
+end
diff --git a/providers/openfeature-go-feature-flag-provider/lib/openfeature/go-feature-flag/go_feature_flag_provider.rb b/providers/openfeature-go-feature-flag-provider/lib/openfeature/go-feature-flag/go_feature_flag_provider.rb
new file mode 100644
index 0000000..9cb6f24
--- /dev/null
+++ b/providers/openfeature-go-feature-flag-provider/lib/openfeature/go-feature-flag/go_feature_flag_provider.rb
@@ -0,0 +1,89 @@
+# frozen_string_literal: true
+
+module OpenFeature
+ module GoFeatureFlag
+ # This class is the entry point for the GoFeatureFlagProvider
+ class Provider
+ PROVIDER_NAME = "GO Feature Flag Provider"
+ attr_reader :metadata, :options
+
+ def initialize(options: Options.new)
+ @metadata = SDK::Provider::ProviderMetadata.new(name: PROVIDER_NAME)
+ @options = options
+ @goff_api = GoFeatureFlagApi.new(options: options)
+ end
+
+ def fetch_boolean_value(flag_key:, default_value:, evaluation_context: nil)
+ evaluate(flag_key: flag_key, default_value: default_value, evaluation_context: evaluation_context, allowed_classes: [TrueClass, FalseClass])
+ end
+
+ def fetch_string_value(flag_key:, default_value:, evaluation_context: nil)
+ evaluate(flag_key: flag_key, default_value: default_value, evaluation_context: evaluation_context, allowed_classes: [String])
+ end
+
+ def fetch_number_value(flag_key:, default_value:, evaluation_context: nil)
+ evaluate(flag_key: flag_key, default_value: default_value, evaluation_context: evaluation_context, allowed_classes: [Integer, Float])
+ end
+
+ def fetch_object_value(flag_key:, default_value:, evaluation_context: nil)
+ evaluate(flag_key: flag_key, default_value: default_value, evaluation_context: evaluation_context, allowed_classes: [Array, Hash])
+ end
+
+ private
+
+ def evaluate(flag_key:, default_value:, allowed_classes:, evaluation_context: nil)
+ evaluation_context = OpenFeature::SDK::EvaluationContext.new if evaluation_context.nil?
+ validate_parameters(flag_key, evaluation_context)
+
+ # do a http call to the go feature flag server
+ parsed_response = @goff_api.evaluate_ofrep_api(flag_key: flag_key, evaluation_context: evaluation_context)
+ parsed_response = OfrepApiResponse unless parsed_response.is_a?(OfrepApiResponse)
+
+ if parsed_response.has_error?
+ return SDK::Provider::ResolutionDetails.new(
+ value: default_value,
+ error_code: parsed_response.error_code,
+ error_message: parsed_response.error_details,
+ reason: parsed_response.reason
+ )
+ end
+
+ unless allowed_classes.include?(parsed_response.value.class)
+ return SDK::Provider::ResolutionDetails.new(
+ value: default_value,
+ error_code: SDK::Provider::ErrorCode::TYPE_MISMATCH,
+ error_message: "flag type #{parsed_response.value.class} does not match allowed types #{allowed_classes}",
+ reason: SDK::Provider::Reason::ERROR
+ )
+ end
+
+ SDK::Provider::ResolutionDetails.new(
+ value: parsed_response.value,
+ reason: parsed_response.reason,
+ variant: parsed_response.variant,
+ flag_metadata: parsed_response.metadata
+ )
+ rescue UnauthorizedError,
+ InvalidOptionError,
+ FlagNotFoundError,
+ InternalServerError => e
+ SDK::Provider::ResolutionDetails.new(
+ value: default_value,
+ error_code: e.error_code,
+ error_message: e.error_message,
+ reason: SDK::Provider::Reason::ERROR
+ )
+ end
+
+ def validate_parameters(flag_key, evaluation_context)
+ if evaluation_context.nil? || evaluation_context.targeting_key.nil? || evaluation_context.targeting_key.empty?
+ raise InvalidOptionError.new(SDK::Provider::ErrorCode::INVALID_CONTEXT, "invalid evaluation context provided")
+ end
+
+ if flag_key.nil? || flag_key.empty?
+ raise InvalidOptionError.new(SDK::Provider::ErrorCode::GENERAL, "invalid flag key provided")
+ end
+ end
+ end
+ end
+end
diff --git a/providers/openfeature-go-feature-flag-provider/lib/openfeature/go-feature-flag/goff_api.rb b/providers/openfeature-go-feature-flag-provider/lib/openfeature/go-feature-flag/goff_api.rb
new file mode 100644
index 0000000..ffa8ffc
--- /dev/null
+++ b/providers/openfeature-go-feature-flag-provider/lib/openfeature/go-feature-flag/goff_api.rb
@@ -0,0 +1,149 @@
+# frozen_string_literal: true
+
+require "open_feature/sdk"
+require "net/http"
+require "json"
+require "faraday"
+require_relative "error/errors"
+require_relative "model/ofrep_api_response"
+
+module OpenFeature
+ module GoFeatureFlag
+ # This class is the entry point for the GoFeatureFlagProvider
+ class GoFeatureFlagApi
+ attr_reader :options
+ def initialize(options: {})
+ @options = options
+ @faraday_connection = Faraday.new(
+ url: @options.endpoint,
+ headers: {"Content-Type" => "application/json"}.merge(@options.custom_headers || {})
+ )
+ end
+
+ def evaluate_ofrep_api(flag_key:, evaluation_context:)
+ unless @retry_after.nil?
+ if Time.now < @retry_after
+ raise OpenFeature::GoFeatureFlag::RateLimited.new(nil)
+ else
+ @retry_after = nil
+ end
+ end
+
+ evaluation_context = OpenFeature::SDK::EvaluationContext.new if evaluation_context.nil?
+ # replace targeting_key by targetingKey
+ evaluation_context.fields["targetingKey"] = evaluation_context.targeting_key
+ evaluation_context.fields.delete("targeting_key")
+
+ response = @faraday_connection.post("/ofrep/v1/evaluate/flags/#{flag_key}") do |req|
+ req.body = {context: evaluation_context.fields}.to_json
+ end
+
+ case response.status
+ when 200
+ parse_success_response(response)
+ when 400
+ parse_error_response(response)
+ when 401, 403
+ raise OpenFeature::GoFeatureFlag::UnauthorizedError.new(response)
+ when 404
+ raise OpenFeature::GoFeatureFlag::FlagNotFoundError.new(response, flag_key)
+ when 429
+ parse_retry_later_header(response)
+ raise OpenFeature::GoFeatureFlag::RateLimited.new(response)
+ else
+ raise OpenFeature::GoFeatureFlag::InternalServerError.new(response)
+ end
+ end
+
+ private
+
+ def parse_error_response(response)
+ required_keys = %w[key error_code]
+ parsed = JSON.parse(response.body)
+
+ missing_keys = required_keys - parsed.keys
+ unless missing_keys.empty?
+ raise OpenFeature::GoFeatureFlag::ParseError.new(response)
+ end
+
+ OpenFeature::GoFeatureFlag::OfrepApiResponse.new(
+ value: nil,
+ key: parsed["key"],
+ reason: SDK::Provider::Reason::ERROR,
+ variant: nil,
+ error_code: error_code_mapper(parsed["error_code"]),
+ error_details: parsed["error_details"],
+ metadata: nil
+ )
+ end
+
+ def parse_success_response(response)
+ required_keys = %w[key value reason variant]
+ parsed = JSON.parse(response.body)
+
+ missing_keys = required_keys - parsed.keys
+ unless missing_keys.empty?
+ raise OpenFeature::GoFeatureFlag::ParseError.new(response)
+ end
+
+ OpenFeature::GoFeatureFlag::OfrepApiResponse.new(
+ value: parsed["value"],
+ key: parsed["key"],
+ reason: reason_mapper(parsed["reason"]),
+ variant: parsed["variant"],
+ error_code: nil,
+ error_details: nil,
+ metadata: parsed["metadata"]
+ )
+ end
+
+ def reason_mapper(reason_str)
+ reason_str = reason_str.upcase
+ reason_map = {
+ "STATIC" => SDK::Provider::Reason::STATIC,
+ "DEFAULT" => SDK::Provider::Reason::DEFAULT,
+ "TARGETING_MATCH" => SDK::Provider::Reason::TARGETING_MATCH,
+ "SPLIT" => SDK::Provider::Reason::SPLIT,
+ "CACHED" => SDK::Provider::Reason::CACHED,
+ "DISABLED" => SDK::Provider::Reason::DISABLED,
+ "UNKNOWN" => SDK::Provider::Reason::UNKNOWN,
+ "STALE" => SDK::Provider::Reason::STALE,
+ "ERROR" => SDK::Provider::Reason::ERROR
+ }
+ reason_map[reason_str] || SDK::Provider::Reason::UNKNOWN
+ end
+
+ def error_code_mapper(error_code_str)
+ error_code_str = error_code_str.upcase
+ error_code_map = {
+ "PROVIDER_NOT_READY" => SDK::Provider::ErrorCode::PROVIDER_NOT_READY,
+ "FLAG_NOT_FOUND" => SDK::Provider::ErrorCode::FLAG_NOT_FOUND,
+ "PARSE_ERROR" => SDK::Provider::ErrorCode::PARSE_ERROR,
+ "TYPE_MISMATCH" => SDK::Provider::ErrorCode::TYPE_MISMATCH,
+ "TARGETING_KEY_MISSING" => SDK::Provider::ErrorCode::TARGETING_KEY_MISSING,
+ "INVALID_CONTEXT" => SDK::Provider::ErrorCode::INVALID_CONTEXT,
+ "GENERAL" => SDK::Provider::ErrorCode::GENERAL
+ }
+ error_code_map[error_code_str] || SDK::Provider::ErrorCode::GENERAL
+ end
+
+ def parse_retry_later_header(response)
+ retry_after = response["Retry-After"]
+ return nil if retry_after.nil?
+
+ begin
+ @retry_after = if /^\d+$/.match?(retry_after)
+ # Retry-After is in seconds
+ Time.now + Integer(retry_after)
+ else
+ # Retry-After is an HTTP-date
+ Time.httpdate(retry_after)
+ end
+ rescue ArgumentError
+ # ignore invalid Retry-After header
+ nil
+ end
+ end
+ end
+ end
+end
diff --git a/providers/openfeature-go-feature-flag-provider/lib/openfeature/go-feature-flag/model/ofrep_api_response.rb b/providers/openfeature-go-feature-flag-provider/lib/openfeature/go-feature-flag/model/ofrep_api_response.rb
new file mode 100644
index 0000000..7fc327b
--- /dev/null
+++ b/providers/openfeature-go-feature-flag-provider/lib/openfeature/go-feature-flag/model/ofrep_api_response.rb
@@ -0,0 +1,32 @@
+module OpenFeature
+ module GoFeatureFlag
+ class OfrepApiResponse
+ attr_reader :value, :key, :reason, :variant, :error_code, :error_details, :metadata
+
+ def initialize(value:, key:, reason:, variant:, error_code:, error_details:, metadata:)
+ @value = value
+ @key = key
+ @reason = reason
+ @variant = variant
+ @error_code = error_code
+ @error_details = error_details
+ @metadata = metadata
+ end
+
+ def has_error?
+ !@error_code.nil? && !@error_code.empty?
+ end
+
+ def eql?(other)
+ return false unless other.is_a?(OpenFeature::GoFeatureFlag::OfrepApiResponse)
+ key == other.key &&
+ value == other.value &&
+ reason == other.reason &&
+ variant == other.variant &&
+ error_code == other.error_code &&
+ error_details == other.error_details &&
+ metadata == other.metadata
+ end
+ end
+ end
+end
diff --git a/providers/openfeature-go-feature-flag-provider/lib/openfeature/go-feature-flag/options.rb b/providers/openfeature-go-feature-flag-provider/lib/openfeature/go-feature-flag/options.rb
new file mode 100644
index 0000000..609b5fa
--- /dev/null
+++ b/providers/openfeature-go-feature-flag-provider/lib/openfeature/go-feature-flag/options.rb
@@ -0,0 +1,29 @@
+# frozen_string_literal: true
+
+require "uri"
+
+module OpenFeature
+ module GoFeatureFlag
+ # This class is the configuration class for the GoFeatureFlagProvider
+ class Options
+ attr_accessor :endpoint, :custom_headers
+
+ def initialize(endpoint: nil, headers: {})
+ validate_endpoint(endpoint: endpoint)
+ @endpoint = endpoint
+ @custom_headers = headers
+ end
+
+ private
+
+ def validate_endpoint(endpoint: nil)
+ return if endpoint.nil?
+
+ uri = URI.parse(endpoint)
+ raise ArgumentError, "Invalid URL for endpoint: #{endpoint}" unless uri.is_a?(URI::HTTP) || uri.is_a?(URI::HTTPS)
+ rescue URI::InvalidURIError
+ raise ArgumentError, "Invalid URL for endpoint: #{endpoint}"
+ end
+ end
+ end
+end
diff --git a/providers/openfeature-go-feature-flag-provider/lib/openfeature/go-feature-flag/version.rb b/providers/openfeature-go-feature-flag-provider/lib/openfeature/go-feature-flag/version.rb
new file mode 100644
index 0000000..b07d460
--- /dev/null
+++ b/providers/openfeature-go-feature-flag-provider/lib/openfeature/go-feature-flag/version.rb
@@ -0,0 +1,5 @@
+module OpenFeature
+ module GoFeatureFlag
+ GO_FEATURE_FLAG_PROVIDER_VERSION = "0.1.0"
+ end
+end
diff --git a/providers/openfeature-go-feature-flag-provider/openfeature-go-feature-flag-provider.gemspec b/providers/openfeature-go-feature-flag-provider/openfeature-go-feature-flag-provider.gemspec
new file mode 100644
index 0000000..aece293
--- /dev/null
+++ b/providers/openfeature-go-feature-flag-provider/openfeature-go-feature-flag-provider.gemspec
@@ -0,0 +1,41 @@
+# frozen_string_literal: true
+
+require_relative "lib/openfeature/go-feature-flag/version"
+
+Gem::Specification.new do |spec|
+ spec.name = "openfeature-go-feature-flag-provider"
+ spec.version = OpenFeature::GoFeatureFlag::GO_FEATURE_FLAG_PROVIDER_VERSION
+ spec.authors = ["Thomas Poignant"]
+ spec.email = ["contact@gofeatureflag.org"]
+
+ spec.summary = "The GO Feature Flag provider for the OpenFeature Ruby SDK"
+ spec.description = "The GO Feature Flag provider for the OpenFeature Ruby SDK"
+ spec.homepage = "https://github.com/open-feature/ruby-sdk-contrib/tree/main/providers/openfeature-go-feature-flag-provider"
+ spec.license = "Apache-2.0"
+ spec.required_ruby_version = ">= 3.1"
+
+ spec.metadata["homepage_uri"] = spec.homepage
+ spec.metadata["source_code_uri"] = "https://github.com/open-feature/ruby-sdk-contrib/tree/main/providers/openfeature-go-feature-flag-provider"
+ spec.metadata["changelog_uri"] = "https://github.com/open-feature/ruby-sdk-contrib/blob/main/providers/openfeature-go-feature-flag-provider/CHANGELOG.md"
+ spec.metadata["bug_tracker_uri"] = "https://github.com/thomaspoignant/go-feature-flag/issues/new/choose"
+ spec.metadata["documentation_uri"] = "https://gofeatureflag.org/docs"
+
+ # Specify which files should be added to the gem when it is released.
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
+ end
+ spec.bindir = "exe"
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
+ spec.require_paths = ["lib"]
+
+ spec.add_runtime_dependency "openfeature-sdk", "~> 0.3.1"
+ spec.add_runtime_dependency "faraday", "~> 2.10.1"
+
+ spec.add_development_dependency "rake", "~> 13.0"
+ spec.add_development_dependency "rspec", "~> 3.12.0"
+ spec.add_development_dependency "standard"
+ spec.add_development_dependency "rubocop"
+ spec.add_development_dependency "simplecov"
+ spec.add_development_dependency "webmock"
+end
diff --git a/providers/openfeature-go-feature-flag-provider/spec/openfeature/gofeatureflag/goff_api_spec.rb b/providers/openfeature-go-feature-flag-provider/spec/openfeature/gofeatureflag/goff_api_spec.rb
new file mode 100644
index 0000000..ec939f7
--- /dev/null
+++ b/providers/openfeature-go-feature-flag-provider/spec/openfeature/gofeatureflag/goff_api_spec.rb
@@ -0,0 +1,280 @@
+require "spec_helper"
+
+RSpec.describe OpenFeature::GoFeatureFlag::GoFeatureFlagApi do
+ subject(:goff_api) do
+ options = OpenFeature::GoFeatureFlag::Options.new(endpoint: "http://localhost:1031")
+ described_class.new(options: options)
+ end
+
+ let(:default_evaluation_context) do
+ OpenFeature::SDK::EvaluationContext.new(
+ targeting_key: "4f433951-4c8c-42b3-9f18-8c9a5ed8e9eb",
+ company: "GO Feature Flag",
+ firstname: "John",
+ lastname: "Doe"
+ )
+ end
+
+ context "#evaluate" do
+ it "should raise an error if rate limited" do
+ stub_request(:post, "http://localhost:1031/ofrep/v1/evaluate/flags/double_key")
+ .to_return(status: 429)
+
+ expect {
+ goff_api.evaluate_ofrep_api(flag_key: "double_key", evaluation_context: default_evaluation_context)
+ }.to raise_error(OpenFeature::GoFeatureFlag::RateLimited)
+ end
+
+ it "should raise an error if not authorized (401)" do
+ stub_request(:post, "http://localhost:1031/ofrep/v1/evaluate/flags/double_key")
+ .to_return(status: 401)
+
+ expect {
+ goff_api.evaluate_ofrep_api(flag_key: "double_key", evaluation_context: default_evaluation_context)
+ }.to raise_error(OpenFeature::GoFeatureFlag::UnauthorizedError)
+ end
+
+ it "should raise an error if not authorized (403)" do
+ stub_request(:post, "http://localhost:1031/ofrep/v1/evaluate/flags/double_key")
+ .to_return(status: 403)
+
+ expect {
+ goff_api.evaluate_ofrep_api(flag_key: "double_key", evaluation_context: default_evaluation_context)
+ }.to raise_error(OpenFeature::GoFeatureFlag::UnauthorizedError)
+ end
+
+ it "should raise an error if flag not found (404)" do
+ stub_request(:post, "http://localhost:1031/ofrep/v1/evaluate/flags/does-not-exists")
+ .to_return(status: 404)
+
+ expect {
+ goff_api.evaluate_ofrep_api(flag_key: "does-not-exists", evaluation_context: default_evaluation_context)
+ }.to raise_error(OpenFeature::GoFeatureFlag::FlagNotFoundError)
+ end
+
+ it "should raise an error if unknown http code (500)" do
+ stub_request(:post, "http://localhost:1031/ofrep/v1/evaluate/flags/double_key")
+ .to_return(status: 500)
+
+ expect {
+ goff_api.evaluate_ofrep_api(flag_key: "double_key", evaluation_context: default_evaluation_context)
+ }.to raise_error(OpenFeature::GoFeatureFlag::InternalServerError)
+ end
+
+ it "should return an error response if 400" do
+ stub_request(:post, "http://localhost:1031/ofrep/v1/evaluate/flags/double_key")
+ .to_return(status: 400, body:
+ {
+ key: "double_key",
+ error_code: "TYPE_MISMATCH",
+ error_details: "expected type: boolean, got: string"
+ }.to_json)
+
+ got = goff_api.evaluate_ofrep_api(flag_key: "double_key", evaluation_context: default_evaluation_context)
+ want = OpenFeature::GoFeatureFlag::OfrepApiResponse.new(
+ key: "double_key",
+ value: nil,
+ reason: OpenFeature::SDK::Provider::Reason::ERROR,
+ variant: nil,
+ error_code: OpenFeature::SDK::Provider::ErrorCode::TYPE_MISMATCH,
+ error_details: "expected type: boolean, got: string",
+ metadata: nil
+ )
+ expect(got).to eql(want)
+ end
+
+ it "should return a valid response if 200" do
+ stub_request(:post, "http://localhost:1031/ofrep/v1/evaluate/flags/double_key")
+ .to_return(status: 200, body:
+ {
+ key: "double_key",
+ metadata: {"website" => "https://gofeatureflag.org"},
+ value: 1.15,
+ reason: "TARGETING_MATCH",
+ variant: "variantA"
+ }.to_json)
+
+ got = goff_api.evaluate_ofrep_api(flag_key: "double_key", evaluation_context: default_evaluation_context)
+ want = OpenFeature::GoFeatureFlag::OfrepApiResponse.new(
+ key: "double_key",
+ value: 1.15,
+ reason: OpenFeature::SDK::Provider::Reason::TARGETING_MATCH,
+ variant: "variantA",
+ error_code: nil,
+ error_details: nil,
+ metadata: {"website" => "https://gofeatureflag.org"}
+ )
+ expect(got).to eql(want)
+ end
+
+ it "should raise an error if 200 and json does not contains the required keys (missing value)" do
+ stub_request(:post, "http://localhost:1031/ofrep/v1/evaluate/flags/double_key")
+ .to_return(status: 200, body:
+ {
+ key: "double_key",
+ metadata: {"website" => "https://gofeatureflag.org"},
+ reason: "TARGETING_MATCH",
+ variant: "variantA"
+ }.to_json)
+
+ expect {
+ goff_api.evaluate_ofrep_api(flag_key: "double_key", evaluation_context: default_evaluation_context)
+ }.to raise_error(OpenFeature::GoFeatureFlag::ParseError)
+ end
+
+ it "should raise an error if 200 and json does not contains the required keys (missing key)" do
+ stub_request(:post, "http://localhost:1031/ofrep/v1/evaluate/flags/double_key")
+ .to_return(status: 200, body:
+ {
+ value: 1.15,
+ metadata: {"website" => "https://gofeatureflag.org"},
+ reason: "TARGETING_MATCH",
+ variant: "variantA"
+ }.to_json)
+
+ expect {
+ goff_api.evaluate_ofrep_api(flag_key: "double_key", evaluation_context: default_evaluation_context)
+ }.to raise_error(OpenFeature::GoFeatureFlag::ParseError)
+ end
+
+ it "should raise an error if 200 and json does not contains the required keys (missing reason)" do
+ stub_request(:post, "http://localhost:1031/ofrep/v1/evaluate/flags/double_key")
+ .to_return(status: 200, body:
+ {
+ value: 1.15,
+ metadata: {"website" => "https://gofeatureflag.org"},
+ key: "double_key",
+ variant: "variantA"
+ }.to_json)
+
+ expect {
+ goff_api.evaluate_ofrep_api(flag_key: "double_key", evaluation_context: default_evaluation_context)
+ }.to raise_error(OpenFeature::GoFeatureFlag::ParseError)
+ end
+
+ it "should raise an error if 200 and json does not contains the required keys (missing variant)" do
+ stub_request(:post, "http://localhost:1031/ofrep/v1/evaluate/flags/double_key")
+ .to_return(status: 200, body:
+ {
+ value: 1.15,
+ metadata: {"website" => "https://gofeatureflag.org"},
+ key: "double_key",
+ reason: "TARGETING_MATCH"
+ }.to_json)
+
+ expect {
+ goff_api.evaluate_ofrep_api(flag_key: "double_key", evaluation_context: default_evaluation_context)
+ }.to raise_error(OpenFeature::GoFeatureFlag::ParseError)
+ end
+
+ it "should raise an error if 400 and json does not contains the required keys (missing key)" do
+ stub_request(:post, "http://localhost:1031/ofrep/v1/evaluate/flags/double_key")
+ .to_return(status: 400, body:
+ {
+ error_code: "TYPE_MISMATCH"
+ }.to_json)
+
+ expect {
+ goff_api.evaluate_ofrep_api(flag_key: "double_key", evaluation_context: default_evaluation_context)
+ }.to raise_error(OpenFeature::GoFeatureFlag::ParseError)
+ end
+
+ it "should raise an error if 400 and json does not contains the required keys (missing error_code)" do
+ stub_request(:post, "http://localhost:1031/ofrep/v1/evaluate/flags/double_key")
+ .to_return(status: 400, body:
+ {
+ key: "double_key"
+ }.to_json)
+
+ expect {
+ goff_api.evaluate_ofrep_api(flag_key: "double_key", evaluation_context: default_evaluation_context)
+ }.to raise_error(OpenFeature::GoFeatureFlag::ParseError)
+ end
+
+ it "should raise an error if 400 and json does not contains the required keys (missing error_code)" do
+ stub_request(:post, "http://localhost:1031/ofrep/v1/evaluate/flags/double_key")
+ .to_return(status: 400, body:
+ {
+ key: "double_key"
+ }.to_json)
+
+ expect {
+ goff_api.evaluate_ofrep_api(flag_key: "double_key", evaluation_context: default_evaluation_context)
+ }.to raise_error(OpenFeature::GoFeatureFlag::ParseError)
+ end
+
+ it "should not be able to call the API again if rate-limited (with retry-after int)" do
+ stub_request(:post, "http://localhost:1031/ofrep/v1/evaluate/flags/double_key")
+ .to_return(status: 429, headers: {"Retry-After" => "10"})
+
+ expect {
+ goff_api.evaluate_ofrep_api(flag_key: "double_key", evaluation_context: default_evaluation_context)
+ }.to raise_error(OpenFeature::GoFeatureFlag::RateLimited)
+
+ expect {
+ goff_api.evaluate_ofrep_api(flag_key: "random_flag", evaluation_context: default_evaluation_context)
+ }.to raise_error(OpenFeature::GoFeatureFlag::RateLimited)
+ end
+
+ it "should be able to call the API again if we wait after the retry-after (as int)" do
+ stub_request(:post, "http://localhost:1031/ofrep/v1/evaluate/flags/double_key")
+ .to_return(status: 429, headers: {"Retry-After" => "1"})
+ stub_request(:post, "http://localhost:1031/ofrep/v1/evaluate/flags/random_flag")
+ .to_return(status: 200, body:
+ {
+ value: 1.15,
+ metadata: {"website" => "https://gofeatureflag.org"},
+ key: "double_key",
+ reason: "TARGETING_MATCH",
+ variant: "variantA"
+ }.to_json)
+
+ expect {
+ goff_api.evaluate_ofrep_api(flag_key: "double_key", evaluation_context: default_evaluation_context)
+ }.to raise_error(OpenFeature::GoFeatureFlag::RateLimited)
+
+ sleep(1.1)
+
+ expect {
+ goff_api.evaluate_ofrep_api(flag_key: "random_flag", evaluation_context: default_evaluation_context)
+ }.not_to raise_error
+ end
+
+ it "should not be able to call the API again if rate-limited (with retry-after date)" do
+ stub_request(:post, "http://localhost:1031/ofrep/v1/evaluate/flags/double_key")
+ .to_return(status: 429, headers: {"Retry-After" => (Time.now + 1).httpdate})
+
+ expect {
+ goff_api.evaluate_ofrep_api(flag_key: "double_key", evaluation_context: default_evaluation_context)
+ }.to raise_error(OpenFeature::GoFeatureFlag::RateLimited)
+
+ expect {
+ goff_api.evaluate_ofrep_api(flag_key: "random_flag", evaluation_context: default_evaluation_context)
+ }.to raise_error(OpenFeature::GoFeatureFlag::RateLimited)
+ end
+
+ it "should be able to call the API again if we wait after the retry-after (as date)" do
+ stub_request(:post, "http://localhost:1031/ofrep/v1/evaluate/flags/double_key")
+ .to_return(status: 429, headers: {"Retry-After" => (Time.now + 1).httpdate})
+ stub_request(:post, "http://localhost:1031/ofrep/v1/evaluate/flags/random_flag")
+ .to_return(status: 200, body:
+ {
+ value: 1.15,
+ metadata: {"website" => "https://gofeatureflag.org"},
+ key: "double_key",
+ reason: "TARGETING_MATCH",
+ variant: "variantA"
+ }.to_json)
+
+ expect {
+ goff_api.evaluate_ofrep_api(flag_key: "double_key", evaluation_context: default_evaluation_context)
+ }.to raise_error(OpenFeature::GoFeatureFlag::RateLimited)
+
+ sleep(1.1)
+
+ expect {
+ goff_api.evaluate_ofrep_api(flag_key: "random_flag", evaluation_context: default_evaluation_context)
+ }.not_to raise_error
+ end
+ end
+end
diff --git a/providers/openfeature-go-feature-flag-provider/spec/openfeature/gofeatureflag/options_spec.rb b/providers/openfeature-go-feature-flag-provider/spec/openfeature/gofeatureflag/options_spec.rb
new file mode 100644
index 0000000..46e55e9
--- /dev/null
+++ b/providers/openfeature-go-feature-flag-provider/spec/openfeature/gofeatureflag/options_spec.rb
@@ -0,0 +1,18 @@
+require "spec_helper"
+
+RSpec.describe OpenFeature::GoFeatureFlag::Options do
+ context "#endpoint" do
+ it "should have a valid endpoint set" do
+ options = OpenFeature::GoFeatureFlag::Options.new(endpoint: "http://localhost:1031")
+ expect(options.endpoint).to eql("http://localhost:1031")
+ end
+
+ it "should raise if endpoint is invalid" do
+ expect { OpenFeature::GoFeatureFlag::Options.new(endpoint: "invalid_url") }.to raise_error(ArgumentError, "Invalid URL for endpoint: invalid_url")
+ end
+
+ it "should raise if endpoint is not http" do
+ expect { OpenFeature::GoFeatureFlag::Options.new(endpoint: "ftp://gofeatureflag.org") }.to raise_error(ArgumentError, "Invalid URL for endpoint: ftp://gofeatureflag.org")
+ end
+ end
+end
diff --git a/providers/openfeature-go-feature-flag-provider/spec/openfeature/gofeatureflag/provider_spec.rb b/providers/openfeature-go-feature-flag-provider/spec/openfeature/gofeatureflag/provider_spec.rb
new file mode 100644
index 0000000..30b17d1
--- /dev/null
+++ b/providers/openfeature-go-feature-flag-provider/spec/openfeature/gofeatureflag/provider_spec.rb
@@ -0,0 +1,687 @@
+require "spec_helper"
+
+RSpec.describe OpenFeature::GoFeatureFlag::Provider do
+ subject(:goff_provider) do
+ options = OpenFeature::GoFeatureFlag::Options.new(endpoint: "http://localhost:1031")
+ described_class.new(options: options)
+ end
+
+ context "#metadata" do
+ it "metadata name is defined" do
+ expect(goff_provider).to respond_to(:metadata)
+ expect(goff_provider.metadata).to respond_to(:name)
+ expect(goff_provider.metadata.name).to eq("GO Feature Flag Provider")
+ end
+ end
+
+ context "#options" do
+ it "should have a valid endpoint set" do
+ expect(goff_provider.options.endpoint).to eql("http://localhost:1031")
+ end
+
+ it "should raise if endpoint is invalid" do
+ expect { OpenFeature::GoFeatureFlag::Options.new(endpoint: "invalid_url") }.to raise_error(ArgumentError, "Invalid URL for endpoint: invalid_url")
+ end
+
+ it "should raise if endpoint is not http" do
+ expect { OpenFeature::GoFeatureFlag::Options.new(endpoint: "ftp://gofeatureflag.org") }.to raise_error(ArgumentError, "Invalid URL for endpoint: ftp://gofeatureflag.org")
+ end
+ end
+
+ context "#fetch_boolean_value with openfeature" do
+ it "should return the value of the flag" do
+ test_name = RSpec.current_example.description
+ stub_request(:post, "http://localhost:1031/ofrep/v1/evaluate/flags/boolean_flag")
+ .to_return(status: 200, body:
+ {
+ key: "double_key",
+ metadata: {"website" => "https://gofeatureflag.org"},
+ value: true,
+ reason: "TARGETING_MATCH",
+ variant: "variantA"
+ }.to_json)
+
+ OpenFeature::SDK.configure do |config|
+ config.set_provider(goff_provider, domain: test_name)
+ end
+ client = OpenFeature::SDK.build_client(domain: test_name)
+ got = client.fetch_boolean_details(
+ flag_key: "boolean_flag",
+ default_value: false,
+ evaluation_context: OpenFeature::SDK::EvaluationContext.new(targeting_key: "9b9450f8-ab5c-4dcf-872f-feda3f6ccb16")
+ )
+ want = OpenFeature::SDK::EvaluationDetails.new(
+ flag_key: "boolean_flag",
+ resolution_details: OpenFeature::SDK::Provider::ResolutionDetails.new(
+ value: true,
+ reason: OpenFeature::SDK::Provider::Reason::TARGETING_MATCH,
+ variant: "variantA",
+ flag_metadata: {"website" => "https://gofeatureflag.org"}
+ )
+ )
+ expect(got).to eql(want)
+ end
+
+ it "should return the default value if flag is not the right type" do
+ test_name = RSpec.current_example.description
+ stub_request(:post, "http://localhost:1031/ofrep/v1/evaluate/flags/boolean_flag")
+ .to_return(status: 200, body:
+ {
+ key: "double_key",
+ metadata: {"website" => "https://gofeatureflag.org"},
+ value: "default",
+ reason: "TARGETING_MATCH",
+ variant: "variantA"
+ }.to_json)
+
+ OpenFeature::SDK.configure do |config|
+ config.set_provider(goff_provider, domain: test_name)
+ end
+ client = OpenFeature::SDK.build_client(domain: test_name)
+ got = client.fetch_boolean_details(
+ flag_key: "boolean_flag",
+ default_value: false,
+ evaluation_context: OpenFeature::SDK::EvaluationContext.new(targeting_key: "9b9450f8-ab5c-4dcf-872f-feda3f6ccb16")
+ )
+ want = OpenFeature::SDK::EvaluationDetails.new(
+ flag_key: "boolean_flag",
+ resolution_details: OpenFeature::SDK::Provider::ResolutionDetails.new(
+ value: false,
+ reason: OpenFeature::SDK::Provider::Reason::ERROR,
+ error_code: OpenFeature::SDK::Provider::ErrorCode::TYPE_MISMATCH,
+ error_message: "flag type String does not match allowed types [TrueClass, FalseClass]"
+ )
+ )
+ expect(got).to eql(want)
+ end
+
+ it "should return the default value of the flag if error send by the API (http code 403)" do
+ test_name = RSpec.current_example.description
+ stub_request(:post, "http://localhost:1031/ofrep/v1/evaluate/flags/boolean_flag")
+ .to_return(status: 403)
+
+ OpenFeature::SDK.configure do |config|
+ config.set_provider(goff_provider, domain: test_name)
+ end
+ client = OpenFeature::SDK.build_client(domain: test_name)
+ got = client.fetch_boolean_details(
+ flag_key: "boolean_flag",
+ default_value: false,
+ evaluation_context: OpenFeature::SDK::EvaluationContext.new(targeting_key: "9b9450f8-ab5c-4dcf-872f-feda3f6ccb16")
+ )
+ want = OpenFeature::SDK::EvaluationDetails.new(
+ flag_key: "boolean_flag",
+ resolution_details: OpenFeature::SDK::Provider::ResolutionDetails.new(
+ value: false,
+ reason: OpenFeature::SDK::Provider::Reason::ERROR,
+ error_code: OpenFeature::SDK::Provider::ErrorCode::GENERAL,
+ error_message: "unauthorized"
+ )
+ )
+ expect(got).to eql(want)
+ end
+
+ it "should return the default value of the flag if error send by the API (http code 400)" do
+ test_name = RSpec.current_example.description
+ stub_request(:post, "http://localhost:1031/ofrep/v1/evaluate/flags/boolean_flag")
+ .to_return(status: 400, body:
+ {
+ key: "double_key",
+ error_code: "INVALID_CONTEXT"
+ }.to_json)
+
+ OpenFeature::SDK.configure do |config|
+ config.set_provider(goff_provider, domain: test_name)
+ end
+ client = OpenFeature::SDK.build_client(domain: test_name)
+ got = client.fetch_boolean_details(
+ flag_key: "boolean_flag",
+ default_value: false,
+ evaluation_context: OpenFeature::SDK::EvaluationContext.new(targeting_key: "9b9450f8-ab5c-4dcf-872f-feda3f6ccb16")
+ )
+ want = OpenFeature::SDK::EvaluationDetails.new(
+ flag_key: "boolean_flag",
+ resolution_details: OpenFeature::SDK::Provider::ResolutionDetails.new(
+ value: false,
+ reason: OpenFeature::SDK::Provider::Reason::ERROR,
+ error_code: OpenFeature::SDK::Provider::ErrorCode::INVALID_CONTEXT
+ )
+ )
+ expect(got).to eql(want)
+ end
+
+ it "should return default value if no evaluation context" do
+ test_name = RSpec.current_example.description
+ stub_request(:post, "http://localhost:1031/ofrep/v1/evaluate/flags/boolean_flag")
+ .to_return(status: 200, body:
+ {
+ key: "double_key",
+ metadata: {"website" => "https://gofeatureflag.org"},
+ value: true,
+ reason: "TARGETING_MATCH",
+ variant: "variantA"
+ }.to_json)
+
+ OpenFeature::SDK.configure do |config|
+ config.set_provider(goff_provider, domain: test_name)
+ end
+ client = OpenFeature::SDK.build_client(domain: test_name)
+ got = client.fetch_boolean_details(
+ flag_key: "boolean_flag",
+ default_value: false,
+ evaluation_context: nil
+ )
+ want = OpenFeature::SDK::EvaluationDetails.new(
+ flag_key: "boolean_flag",
+ resolution_details: OpenFeature::SDK::Provider::ResolutionDetails.new(
+ value: false,
+ reason: OpenFeature::SDK::Provider::Reason::ERROR,
+ error_code: OpenFeature::SDK::Provider::ErrorCode::INVALID_CONTEXT,
+ error_message: "invalid evaluation context provided"
+ )
+ )
+ expect(got).to eql(want)
+ end
+
+ it "should return default value if evaluation context has empty string targetingKey" do
+ test_name = RSpec.current_example.description
+ stub_request(:post, "http://localhost:1031/ofrep/v1/evaluate/flags/boolean_flag")
+ .to_return(status: 200, body:
+ {
+ key: "double_key",
+ metadata: {"website" => "https://gofeatureflag.org"},
+ value: true,
+ reason: "TARGETING_MATCH",
+ variant: "variantA"
+ }.to_json)
+
+ OpenFeature::SDK.configure do |config|
+ config.set_provider(goff_provider, domain: test_name)
+ end
+ client = OpenFeature::SDK.build_client(domain: test_name)
+ got = client.fetch_boolean_details(
+ flag_key: "boolean_flag",
+ default_value: false,
+ evaluation_context: OpenFeature::SDK::EvaluationContext.new(targeting_key: "")
+ )
+ want = OpenFeature::SDK::EvaluationDetails.new(
+ flag_key: "boolean_flag",
+ resolution_details: OpenFeature::SDK::Provider::ResolutionDetails.new(
+ value: false,
+ reason: OpenFeature::SDK::Provider::Reason::ERROR,
+ error_code: OpenFeature::SDK::Provider::ErrorCode::INVALID_CONTEXT,
+ error_message: "invalid evaluation context provided"
+ )
+ )
+ expect(got).to eql(want)
+ end
+
+ it "should return default value if evaluation context has nil targetingKey" do
+ test_name = RSpec.current_example.description
+ stub_request(:post, "http://localhost:1031/ofrep/v1/evaluate/flags/boolean_flag")
+ .to_return(status: 200, body:
+ {
+ key: "double_key",
+ metadata: {"website" => "https://gofeatureflag.org"},
+ value: true,
+ reason: "TARGETING_MATCH",
+ variant: "variantA"
+ }.to_json)
+
+ OpenFeature::SDK.configure do |config|
+ config.set_provider(goff_provider, domain: test_name)
+ end
+ client = OpenFeature::SDK.build_client(domain: test_name)
+ got = client.fetch_boolean_details(
+ flag_key: "boolean_flag",
+ default_value: false,
+ evaluation_context: OpenFeature::SDK::EvaluationContext.new(targeting_key: nil)
+ )
+ want = OpenFeature::SDK::EvaluationDetails.new(
+ flag_key: "boolean_flag",
+ resolution_details: OpenFeature::SDK::Provider::ResolutionDetails.new(
+ value: false,
+ reason: OpenFeature::SDK::Provider::Reason::ERROR,
+ error_code: OpenFeature::SDK::Provider::ErrorCode::INVALID_CONTEXT,
+ error_message: "invalid evaluation context provided"
+ )
+ )
+ expect(got).to eql(want)
+ end
+
+ it "should return default value if flag_key nil" do
+ test_name = RSpec.current_example.description
+ stub_request(:post, "http://localhost:1031/ofrep/v1/evaluate/flags/boolean_flag")
+ .to_return(status: 200, body:
+ {
+ key: "double_key",
+ metadata: {"website" => "https://gofeatureflag.org"},
+ value: true,
+ reason: "TARGETING_MATCH",
+ variant: "variantA"
+ }.to_json)
+
+ OpenFeature::SDK.configure do |config|
+ config.set_provider(goff_provider, domain: test_name)
+ end
+ client = OpenFeature::SDK.build_client(domain: test_name)
+ got = client.fetch_boolean_details(
+ flag_key: nil,
+ default_value: false,
+ evaluation_context: OpenFeature::SDK::EvaluationContext.new(targeting_key: "1234")
+ )
+ want = OpenFeature::SDK::EvaluationDetails.new(
+ flag_key: nil,
+ resolution_details: OpenFeature::SDK::Provider::ResolutionDetails.new(
+ value: false,
+ reason: OpenFeature::SDK::Provider::Reason::ERROR,
+ error_code: OpenFeature::SDK::Provider::ErrorCode::GENERAL,
+ error_message: "invalid flag key provided"
+ )
+ )
+ expect(got).to eql(want)
+ end
+
+ it "should return default value if flag_key empty string" do
+ test_name = RSpec.current_example.description
+ stub_request(:post, "http://localhost:1031/ofrep/v1/evaluate/flags/boolean_flag")
+ .to_return(status: 200, body:
+ {
+ key: "double_key",
+ metadata: {"website" => "https://gofeatureflag.org"},
+ value: true,
+ reason: "TARGETING_MATCH",
+ variant: "variantA"
+ }.to_json)
+
+ OpenFeature::SDK.configure do |config|
+ config.set_provider(goff_provider, domain: test_name)
+ end
+ client = OpenFeature::SDK.build_client(domain: test_name)
+ got = client.fetch_boolean_details(
+ flag_key: "",
+ default_value: false,
+ evaluation_context: OpenFeature::SDK::EvaluationContext.new(targeting_key: "1234")
+ )
+ want = OpenFeature::SDK::EvaluationDetails.new(
+ flag_key: "",
+ resolution_details: OpenFeature::SDK::Provider::ResolutionDetails.new(
+ value: false,
+ reason: OpenFeature::SDK::Provider::Reason::ERROR,
+ error_code: OpenFeature::SDK::Provider::ErrorCode::GENERAL,
+ error_message: "invalid flag key provided"
+ )
+ )
+ expect(got).to eql(want)
+ end
+ end
+
+ context "#fetch_string_value with openfeature" do
+ it "should return the value of the flag" do
+ test_name = RSpec.current_example.description
+ stub_request(:post, "http://localhost:1031/ofrep/v1/evaluate/flags/flag_key")
+ .to_return(status: 200, body:
+ {
+ key: "flag_key",
+ metadata: {"website" => "https://gofeatureflag.org"},
+ value: "aValue",
+ reason: "TARGETING_MATCH",
+ variant: "variantA"
+ }.to_json)
+
+ OpenFeature::SDK.configure do |config|
+ config.set_provider(goff_provider, domain: test_name)
+ end
+ client = OpenFeature::SDK.build_client(domain: test_name)
+ got = client.fetch_string_details(
+ flag_key: "flag_key",
+ default_value: "default",
+ evaluation_context: OpenFeature::SDK::EvaluationContext.new(targeting_key: "9b9450f8-ab5c-4dcf-872f-feda3f6ccb16")
+ )
+ want = OpenFeature::SDK::EvaluationDetails.new(
+ flag_key: "flag_key",
+ resolution_details: OpenFeature::SDK::Provider::ResolutionDetails.new(
+ value: "aValue",
+ variant: "variantA",
+ reason: OpenFeature::SDK::Provider::Reason::TARGETING_MATCH,
+ flag_metadata: {"website" => "https://gofeatureflag.org"}
+ )
+ )
+ expect(got).to eql(want)
+ end
+
+ it "should return the default value if flag is not the right type" do
+ test_name = RSpec.current_example.description
+ stub_request(:post, "http://localhost:1031/ofrep/v1/evaluate/flags/flag_key")
+ .to_return(status: 200, body:
+ {
+ key: "flag_key",
+ metadata: {"website" => "https://gofeatureflag.org"},
+ value: 15,
+ reason: "TARGETING_MATCH",
+ variant: "variantA"
+ }.to_json)
+
+ OpenFeature::SDK.configure do |config|
+ config.set_provider(goff_provider, domain: test_name)
+ end
+ client = OpenFeature::SDK.build_client(domain: test_name)
+ got = client.fetch_string_details(
+ flag_key: "flag_key",
+ default_value: "default",
+ evaluation_context: OpenFeature::SDK::EvaluationContext.new(targeting_key: "9b9450f8-ab5c-4dcf-872f-feda3f6ccb16")
+ )
+ want = OpenFeature::SDK::EvaluationDetails.new(
+ flag_key: "flag_key",
+ resolution_details: OpenFeature::SDK::Provider::ResolutionDetails.new(
+ value: "default",
+ reason: OpenFeature::SDK::Provider::Reason::ERROR,
+ error_code: OpenFeature::SDK::Provider::ErrorCode::TYPE_MISMATCH,
+ error_message: "flag type Integer does not match allowed types [String]"
+ )
+ )
+ expect(got).to eql(want)
+ end
+ end
+
+ context "#fetch_number_value with openfeature" do
+ it "should return the value of the flag" do
+ test_name = RSpec.current_example.description
+ stub_request(:post, "http://localhost:1031/ofrep/v1/evaluate/flags/flag_key")
+ .to_return(status: 200, body:
+ {
+ key: "flag_key",
+ metadata: {"website" => "https://gofeatureflag.org"},
+ value: 15,
+ reason: "TARGETING_MATCH",
+ variant: "variantA"
+ }.to_json)
+
+ OpenFeature::SDK.configure do |config|
+ config.set_provider(goff_provider, domain: test_name)
+ end
+ client = OpenFeature::SDK.build_client(domain: test_name)
+ got = client.fetch_number_details(
+ flag_key: "flag_key",
+ default_value: 25,
+ evaluation_context: OpenFeature::SDK::EvaluationContext.new(targeting_key: "9b9450f8-ab5c-4dcf-872f-feda3f6ccb16")
+ )
+ want = OpenFeature::SDK::EvaluationDetails.new(
+ flag_key: "flag_key",
+ resolution_details: OpenFeature::SDK::Provider::ResolutionDetails.new(
+ value: 15,
+ variant: "variantA",
+ reason: OpenFeature::SDK::Provider::Reason::TARGETING_MATCH,
+ flag_metadata: {"website" => "https://gofeatureflag.org"}
+ )
+ )
+ expect(got).to eql(want)
+ end
+
+ it "should return the default value if flag is not the right type" do
+ test_name = RSpec.current_example.description
+ stub_request(:post, "http://localhost:1031/ofrep/v1/evaluate/flags/flag_key")
+ .to_return(status: 200, body:
+ {
+ key: "flag_key",
+ metadata: {"website" => "https://gofeatureflag.org"},
+ value: "yoyo",
+ reason: "TARGETING_MATCH",
+ variant: "variantA"
+ }.to_json)
+
+ OpenFeature::SDK.configure do |config|
+ config.set_provider(goff_provider, domain: test_name)
+ end
+ client = OpenFeature::SDK.build_client(domain: test_name)
+ got = client.fetch_number_details(
+ flag_key: "flag_key",
+ default_value: 25,
+ evaluation_context: OpenFeature::SDK::EvaluationContext.new(targeting_key: "9b9450f8-ab5c-4dcf-872f-feda3f6ccb16")
+ )
+ want = OpenFeature::SDK::EvaluationDetails.new(
+ flag_key: "flag_key",
+ resolution_details: OpenFeature::SDK::Provider::ResolutionDetails.new(
+ value: 25,
+ reason: OpenFeature::SDK::Provider::Reason::ERROR,
+ error_code: OpenFeature::SDK::Provider::ErrorCode::TYPE_MISMATCH,
+ error_message: "flag type String does not match allowed types [Integer, Float]"
+ )
+ )
+ expect(got).to eql(want)
+ end
+ end
+
+ context "#fetch_object_value with openfeature" do
+ it "should return the value of the flag" do
+ test_name = RSpec.current_example.description
+ stub_request(:post, "http://localhost:1031/ofrep/v1/evaluate/flags/flag_key")
+ .to_return(status: 200, body:
+ {
+ key: "flag_key",
+ metadata: {"website" => "https://gofeatureflag.org"},
+ value: {"test" => "test"},
+ reason: "TARGETING_MATCH",
+ variant: "variantA"
+ }.to_json)
+
+ OpenFeature::SDK.configure do |config|
+ config.set_provider(goff_provider, domain: test_name)
+ end
+ client = OpenFeature::SDK.build_client(domain: test_name)
+ got = client.fetch_object_details(
+ flag_key: "flag_key",
+ default_value: {"fail" => true},
+ evaluation_context: OpenFeature::SDK::EvaluationContext.new(targeting_key: "9b9450f8-ab5c-4dcf-872f-feda3f6ccb16")
+ )
+ want = OpenFeature::SDK::EvaluationDetails.new(
+ flag_key: "flag_key",
+ resolution_details: OpenFeature::SDK::Provider::ResolutionDetails.new(
+ value: {"test" => "test"},
+ variant: "variantA",
+ reason: OpenFeature::SDK::Provider::Reason::TARGETING_MATCH,
+ flag_metadata: {"website" => "https://gofeatureflag.org"}
+ )
+ )
+ expect(got).to eql(want)
+ end
+
+ it "should return the default value if flag is not the right type" do
+ test_name = RSpec.current_example.description
+ stub_request(:post, "http://localhost:1031/ofrep/v1/evaluate/flags/flag_key")
+ .to_return(status: 200, body:
+ {
+ key: "flag_key",
+ metadata: {"website" => "https://gofeatureflag.org"},
+ value: '{"test" => "test"}',
+ reason: "TARGETING_MATCH",
+ variant: "variantA"
+ }.to_json)
+
+ OpenFeature::SDK.configure do |config|
+ config.set_provider(goff_provider, domain: test_name)
+ end
+ client = OpenFeature::SDK.build_client(domain: test_name)
+ got = client.fetch_object_details(
+ flag_key: "flag_key",
+ default_value: {"fail" => true},
+ evaluation_context: OpenFeature::SDK::EvaluationContext.new(targeting_key: "9b9450f8-ab5c-4dcf-872f-feda3f6ccb16")
+ )
+ want = OpenFeature::SDK::EvaluationDetails.new(
+ flag_key: "flag_key",
+ resolution_details: OpenFeature::SDK::Provider::ResolutionDetails.new(
+ value: {"fail" => true},
+ reason: OpenFeature::SDK::Provider::Reason::ERROR,
+ error_code: OpenFeature::SDK::Provider::ErrorCode::TYPE_MISMATCH,
+ error_message: "flag type String does not match allowed types [Array, Hash]"
+ )
+ )
+ expect(got).to eql(want)
+ end
+ end
+
+ context "#fetch_boolean_value provider directly" do
+ it "should return an error if no evaluation context" do
+ eval = goff_provider.fetch_boolean_value(flag_key: "flag_key", default_value: true, evaluation_context: nil)
+ want = OpenFeature::SDK::Provider::ResolutionDetails.new(
+ value: true,
+ error_code: OpenFeature::SDK::Provider::ErrorCode::INVALID_CONTEXT,
+ error_message: "invalid evaluation context provided",
+ reason: OpenFeature::SDK::Provider::Reason::ERROR
+ )
+ expect(eval).to eql(want)
+ end
+
+ it "should return an error if evaluation context has empty string targetingKey" do
+ eval = goff_provider.fetch_boolean_value(flag_key: "flag_key",
+ default_value: true,
+ evaluation_context: OpenFeature::SDK::EvaluationContext.new(targeting_key: ""))
+ want = OpenFeature::SDK::Provider::ResolutionDetails.new(
+ value: true,
+ error_code: OpenFeature::SDK::Provider::ErrorCode::INVALID_CONTEXT,
+ error_message: "invalid evaluation context provided",
+ reason: OpenFeature::SDK::Provider::Reason::ERROR
+ )
+ expect(eval).to eql(want)
+ end
+
+ it "should return an error if evaluation context has nil targetingKey" do
+ eval = goff_provider.fetch_boolean_value(flag_key: "flag_key",
+ default_value: true,
+ evaluation_context: OpenFeature::SDK::EvaluationContext.new(targeting_key: nil))
+ want = OpenFeature::SDK::Provider::ResolutionDetails.new(
+ value: true,
+ error_code: OpenFeature::SDK::Provider::ErrorCode::INVALID_CONTEXT,
+ error_message: "invalid evaluation context provided",
+ reason: OpenFeature::SDK::Provider::Reason::ERROR
+ )
+ expect(eval).to eql(want)
+ end
+
+ it "should return an error if flag_key nil" do
+ eval = goff_provider.fetch_boolean_value(flag_key: nil,
+ default_value: true,
+ evaluation_context: OpenFeature::SDK::EvaluationContext.new(targeting_key: "9b9450f8-ab5c-4dcf-872f-feda3f6ccb16"))
+ want = OpenFeature::SDK::Provider::ResolutionDetails.new(
+ value: true,
+ error_code: OpenFeature::SDK::Provider::ErrorCode::GENERAL,
+ error_message: "invalid flag key provided",
+ reason: OpenFeature::SDK::Provider::Reason::ERROR
+ )
+ expect(eval).to eql(want)
+ end
+
+ it "should return an error if flag_key empty string" do
+ eval = goff_provider.fetch_boolean_value(flag_key: "",
+ default_value: true,
+ evaluation_context: OpenFeature::SDK::EvaluationContext.new(targeting_key: "9b9450f8-ab5c-4dcf-872f-feda3f6ccb16"))
+ want = OpenFeature::SDK::Provider::ResolutionDetails.new(
+ value: true,
+ error_code: OpenFeature::SDK::Provider::ErrorCode::GENERAL,
+ error_message: "invalid flag key provided",
+ reason: OpenFeature::SDK::Provider::Reason::ERROR
+ )
+ expect(eval).to eql(want)
+ end
+
+ it "return an error API response if 401" do
+ stub_request(:post, "http://localhost:1031/ofrep/v1/evaluate/flags/boolean_flag")
+ .to_return(status: 401)
+ eval = goff_provider.fetch_boolean_value(
+ flag_key: "boolean_flag",
+ default_value: true,
+ evaluation_context: OpenFeature::SDK::EvaluationContext.new(targeting_key: "9b9450f8-ab5c-4dcf-872f-feda3f6ccb16")
+ )
+ want = OpenFeature::SDK::Provider::ResolutionDetails.new(
+ value: true,
+ error_code: OpenFeature::SDK::Provider::ErrorCode::GENERAL,
+ error_message: "unauthorized",
+ reason: OpenFeature::SDK::Provider::Reason::ERROR
+ )
+ expect(eval).to eql(want)
+ end
+
+ it "return an error API response if 403" do
+ stub_request(:post, "http://localhost:1031/ofrep/v1/evaluate/flags/boolean_flag")
+ .to_return(status: 403)
+ eval = goff_provider.fetch_boolean_value(
+ flag_key: "boolean_flag",
+ default_value: true,
+ evaluation_context: OpenFeature::SDK::EvaluationContext.new(targeting_key: "9b9450f8-ab5c-4dcf-872f-feda3f6ccb16")
+ )
+ want = OpenFeature::SDK::Provider::ResolutionDetails.new(
+ value: true,
+ error_code: OpenFeature::SDK::Provider::ErrorCode::GENERAL,
+ error_message: "unauthorized",
+ reason: OpenFeature::SDK::Provider::Reason::ERROR
+ )
+ expect(eval).to eql(want)
+ end
+
+ it "return an error API response if 400" do
+ stub_request(:post, "http://localhost:1031/ofrep/v1/evaluate/flags/boolean_flag")
+ .to_return(status: 400, body:
+ {
+ key: "boolean_flag",
+ error_code: OpenFeature::SDK::Provider::ErrorCode::GENERAL.to_s,
+ error_details: "GENERAL error"
+ }.to_json)
+ eval = goff_provider.fetch_boolean_value(
+ flag_key: "boolean_flag",
+ default_value: false,
+ evaluation_context: OpenFeature::SDK::EvaluationContext.new(targeting_key: "9b9450f8-ab5c-4dcf-872f-feda3f6ccb16")
+ )
+ want = OpenFeature::SDK::Provider::ResolutionDetails.new(
+ value: false,
+ error_code: OpenFeature::SDK::Provider::ErrorCode::GENERAL,
+ error_message: "GENERAL error",
+ reason: OpenFeature::SDK::Provider::Reason::ERROR
+ )
+ expect(eval).to eql(want)
+ end
+
+ it "return an error API response if flag not found 404" do
+ stub_request(:post, "http://localhost:1031/ofrep/v1/evaluate/flags/boolean_flag")
+ .to_return(status: 404, body:
+ {
+ key: "boolean_flag",
+ error_code: OpenFeature::SDK::Provider::ErrorCode::FLAG_NOT_FOUND.to_s,
+ error_details: "GENERAL error"
+ }.to_json)
+ eval = goff_provider.fetch_boolean_value(
+ flag_key: "boolean_flag",
+ default_value: false,
+ evaluation_context: OpenFeature::SDK::EvaluationContext.new(targeting_key: "9b9450f8-ab5c-4dcf-872f-feda3f6ccb16")
+ )
+ want = OpenFeature::SDK::Provider::ResolutionDetails.new(
+ value: false,
+ error_code: OpenFeature::SDK::Provider::ErrorCode::FLAG_NOT_FOUND,
+ error_message: "Flag not found: boolean_flag",
+ reason: OpenFeature::SDK::Provider::Reason::ERROR
+ )
+ expect(eval).to eql(want)
+ end
+
+ it "return an error API response if 500" do
+ stub_request(:post, "http://localhost:1031/ofrep/v1/evaluate/flags/boolean_flag")
+ .to_return(status: 500, body:
+ {
+ key: "boolean_flag",
+ error_code: OpenFeature::SDK::Provider::ErrorCode::GENERAL.to_s,
+ error_details: "GENERAL error"
+ }.to_json)
+ eval = goff_provider.fetch_boolean_value(
+ flag_key: "boolean_flag",
+ default_value: false,
+ evaluation_context: OpenFeature::SDK::EvaluationContext.new(targeting_key: "9b9450f8-ab5c-4dcf-872f-feda3f6ccb16")
+ )
+ want = OpenFeature::SDK::Provider::ResolutionDetails.new(
+ value: false,
+ error_code: OpenFeature::SDK::Provider::ErrorCode::GENERAL,
+ error_message: "Internal Server Error",
+ reason: OpenFeature::SDK::Provider::Reason::ERROR
+ )
+ expect(eval).to eql(want)
+ end
+ end
+end
diff --git a/providers/openfeature-go-feature-flag-provider/spec/spec_helper.rb b/providers/openfeature-go-feature-flag-provider/spec/spec_helper.rb
new file mode 100644
index 0000000..c0d12a9
--- /dev/null
+++ b/providers/openfeature-go-feature-flag-provider/spec/spec_helper.rb
@@ -0,0 +1,27 @@
+# frozen_string_literal: true
+
+require "bundler/setup"
+require "rspec"
+require "openfeature/go-feature-flag/go_feature_flag_provider"
+require "openfeature/go-feature-flag/options"
+require "openfeature/go-feature-flag/goff_api"
+require "open_feature/sdk"
+require "webmock/rspec"
+
+RSpec.configure do |config|
+ config.expect_with :rspec do |expectations|
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
+ end
+
+ config.mock_with :rspec do |mocks|
+ mocks.verify_partial_doubles = true
+ end
+
+ config.shared_context_metadata_behavior = :apply_to_host_groups
+ config.filter_run_when_matching :focus
+ config.example_status_persistence_file_path = "spec/examples.txt"
+ config.disable_monkey_patching!
+ config.warnings = true
+ config.order = :random
+ Kernel.srand config.seed
+end
diff --git a/release-please-config.json b/release-please-config.json
index 0b970c2..3148493 100644
--- a/release-please-config.json
+++ b/release-please-config.json
@@ -21,6 +21,16 @@
"extra-files": [
"README.md"
]
+ },
+ "providers/openfeature-go-feature-flag-provider": {
+ "package-name": "openfeature-go-feature-flag-provider",
+ "version-file": "lib/openfeature/go-feature-flag/version.rb",
+ "bump-minor-pre-major": true,
+ "bump-patch-for-minor-pre-major": true,
+ "versioning": "default",
+ "extra-files": [
+ "README.md"
+ ]
}
},
"changelog-sections": [
diff --git a/ruby-sdk-contrib.code-workspace b/ruby-sdk-contrib.code-workspace
index 8a3f8ce..2669c9a 100644
--- a/ruby-sdk-contrib.code-workspace
+++ b/ruby-sdk-contrib.code-workspace
@@ -5,6 +5,9 @@
},
{
"path": "providers/openfeature-meta_provider"
+ },
+ {
+ "path": "providers/openfeature-go-feature-flag-provider"
}
]
}