Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions providers/openfeature-flagd-provider/Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ GEM
remote: https://rubygems.org/
specs:
ast (2.4.3)
base64 (0.3.0)
bigdecimal (4.0.1)
builder (3.3.0)
cucumber (9.2.1)
Expand Down Expand Up @@ -38,6 +39,11 @@ GEM
cucumber-tag-expressions (6.1.2)
diff-lcs (1.5.1)
docile (1.4.1)
docker-api (2.4.0)
excon (>= 0.64.0)
multi_json
excon (1.7.1)
logger
ffi (1.17.4)
ffi (1.17.4-arm64-darwin)
ffi (1.17.4-x86_64-linux-gnu)
Expand Down Expand Up @@ -67,6 +73,7 @@ GEM
logger (1.7.0)
memoist3 (1.0.0)
mini_mime (1.1.5)
multi_json (1.21.1)
multi_test (1.1.0)
openfeature-sdk (0.3.1)
parallel (1.27.0)
Expand Down Expand Up @@ -131,6 +138,8 @@ GEM
sys-uname (1.5.1)
ffi (~> 1.1)
memoist3 (~> 1.0.0)
testcontainers-core (0.2.0)
docker-api (~> 2.2)
unicode-display_width (3.2.0)
unicode-emoji (~> 4.1)
unicode-emoji (4.2.0)
Expand All @@ -142,6 +151,7 @@ PLATFORMS
x86_64-linux

DEPENDENCIES
base64
cucumber (~> 9.2)
logger
openfeature-flagd-provider!
Expand All @@ -150,6 +160,7 @@ DEPENDENCIES
rubocop
simplecov (~> 0.22)
standard
testcontainers-core (~> 0.2)

BUNDLED WITH
2.3.25
52 changes: 35 additions & 17 deletions providers/openfeature-flagd-provider/features/support/env.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,46 +3,64 @@
require "net/http"
require "uri"
require "rspec/expectations"
require "testcontainers"
require "open_feature/sdk"
require "openfeature/flagd/provider"

World(RSpec::Matchers)

# Boots the shared flagd testbed container and drives its launchpad so flagd is serving the
# standard flag set before the suite runs. Uses the Docker CLI directly (reliable on CI).
# Boots the flagd testbed container via testcontainers and drives its launchpad; version pinned to test-harness/version.txt
module Testbed
VERSION = File.read(File.expand_path("../../test-harness/version.txt", __dir__)).strip
IMAGE = "ghcr.io/open-feature/flagd-testbed:v#{VERSION}"
NAME = "flagd-e2e-ruby-#{Process.pid}"
RPC_PORT = 8013
HEALTH_PORT = 8014
LAUNCHPAD_PORT = 8080

module_function

def start
sh("docker rm -f #{NAME}")
raise "failed to start #{IMAGE} (is docker available?)" unless
sh("docker run -d --name #{NAME} -p 8013:8013 -p 8014:8014 -p 8080:8080 #{IMAGE}")
@container = Testcontainers::DockerContainer
.new(IMAGE)
.with_exposed_ports(RPC_PORT, HEALTH_PORT, LAUNCHPAD_PORT)
.with_wait_for(:tcp_port, LAUNCHPAD_PORT)
@container.start
Comment thread
coderabbitai[bot] marked this conversation as resolved.

# launchpad starts flagd with the default flag set
wait_for { http_code(:post, "http://localhost:8080/start") }
wait_for { http_code(:get, "http://localhost:8014/healthz") == "200" } ||
# start flagd via launchpad; retry since the mapped port opens before the app serves
launchpad = "http://#{host}:#{mapped(LAUNCHPAD_PORT)}/start"
wait_for { http_code(:post, launchpad) == "200" } ||
raise("launchpad did not start flagd in time")
wait_for { http_code(:get, "http://#{host}:#{mapped(HEALTH_PORT)}/healthz") == "200" } ||
raise("flagd testbed did not become healthy in time")

# point the provider at the mapped RPC port for this run
ENV["FLAGD_HOST"] = host
ENV["FLAGD_PORT"] = mapped(RPC_PORT).to_s
rescue
stop
raise
end

def stop
sh("docker rm -f #{NAME}")
@container&.stop
@container&.remove
rescue
nil
ensure
@container = nil
end

def sh(cmd)
system(cmd, out: File::NULL, err: File::NULL)
def host
@container.host
end

def mapped(port)
@container.mapped_port(port)
end

def http_code(verb, url)
uri = URI(url)
res = if verb == :post
Net::HTTP.post(uri, "")
else
Net::HTTP.get_response(uri)
end
res = (verb == :post) ? Net::HTTP.post(uri, "") : Net::HTTP.get_response(uri)
res.code
rescue
nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ Gem::Specification.new do |spec|
spec.add_development_dependency "rake", "~> 13.0"
spec.add_development_dependency "rspec", "~> 3.12.0"
spec.add_development_dependency "cucumber", "~> 9.2"
spec.add_development_dependency "testcontainers-core", "~> 0.2"
spec.add_development_dependency "base64"
spec.add_development_dependency "logger"
spec.add_development_dependency "standard"
spec.add_development_dependency "rubocop"
Expand Down