Skip to content
Draft
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
14 changes: 14 additions & 0 deletions providers/go-feature-flag/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
<wasm.version>0.2.4</wasm.version>
<!-- exclusion expression for e2e tests -->
<testExclusions>**/e2e/*.java</testExclusions>
<!-- Match any tck version locally; CI resolves it from the reactor -->
<tck.version>[0.1.0,)</tck.version>
</properties>

<developers>
Expand Down Expand Up @@ -112,6 +114,18 @@
<scope>test</scope>
</dependency>

<!--
OpenFeature Provider TCK. Brings its own Gherkin, step definitions and Compose
lifecycle; the classes under src/test/java/.../gofeatureflag/tck are the whole
adoption, run only by the root pom's `tck` profile.
-->
<dependency>
<groupId>dev.openfeature.contrib.tools</groupId>
<artifactId>tck</artifactId>
<version>${tck.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>testcontainers-junit-jupiter</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
*
* <p>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.
*
* <p>The backend is <a href="https://github.com/aepfli/goff-tck-testbed">aepfli/goff-tck-testbed</a>:
* 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.
*
* <p>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.
*
* <p>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<Integer> 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);
}
}
}
Original file line number Diff line number Diff line change
@@ -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}
*
* <p>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.
*
* <p>{@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<Capability> capabilities() {
return Capability.declarable();
}

@Override
public List<KnownDeviation> knownDeviations() {
return Collections.emptyList();
}
}
Original file line number Diff line number Diff line change
@@ -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.
*
* <p>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}
*
* <p>Withheld, each because this mode does not attempt it, and each measured as failing when
* declared:
*
* <ul>
* <li><b>{@link Capability#STALE}</b> and <b>{@link Capability#CONFIGURATION_CHANGE}</b> — the
* only outbound call is the per-evaluation OFREP request. Nothing polls, so a change or an
* outage is never observed as an event.
* <li><b>{@link Capability#UNAVAILABLE_INIT}</b> — {@code RemoteEvaluator.initialize} only
* initialises the OFREP provider, which never contacts the backend, so a provider pointed
* at a dead port reaches {@code READY}.
* <li><b>{@link Capability#NUMERIC_COERCION}</b> — OFREP carries no type, and the OFREP
* provider admits a value only on an exact instance check, so {@code integer-flag} asked
* for as a float returns the code default. Strict numeric typing is a legitimate choice,
* so no deviation. The in-process mode of this same provider does widen.
* <li><b>{@link Capability#DISABLED_FLAGS}</b> — the relay proxy answers a disabled flag with
* reason {@code DISABLED} and no value, OFREP's {@code codeDefaultFlag}, and the OFREP
* provider reports that as {@code FLAG_NOT_FOUND}, dropping the reason
* (java-sdk-contrib#1850). The value is the code default either way. Declare it again once
* that is fixed; the in-process mode of this same provider reports {@code DISABLED}.
* </ul>
*/
@Override
public Set<Capability> capabilities() {
return Capability.declarableExcept(
Capability.STALE,
Capability.CONFIGURATION_CHANGE,
Capability.UNAVAILABLE_INIT,
Capability.NUMERIC_COERCION,
Capability.DISABLED_FLAGS);
}
}
Original file line number Diff line number Diff line change
@@ -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
Loading