|
| 1 | +package io.github.sideshowcoder.dropwizard_openfeature; |
| 2 | + |
| 3 | +import static org.junit.jupiter.api.Assertions.assertEquals; |
| 4 | +import static org.junit.jupiter.api.Assertions.assertTrue; |
| 5 | + |
| 6 | +import java.util.List; |
| 7 | + |
| 8 | +import org.junit.jupiter.api.Test; |
| 9 | +import org.junit.jupiter.api.extension.ExtendWith; |
| 10 | +import org.testcontainers.containers.GenericContainer; |
| 11 | +import org.testcontainers.containers.wait.strategy.Wait; |
| 12 | +import org.testcontainers.junit.jupiter.Container; |
| 13 | +import org.testcontainers.junit.jupiter.Testcontainers; |
| 14 | +import org.testcontainers.utility.DockerImageName; |
| 15 | +import org.testcontainers.utility.MountableFile; |
| 16 | + |
| 17 | +import com.codahale.metrics.health.HealthCheck; |
| 18 | + |
| 19 | +import dev.openfeature.sdk.Client; |
| 20 | +import dev.openfeature.sdk.EvaluationContext; |
| 21 | +import dev.openfeature.sdk.ImmutableContext; |
| 22 | +import dev.openfeature.sdk.OpenFeatureAPI; |
| 23 | +import io.dropwizard.testing.ResourceHelpers; |
| 24 | +import io.dropwizard.testing.junit5.DropwizardAppExtension; |
| 25 | +import io.dropwizard.testing.junit5.DropwizardExtensionsSupport; |
| 26 | +import io.github.sideshowcoder.dropwizard_openfeature.helpers.App; |
| 27 | +import io.github.sideshowcoder.dropwizard_openfeature.helpers.Config; |
| 28 | + |
| 29 | +@Testcontainers |
| 30 | +@ExtendWith(DropwizardExtensionsSupport.class) |
| 31 | +public class OpenFeatureBundleGoFeatureFlagProviderTest { |
| 32 | + |
| 33 | + @Container |
| 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 | + } |
| 46 | + |
| 47 | + private static final DropwizardAppExtension<Config> APP = new DropwizardAppExtension<>( |
| 48 | + App.class, |
| 49 | + ResourceHelpers.resourceFilePath("go-feature-flag-provider-config.yml") |
| 50 | + ); |
| 51 | + |
| 52 | + @Test |
| 53 | + public void initializesHealthCheck() throws Exception { |
| 54 | + HealthCheck.Result healthcheckResult = APP.getEnvironment().healthChecks().runHealthCheck("openfeature-health-check"); |
| 55 | + assertTrue(healthcheckResult.isHealthy()); |
| 56 | + } |
| 57 | + |
| 58 | + @Test |
| 59 | + public void providesFeatureFlagsViaInMemoryProvider() throws Exception { |
| 60 | + Client client = OpenFeatureAPI.getInstance().getClient("go-feature-flag-client"); |
| 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)); |
| 64 | + } |
| 65 | +} |
0 commit comments