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
5 changes: 0 additions & 5 deletions providers/flagd/docker-compose.yml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import java.util.Map;
import java.util.function.Consumer;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;

/**
* Resolves flag values using
Expand Down Expand Up @@ -204,7 +205,7 @@ private <T> ProviderEvaluation<T> resolve(Class<T> type, String key, EvaluationC
// check variant existence
Object value = flag.getVariants().get(resolvedVariant);
if (value == null) {
if (resolvedVariant.isEmpty() && flag.getDefaultVariant().isEmpty()) {
if (StringUtils.isEmpty(resolvedVariant) && StringUtils.isEmpty(flag.getDefaultVariant())) {
return ProviderEvaluation.<T>builder()
.reason(Reason.ERROR.toString())
.errorCode(ErrorCode.FLAG_NOT_FOUND)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package dev.openfeature.contrib.providers.flagd.e2e;

import dev.openfeature.contrib.providers.flagd.Config;
import java.util.Optional;
import org.testcontainers.containers.ComposeContainer;
import org.testcontainers.containers.ContainerState;

public class ContainerUtil {
public static int getPort(ComposeContainer container, Config.Resolver resolver) {
Optional<ContainerState> flagd = container.getContainerByServiceName("flagd");

return flagd.map(containerState -> {
switch (resolver) {
case RPC:
return containerState.getMappedPort(8013);
case IN_PROCESS:
return containerState.getMappedPort(8015);
default:
return 0;
}
})
.orElseThrow(() -> new RuntimeException("Could not map port"));
}

public static String getLaunchpadUrl(ComposeContainer container) {
Optional<ContainerState> flagd = container.getContainerByServiceName("flagd");
return flagd.map(containerState -> {
return containerState.getHost() + ":" + containerState.getMappedPort(8080);
})
.orElseThrow(() -> new RuntimeException("Could not find launchpad url"));
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
@ConfigurationParameter(key = GLUE_PROPERTY_NAME, value = "dev.openfeature.contrib.providers.flagd.e2e.steps")
@ConfigurationParameter(key = OBJECT_FACTORY_PROPERTY_NAME, value = "io.cucumber.picocontainer.PicoFactory")
@IncludeTags("in-process")
@ExcludeTags({"unixsocket", "targetURI"})
@ExcludeTags({"unixsocket"})
@Testcontainers
@Isolated
public class RunInProcessTest {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
@ConfigurationParameter(key = GLUE_PROPERTY_NAME, value = "dev.openfeature.contrib.providers.flagd.e2e.steps")
@ConfigurationParameter(key = OBJECT_FACTORY_PROPERTY_NAME, value = "io.cucumber.picocontainer.PicoFactory")
@IncludeTags({"rpc"})
@ExcludeTags({"targetURI", "unixsocket"})
@ExcludeTags({"unixsocket"})
@Testcontainers
public class RunRpcTest {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@
import dev.openfeature.contrib.providers.flagd.Config;
import dev.openfeature.contrib.providers.flagd.FlagdOptions;
import dev.openfeature.contrib.providers.flagd.FlagdProvider;
import dev.openfeature.contrib.providers.flagd.e2e.FlagdContainer;
import dev.openfeature.contrib.providers.flagd.e2e.ContainerUtil;
import dev.openfeature.contrib.providers.flagd.e2e.State;
import dev.openfeature.sdk.FeatureProvider;
import dev.openfeature.sdk.OpenFeatureAPI;
import io.cucumber.java.After;
import io.cucumber.java.AfterAll;
import io.cucumber.java.Before;
import io.cucumber.java.BeforeAll;
import io.cucumber.java.en.Given;
import io.cucumber.java.en.When;
Expand All @@ -20,18 +19,21 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.time.Duration;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.RandomStringUtils;
import org.apache.commons.lang3.StringUtils;
import org.junit.jupiter.api.parallel.Isolated;
import org.testcontainers.containers.BindMode;
import org.testcontainers.containers.ComposeContainer;
import org.testcontainers.containers.wait.strategy.Wait;
import org.testcontainers.shaded.org.apache.commons.io.FileUtils;

@Isolated()
@Slf4j
public class ProviderSteps extends AbstractSteps {

public static final int UNAVAILABLE_PORT = 9999;
static FlagdContainer container;
static ComposeContainer container;

static Path sharedTempDir;

Expand All @@ -43,8 +45,14 @@ public ProviderSteps(State state) {
public static void beforeAll() throws IOException {
sharedTempDir = Files.createDirectories(
Paths.get("tmp/" + RandomStringUtils.randomAlphanumeric(8).toLowerCase() + "/"));
container = new FlagdContainer()
.withFileSystemBind(sharedTempDir.toAbsolutePath().toString(), "/flags", BindMode.READ_WRITE);
container = new ComposeContainer(new File("test-harness/docker-compose.yaml"))
.withEnv("FLAGS_DIR", sharedTempDir.toAbsolutePath().toString())
.withExposedService("flagd", 8013, Wait.forListeningPort())
.withExposedService("flagd", 8015, Wait.forListeningPort())
.withExposedService("flagd", 8080, Wait.forListeningPort())
.withExposedService("envoy", 9211, Wait.forListeningPort())
.withStartupTimeout(Duration.ofSeconds(45));
container.start();
}

@AfterAll
Expand All @@ -53,17 +61,10 @@ public static void afterAll() throws IOException {
FileUtils.deleteDirectory(sharedTempDir.toFile());
}

@Before
public void before() {
if (!container.isRunning()) {
container.start();
}
}

@After
public void tearDown() {
if (state.client != null) {
when().post("http://" + container.getLaunchpadUrl() + "/stop")
when().post("http://" + ContainerUtil.getLaunchpadUrl(container) + "/stop")
.then()
.statusCode(200);
}
Expand Down Expand Up @@ -100,7 +101,7 @@ public void setupProvider(String providerType) throws InterruptedException {
String absolutePath = file.getAbsolutePath();
this.state.providerType = ProviderType.SSL;
state.builder
.port(container.getPort(State.resolverType))
.port(ContainerUtil.getPort(container, State.resolverType))
.tls(true)
.certPath(absolutePath);
flagdConfig = "ssl";
Expand All @@ -117,12 +118,12 @@ public void setupProvider(String providerType) throws InterruptedException {
.port(UNAVAILABLE_PORT)
.offlineFlagSourcePath(new File("test-harness/flags/" + replace).getAbsolutePath());
} else {
state.builder.port(container.getPort(State.resolverType));
state.builder.port(ContainerUtil.getPort(container, State.resolverType));
}
break;
case "syncpayload":
flagdConfig = "sync-payload";
state.builder.port(container.getPort(State.resolverType));
state.builder.port(ContainerUtil.getPort(container, State.resolverType));
break;
case "stable":
this.state.providerType = ProviderType.DEFAULT;
Expand All @@ -135,13 +136,22 @@ public void setupProvider(String providerType) throws InterruptedException {
.toAbsolutePath()
.toString());
} else {
state.builder.port(container.getPort(State.resolverType));
state.builder.port(ContainerUtil.getPort(container, State.resolverType));
}
break;
default:
throw new IllegalStateException();
}
when().post("http://" + container.getLaunchpadUrl() + "/start?config={config}", flagdConfig)

// Setting TargetUri if this setting is set
FlagdOptions tempBuild = state.builder.build();
if (!StringUtils.isEmpty(tempBuild.getTargetUri())) {
String replace = tempBuild.getTargetUri().replace("<port>", "" + container.getServicePort("envoy", 9211));
state.builder.targetUri(replace);
state.builder.port(UNAVAILABLE_PORT);
}

when().post("http://" + ContainerUtil.getLaunchpadUrl(container) + "/start?config={config}", flagdConfig)
.then()
.statusCode(200);

Expand All @@ -162,18 +172,22 @@ public void setupProvider(String providerType) throws InterruptedException {

@When("the connection is lost")
public void the_connection_is_lost() {
when().post("http://" + container.getLaunchpadUrl() + "/stop").then().statusCode(200);
when().post("http://" + ContainerUtil.getLaunchpadUrl(container) + "/stop")
.then()
.statusCode(200);
}

@When("the connection is lost for {int}s")
public void the_connection_is_lost_for(int seconds) {
when().post("http://" + container.getLaunchpadUrl() + "/restart?seconds={seconds}", seconds)
when().post("http://" + ContainerUtil.getLaunchpadUrl(container) + "/restart?seconds={seconds}", seconds)
.then()
.statusCode(200);
}

@When("the flag was modified")
public void the_flag_was_modded() {
when().post("http://" + container.getLaunchpadUrl() + "/change").then().statusCode(200);
when().post("http://" + ContainerUtil.getLaunchpadUrl(container) + "/change")
.then()
.statusCode(200);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ public void we_have_an_option_of_type_with_value(String option, String type, Str
.filter(method1 -> method1.getName().equals(mapOptionNames(option)))
.findFirst()
.orElseThrow(RuntimeException::new);

method.invoke(state.builder, converted);
}

Expand Down

This file was deleted.

2 changes: 1 addition & 1 deletion providers/flagd/test-harness