Skip to content

Commit c20d433

Browse files
committed
feat: GoFeatureFlagProvider support
currently only supporting configuring the endpoint. Using test containers to spin up instance to test against
1 parent 6f12d80 commit c20d433

File tree

3 files changed

+25
-14
lines changed

3 files changed

+25
-14
lines changed

src/main/java/io/github/sideshowcoder/dropwizard_openfeature/GoFeatureFlagConfiguration.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import dev.openfeature.contrib.providers.gofeatureflag.GoFeatureFlagProviderOptions;
66
import dev.openfeature.contrib.providers.gofeatureflag.GoFeatureFlagProviderOptions.GoFeatureFlagProviderOptionsBuilder;
7+
import dev.openfeature.contrib.providers.gofeatureflag.exception.InvalidOptions;
78
import jakarta.validation.constraints.NotNull;
89

910
public class GoFeatureFlagConfiguration {
@@ -12,12 +13,14 @@ public class GoFeatureFlagConfiguration {
1213
@NotNull
1314
private String endpoint;
1415

15-
public GoFeatureFlagProviderOptions getGoFeatureFlagProviderOptions() {
16+
public GoFeatureFlagProviderOptions getGoFeatureFlagProviderOptions() throws InvalidOptions {
1617
GoFeatureFlagProviderOptionsBuilder builder = GoFeatureFlagProviderOptions.builder();
1718

1819
builder.endpoint(endpoint);
1920

20-
return builder.build();
21+
GoFeatureFlagProviderOptions options = builder.build();
22+
options.validate();
23+
return options;
2124
}
2225

2326
}

src/main/java/io/github/sideshowcoder/dropwizard_openfeature/OpenFeatureBundle.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import dev.openfeature.contrib.providers.flagd.FlagdProvider;
44
import dev.openfeature.contrib.providers.gofeatureflag.GoFeatureFlagProvider;
5+
import dev.openfeature.contrib.providers.gofeatureflag.GoFeatureFlagProviderOptions;
56
import dev.openfeature.contrib.providers.gofeatureflag.exception.InvalidOptions;
67
import dev.openfeature.sdk.Client;
78
import dev.openfeature.sdk.FeatureProvider;

src/test/java/io/github/sideshowcoder/dropwizard_openfeature/OpenFeatureBundleGoFeatureFlagProviderTest.java

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import static org.junit.jupiter.api.Assertions.assertEquals;
44
import static org.junit.jupiter.api.Assertions.assertTrue;
55

6+
import java.util.List;
7+
68
import org.junit.jupiter.api.Test;
79
import org.junit.jupiter.api.extension.ExtendWith;
810
import org.testcontainers.containers.GenericContainer;
@@ -15,6 +17,8 @@
1517
import com.codahale.metrics.health.HealthCheck;
1618

1719
import dev.openfeature.sdk.Client;
20+
import dev.openfeature.sdk.EvaluationContext;
21+
import dev.openfeature.sdk.ImmutableContext;
1822
import dev.openfeature.sdk.OpenFeatureAPI;
1923
import io.dropwizard.testing.ResourceHelpers;
2024
import io.dropwizard.testing.junit5.DropwizardAppExtension;
@@ -27,17 +31,18 @@
2731
public class OpenFeatureBundleGoFeatureFlagProviderTest {
2832

2933
@Container
30-
public GenericContainer goFeatureFlagRelay = new GenericContainer<>(DockerImageName.parse("gofeatureflag/go-feature-flag:latest"))
31-
.withExposedPorts(1031)
32-
.withCopyFileToContainer(MountableFile.forClasspathResource("goff-proxy.yaml"), "/goff/goff-proxy.yaml")
33-
.withCopyFileToContainer(MountableFile.forClasspathResource("go-feature-flags-flags.yaml"), "/goff/flags.yaml")
34-
.waitingFor(Wait.forHttp("/health"));
35-
36-
// TODO need to start container before dropwizard app! Need to bundle it in some kind of @BeforeAll or something to start the dropwizard app.
37-
// TODO start the gofeatureflag/go-feature-flag:latest docker image which is the relay proxy to interact with the provider https://gofeatureflag.org/docs/relay-proxy/getting_started
38-
// TODO set endpoint to the endpoint provider via the docker container
39-
// TODO create class to parse the configuration options see https://gofeatureflag.org/docs/relay-proxy/getting_started for available options
40-
// TODO how can I make this work on github? Can I start docker containers there?
34+
private static GenericContainer<?> goFeatureFlagRelay = createGoFeatureFlagContainer();
35+
36+
private static GenericContainer<?> createGoFeatureFlagContainer() {
37+
GenericContainer<?> container = new GenericContainer<>(DockerImageName.parse("gofeatureflag/go-feature-flag:latest"))
38+
.withCopyFileToContainer(MountableFile.forClasspathResource("goff-proxy.yaml"), "/goff/goff-proxy.yaml")
39+
.withCopyFileToContainer(MountableFile.forClasspathResource("go-feature-flags-flags.yaml"), "/goff/flags.yaml");
40+
41+
container.setPortBindings(List.of("1031:1031"));
42+
container.waitingFor(Wait.forHttp("/health"));
43+
44+
return container;
45+
}
4146

4247
private static final DropwizardAppExtension<Config> APP = new DropwizardAppExtension<>(
4348
App.class,
@@ -53,6 +58,8 @@ public void initializesHealthCheck() throws Exception {
5358
@Test
5459
public void providesFeatureFlagsViaInMemoryProvider() throws Exception {
5560
Client client = OpenFeatureAPI.getInstance().getClient("go-feature-flag-client");
56-
assertEquals("red", client.getStringValue("staticstringflag", "not-expected-value"));
61+
// GoFeatureFlags requires a target key for all queries!
62+
EvaluationContext ctx = new ImmutableContext("target");
63+
assertEquals("red", client.getStringValue("staticstringflag", "not-expected-value", ctx));
5764
}
5865
}

0 commit comments

Comments
 (0)