diff --git a/providers/go-feature-flag/pom.xml b/providers/go-feature-flag/pom.xml index d2e52e7fee..499247c3b9 100644 --- a/providers/go-feature-flag/pom.xml +++ b/providers/go-feature-flag/pom.xml @@ -23,6 +23,8 @@ 0.2.4 **/e2e/*.java + + [0.1.0,) @@ -112,6 +114,18 @@ test + + + dev.openfeature.contrib.tools + tck + ${tck.version} + test + + org.testcontainers testcontainers-junit-jupiter diff --git a/providers/go-feature-flag/src/test/java/dev/openfeature/contrib/providers/gofeatureflag/tck/AbstractGoFeatureFlagTest.java b/providers/go-feature-flag/src/test/java/dev/openfeature/contrib/providers/gofeatureflag/tck/AbstractGoFeatureFlagTest.java new file mode 100644 index 0000000000..250c76fdec --- /dev/null +++ b/providers/go-feature-flag/src/test/java/dev/openfeature/contrib/providers/gofeatureflag/tck/AbstractGoFeatureFlagTest.java @@ -0,0 +1,85 @@ +package dev.openfeature.contrib.providers.gofeatureflag.tck; + +import dev.openfeature.contrib.providers.gofeatureflag.GoFeatureFlagProvider; +import dev.openfeature.contrib.providers.gofeatureflag.GoFeatureFlagProviderOptions; +import dev.openfeature.contrib.providers.gofeatureflag.bean.EvaluationType; +import dev.openfeature.contrib.providers.gofeatureflag.exception.InvalidOptions; +import dev.openfeature.contrib.tools.tck.BackendEndpoint; +import dev.openfeature.contrib.tools.tck.ContainerizedProviderTckTest; +import dev.openfeature.sdk.FeatureProvider; +import java.io.File; +import java.util.Collections; +import java.util.List; + +/** + * Shared configuration for running the OpenFeature Provider TCK against the GO Feature Flag + * provider. + * + *

The provider evaluates in two quite different ways, and both are worth conforming: in-process + * pulls the flag configuration from the relay proxy and evaluates it in a WASM build of the GO + * Feature Flag engine, while remote asks the relay proxy over OFREP. They share a backend and differ + * only in evaluation type, so the modes are two small subclasses. + * + *

The backend is aepfli/goff-tck-testbed: + * the unmodified relay proxy, with a launchpad implementing the control API that writes its flag + * file and forces a retriever refresh. + */ +abstract class AbstractGoFeatureFlagTest extends ContainerizedProviderTckTest { + + /** The relay proxy's container-internal port, serving both evaluation types. */ + private static final int RELAY_PROXY_PORT = 1031; + + /** + * A port nothing listens on, for the initialisation-failure scenarios. + * + *

Deliberately not a port on the Compose stack: the stack must stay up for the whole suite, + * and simulated outages belong to the control API. + */ + private static final int UNAVAILABLE_PORT = 9999; + + /** + * How often the in-process evaluator polls the relay proxy for a changed configuration. + * + *

Lowered from the two-minute default, against which no event scenario can complete. Remote + * evaluation ignores it. + */ + private static final long FLAG_CHANGE_POLLING_INTERVAL_MS = 500; + + /** The evaluation type under test. */ + protected abstract EvaluationType evaluationType(); + + @Override + public File composeFile() { + return new File("src/test/resources/tck/docker-compose.yaml"); + } + + @Override + public List backendPorts() { + return Collections.singletonList(RELAY_PROXY_PORT); + } + + @Override + public FeatureProvider createProvider(BackendEndpoint endpoint) { + return provider(String.format("http://%s:%d/", endpoint.host(), endpoint.port(RELAY_PROXY_PORT))); + } + + @Override + public FeatureProvider createUnavailableProvider() { + return provider(String.format("http://localhost:%d/", UNAVAILABLE_PORT)); + } + + private FeatureProvider provider(String endpoint) { + try { + return new GoFeatureFlagProvider(GoFeatureFlagProviderOptions.builder() + .endpoint(endpoint) + .evaluationType(evaluationType()) + .flagChangePollingIntervalMs(FLAG_CHANGE_POLLING_INTERVAL_MS) + // The data collector is not part of the provider contract, and its background + // flushes would only add traffic to the backend under test. + .disableDataCollection(true) + .build()); + } catch (InvalidOptions e) { + throw new IllegalStateException("invalid GO Feature Flag provider options", e); + } + } +} diff --git a/providers/go-feature-flag/src/test/java/dev/openfeature/contrib/providers/gofeatureflag/tck/InProcessTest.java b/providers/go-feature-flag/src/test/java/dev/openfeature/contrib/providers/gofeatureflag/tck/InProcessTest.java new file mode 100644 index 0000000000..429448365e --- /dev/null +++ b/providers/go-feature-flag/src/test/java/dev/openfeature/contrib/providers/gofeatureflag/tck/InProcessTest.java @@ -0,0 +1,45 @@ +package dev.openfeature.contrib.providers.gofeatureflag.tck; + +import dev.openfeature.contrib.providers.gofeatureflag.bean.EvaluationType; +import dev.openfeature.contrib.tools.tck.Capability; +import dev.openfeature.contrib.tools.tck.KnownDeviation; +import java.util.Collections; +import java.util.List; +import java.util.Set; + +/** Runs the OpenFeature Provider TCK against the GO Feature Flag provider in in-process mode. */ +public class InProcessTest extends AbstractGoFeatureFlagTest { + + @Override + public String configuration() { + return "go-feature-flag-in-process"; + } + + @Override + protected EvaluationType evaluationType() { + return EvaluationType.IN_PROCESS; + } + + /** + * {@inheritDoc} + * + *

Everything declarable, and measured: 65 scenarios, 64 passing, and the one skip is + * {@code @large-integers}, which the TCK refuses for every Java provider because the integer + * accessor is 32-bit. + * + *

{@link Capability#NUMERIC_COERCION} passes in full, which is worth stating because the GO + * Feature Flag engine itself narrows any float to an integer on an integer request. The WASM build + * evaluates untyped here and this provider type-checks the result, so {@code float-flag} asked for + * as an integer reports {@code TYPE_MISMATCH} rather than {@code 0}. The lossless integral-float + * scenario passes without asserting much: the relay proxy serves {@code 10.0} as {@code 10}. + */ + @Override + public Set capabilities() { + return Capability.declarable(); + } + + @Override + public List knownDeviations() { + return Collections.emptyList(); + } +} diff --git a/providers/go-feature-flag/src/test/java/dev/openfeature/contrib/providers/gofeatureflag/tck/RemoteTest.java b/providers/go-feature-flag/src/test/java/dev/openfeature/contrib/providers/gofeatureflag/tck/RemoteTest.java new file mode 100644 index 0000000000..e2584d41e5 --- /dev/null +++ b/providers/go-feature-flag/src/test/java/dev/openfeature/contrib/providers/gofeatureflag/tck/RemoteTest.java @@ -0,0 +1,58 @@ +package dev.openfeature.contrib.providers.gofeatureflag.tck; + +import dev.openfeature.contrib.providers.gofeatureflag.bean.EvaluationType; +import dev.openfeature.contrib.tools.tck.Capability; +import java.util.Set; + +/** + * Runs the OpenFeature Provider TCK against the GO Feature Flag provider in remote mode. + * + *

Remote evaluation is the OFREP provider underneath ({@code RemoteEvaluator} wraps + * {@code OfrepProvider}), so its declarations follow the OFREP adoption's, and for the same reasons. + */ +public class RemoteTest extends AbstractGoFeatureFlagTest { + + @Override + public String configuration() { + return "go-feature-flag-remote"; + } + + @Override + protected EvaluationType evaluationType() { + return EvaluationType.REMOTE; + } + + /** + * {@inheritDoc} + * + *

Withheld, each because this mode does not attempt it, and each measured as failing when + * declared: + * + *

+ */ + @Override + public Set capabilities() { + return Capability.declarableExcept( + Capability.STALE, + Capability.CONFIGURATION_CHANGE, + Capability.UNAVAILABLE_INIT, + Capability.NUMERIC_COERCION, + Capability.DISABLED_FLAGS); + } +} diff --git a/providers/go-feature-flag/src/test/resources/tck/docker-compose.yaml b/providers/go-feature-flag/src/test/resources/tck/docker-compose.yaml new file mode 100644 index 0000000000..714e84d689 --- /dev/null +++ b/providers/go-feature-flag/src/test/resources/tck/docker-compose.yaml @@ -0,0 +1,16 @@ +# The GO Feature Flag provider-TCK backend: the relay proxy with a launchpad implementing the +# control API. https://github.com/aepfli/goff-tck-testbed +# +# The service is named "backend" because that is ContainerizedProviderTckTest's default. +# +# The image is PINNED, not :latest, so a push to the testbed cannot change this adoption's results +# with no diff here to explain it. +# +# Ports are never pinned. The TCK reads the dynamically mapped host ports after the stack is up, +# and POST /stop never restarts the container precisely so those mappings survive an outage. +services: + backend: + image: ${GOFF_TESTBED_IMAGE:-ghcr.io/aepfli/goff-tck-testbed:0.1.0} + ports: + - 1031 # relay proxy -- what the provider under test talks to + - 8080 # launchpad -- control API