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
9 changes: 6 additions & 3 deletions tools/tck/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ public class MyProviderTest extends ContainerizedProviderTckTest {
}
```

Note `endpoint.port(5000)` rather than `5000`: declared ports are container-internal, the
stack must not pin host ports, and Compose maps each to an arbitrary one.

That's the whole adoption. The TCK owns the Compose lifecycle, port discovery, control calls, provider
registration, event awaiting and teardown, and the assets are packaged in the JAR (no submodule
needed). If you find yourself adding test infrastructure here, please open an issue.
Expand Down Expand Up @@ -119,7 +122,7 @@ Overridable on `ContainerizedProviderTckTest`; names and defaults match every la
| Option | Default | Notes |
| --- | --- | --- |
| `composeFile()` | required | relative to the Maven module directory |
| `backendPorts()` | required | container ports the provider connects to; don't list the control port |
| `backendPorts()` | required | container-internal ports the provider connects to; don't list the control port. Resolve each with `endpoint.port(..)` |
| `backendService()` | `backend` | service hosting both the backend and control API |
| `controlPort()` | `8080` | |
| `additionalPorts()` | none | `Map<String, List<Integer>>` of extra service to ports, resolved via `BackendEndpoint` by service name |
Expand Down Expand Up @@ -247,7 +250,7 @@ src/test/java/openfeature/tck/extensions/FractionalSteps.java // package openf

- Same backend lifecycle and `BackendControl`; canonical steps are on the glue path, so an extension
can open with `Given a stable provider`.
- Step classes may inject `TckState` and use `TckRuntime.get()` for backend control and endpoint. Don't
- Step classes may inject `TckState` and use `ProviderTck.get()` for backend control and endpoint. Don't
build your own client; it would resolve against a provider the suite never registered.
- Don't put files under `gherkin/`; a same-named file would silently shadow a canonical one.
- Unknown tags are tolerated in `extensions/` (they gate nothing) but fail the run in `gherkin/`.
Expand Down Expand Up @@ -279,7 +282,7 @@ src/test/java/openfeature/tck/extensions/FractionalSteps.java // package openf

- See [Appendix F][appendix-f] for suite-wide gaps (context passthrough beyond the targeting key,
per-flag control, caching, `@stale` without containers, hooks, flag metadata).
- `TckRuntime` is static; suites in one JVM fork run sequentially, not concurrently.
- `ProviderTck` is static; suites in one JVM fork run sequentially, not concurrently.

## Contributing

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,39 @@
/**
* The seam between the TCK's step definitions and whatever manipulates the backend.
*
* <p>Use {@link HttpBackendControl} (via {@link ContainerizedProviderTckTest}) for providers with a
* backend; {@link InProcessBackendControl} only for providers with none. The connection operations
* default to throwing {@link UnsupportedOperationException}, a test-configuration bug rather than a
* skip.
* <p>Obtained from {@link #overHttp} (usually via {@link ContainerizedProviderTckTest}) for a
* provider with a backend, or {@link #inProcess()} for one with none. An implementation of its
* own must still declare its {@link BackendType}, a closed set, so the conformance claim stays
* valid. The connection operations default to throwing {@link UnsupportedOperationException}, a
* test-configuration bug rather than a skip.
*
* @see Capability
* @see ProviderTckTest
*/
public interface BackendControl {

/**
* Returns a control over the canonical control API, for a backend this suite did not start.
*
* @param baseUrl root of the control API, without a trailing slash
* @param backendConfiguration the configuration to seed, or {@code null} for none
* @return a control speaking the canonical control API
*/
static BackendControl overHttp(String baseUrl, String backendConfiguration) {
return new HttpBackendControl(baseUrl, backendConfiguration);
}

/**
* Returns a control for a provider with no backend, which also supplies the provider.
*
* <p>Appendix F's narrow allowance; a provider that has a backend must use the control API.
*
* @return an in-process control over a copy of the canonical flag set
*/
static InProcessControl inProcess() {
return new InProcessBackendControl();
}

/**
* Brings the backend to the baseline state: reachable, with the canonical flag set. Called before
* each scenario.
Expand Down Expand Up @@ -52,11 +75,17 @@ default String description() {
}

/**
* Returns how the backend is driven.
* Returns what kind of backend this run drives.
*
* <p>Defaults to {@link BackendType#CUSTOM}, which is the honest answer for a control the TCK
* does not ship. One that drives the canonical control API should return
* {@link BackendType#HTTP}.
*
* @return which of the two control contracts this run is conducted under
* @return what kind of backend this run drives
*/
ControlApi controlApi();
default BackendType backendType() {
return BackendType.CUSTOM;
}

/**
* Builds the exception the connection-control defaults throw.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package dev.openfeature.contrib.tools.tck;

import com.fasterxml.jackson.annotation.JsonValue;

/**
* What kind of backend a run drove: one reached over the control API, a provider with no backend
* inside this process, or a control the TCK does not ship.
*
* <p>Closed on purpose. A {@code String} here would be wider than the vocabulary a report can
* compare, and {@link #CUSTOM} already covers the case a third value would be invented for.
*
* @see BackendControl#backendType()
*/
public enum BackendType {

/** The normative control API: a real backend driven over {@code openapi/control-api.yaml}. */
HTTP("http"),

/** Control of a provider with no backend (in-memory, env var, file), inside this JVM. */
IN_PROCESS("in-process"),

/**
* A control the TCK does not ship, so the run is not directly comparable with the two above.
*
* <p>The default for an implementation of {@link BackendControl} that does not say otherwise.
* One that genuinely drives {@code openapi/control-api.yaml} should return {@link #HTTP}
* instead, and claim the comparability that goes with it.
*/
CUSTOM("custom");

private final String wireValue;

BackendType(String wireValue) {
this.wireValue = wireValue;
}

/**
* Returns the form this value takes in a conformance report.
*
* @return {@code http}, {@code in-process} or {@code custom}
*/
@JsonValue
public String wireValue() {
return wireValue;
}

/**
* Returns the wire form.
*
* @return {@code http}, {@code in-process} or {@code custom}
*/
@Override
public String toString() {
return wireValue;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.net.URI;
import java.util.Set;
import org.opentest4j.TestAbortedException;
import java.util.EnumSet;
import java.util.List;
import java.util.Optional;
Expand Down Expand Up @@ -114,7 +117,7 @@ public enum Capability {
*
* @return the Gherkin tag for this capability
*/
public String tag() {
String tag() {
return tag;
}

Expand All @@ -124,7 +127,7 @@ public String tag() {
*
* @return {@code true} if no scenario carries this capability's tag
*/
public boolean reserved() {
boolean reserved() {
return reserved;
}

Expand All @@ -134,7 +137,7 @@ public boolean reserved() {
* @return {@code true} if no provider written against this SDK can be asked this capability's
* scenarios
*/
public boolean inexpressible() {
boolean inexpressible() {
return inexpressibleBecause != null;
}

Expand All @@ -143,7 +146,7 @@ public boolean inexpressible() {
*
* @return the reason, or {@code null} if this capability is expressible
*/
public String inexpressibleBecause() {
String inexpressibleBecause() {
return inexpressibleBecause;
}

Expand All @@ -153,7 +156,7 @@ public String inexpressibleBecause() {
* @param tag a Gherkin tag including the leading {@code @}
* @return the matching capability, or empty if the tag does not gate a capability
*/
public static Optional<Capability> fromTag(String tag) {
static Optional<Capability> fromTag(String tag) {
return Arrays.stream(values()).filter(c -> c.tag.equals(tag)).findFirst();
}

Expand Down Expand Up @@ -211,4 +214,118 @@ public static void requireDeclarable(Collection<Capability> declared) {
+ "Remove them from capabilities().");
}
}

// The gate: whether a scenario counts, decided from its tags. Here because every rule is
// about this vocabulary, so inexpressibleBecause() need not be public. Static, not a
// ProviderTckHarness default, so an adopter cannot override the two checks that fail a run.


/**
* Applies the gate rules to a scenario of unknown source; the vocabulary check is skipped.
*
* @param tags the scenario's Gherkin tags, including the leading at-sign
* @param declared the capabilities the provider declares
* @throws IllegalStateException if a tag names a reserved capability
* @throws TestAbortedException if a tag gates an inexpressible or an undeclared capability
*/
static void requireDeclared(Collection<String> tags, Set<Capability> declared) {
requireDeclared(null, tags, declared);
}

/**
* Applies all gate rules to a scenario; reservation is checked first, since reserved tags can
* never be declared.
*
* @param source the scenario's feature file, as Cucumber reports it, or {@code null} if unknown
* @param tags the scenario's Gherkin tags, including the leading at-sign
* @param declared the capabilities the provider declares
* @throws IllegalStateException if a tag names a reserved capability, or if a canonical
* scenario carries a tag this vocabulary does not know
* @throws TestAbortedException if a tag gates an inexpressible or an undeclared capability
*/
public static void requireDeclared(URI source, Collection<String> tags, Set<Capability> declared) {
requireNoExpiredReservation(tags);
requireKnownVocabulary(source, tags);
for (String tag : tags) {
Optional<Capability> found = Capability.fromTag(tag);
if (!found.isPresent()) {
// adopter tag; gates nothing
continue;
}
Capability capability = found.get();
if (capability.inexpressible()) {
throw new TestAbortedException("Skipped: the Java SDK cannot express capability "
+ capability.name() + " (tag " + tag + "); " + capability.inexpressibleBecause()
+ ". This is not the provider under test declining.");
}
if (!declared.contains(capability)) {
throw new TestAbortedException("Skipped: provider does not declare capability " + capability.name()
+ " (tag " + tag + "). Declared capabilities: " + declared);
}
}
}

/**
* Fails the run if a canonical scenario carries a tag unknown to {@link Capability}; extension
* scenarios are exempt.
*
* @param source the scenario's feature file, as Cucumber reports it, or {@code null} if unknown
* @param tags the scenario's Gherkin tags, including the leading at-sign
* @throws IllegalStateException if the scenario is canonical and carries an unknown tag
*/
private static void requireKnownVocabulary(URI source, Collection<String> tags) {
if (!isCanonical(source)) {
return;
}
List<String> unknown = new ArrayList<>();
for (String tag : tags) {
if (!Capability.fromTag(tag).isPresent()) {
unknown.add(tag);
}
}
if (unknown.isEmpty()) {
return;
}
throw new IllegalStateException("The canonical scenario at " + source + " carries " + unknown
+ ", unknown to the Capability enum; add the capability to the enum, or move your own "
+ "feature file under " + ProviderTck.EXTENSIONS + "/.");
}

// canonical if the parent directory is FEATURES; null is not canonical
private static boolean isCanonical(URI source) {
if (source == null) {
return false;
}
String path = source.toString().replace('\\', '/');
int lastSeparator = path.lastIndexOf('/');
if (lastSeparator < 0) {
return false;
}
String parent = path.substring(0, lastSeparator);
int start = Math.max(parent.lastIndexOf('/'), parent.lastIndexOf(':')) + 1;
return ProviderTck.FEATURES.equals(parent.substring(start));
}

/**
* Fails the run if a scenario carries the tag of a reserved capability, which could otherwise
* never be declared and would be silently skipped.
*
* @param tags the scenario's Gherkin tags, including the leading at-sign
* @throws IllegalStateException if a tag names a reserved capability
*/
private static void requireNoExpiredReservation(Collection<String> tags) {
List<String> expired = new ArrayList<>();
for (String tag : tags) {
Optional<Capability> capability = Capability.fromTag(tag);
if (capability.isPresent() && capability.get().reserved()) {
expired.add(capability.get().name() + " (" + capability.get().tag() + ")");
}
}
if (expired.isEmpty()) {
return;
}
throw new IllegalStateException("This scenario carries reserved " + expired
+ "; drop the reserved flag in Capability if the tag is canonical, or use a tag of "
+ "your own in extensions/.");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,16 @@
/**
* Base JUnit Platform Suite for providers that talk to an external backend.
*
* <p>Manages the Docker Compose lifecycle (started once, never restarted), port discovery and an
* {@link HttpBackendControl}. See {@code tools/tck/README.md} for an example.
* <p>Manages the Docker Compose lifecycle (started once, never restarted), port discovery and the
* control over the canonical control API. See {@code tools/tck/README.md} for an example.
*
* <p>Every port declared here is container-internal. The stack must not pin host ports, so Compose
* maps each to an arbitrary one, and {@link BackendEndpoint} resolves that mapping -- which is why
* {@link #createProvider(BackendEndpoint)} is handed an endpoint instead of reading the
* declarations back. Dialling a declared port directly reaches nothing.
*
* @see ProviderTckTest
* @see HttpBackendControl
* @see BackendControl#overHttp
*/
public abstract class ContainerizedProviderTckTest extends ProviderTckTest {

Expand All @@ -40,6 +45,9 @@ public abstract class ContainerizedProviderTckTest extends ProviderTckTest {
* Returns the container-internal ports on {@link #backendService()} the provider connects to.
* {@link #controlPort()} is exposed automatically.
*
* <p>These are not the ports the provider dials. Pass each through
* {@link BackendEndpoint#port(int)} to get the host port Compose mapped it to.
*
* @return container-internal ports the provider connects to
*/
public abstract List<Integer> backendPorts();
Expand Down Expand Up @@ -81,7 +89,8 @@ public String backendService() {
}

/**
* Returns the container-internal port the control API listens on.
* Returns the container-internal port the control API listens on. Exposed and resolved like
* {@link #backendPorts()}; the TCK dials the mapped port itself.
*
* @return the control API port, {@code 8080} by default
*/
Expand Down
Loading
Loading