Skip to content

Commit

Permalink
fix: added e2e test
Browse files Browse the repository at this point in the history
Signed-off-by: Pradeep <pradeepbbl@gmail.com>
  • Loading branch information
pradeepbbl committed Oct 15, 2024
1 parent cce43cd commit 8d7cee6
Show file tree
Hide file tree
Showing 6 changed files with 154 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@

import org.jetbrains.annotations.NotNull;
import org.testcontainers.containers.GenericContainer;
import org.testcontainers.containers.Network;
import org.testcontainers.utility.DockerImageName;
import org.testcontainers.utility.MountableFile;

import java.io.IOException;
import java.util.Properties;

public class ContainerConfig {
private static final String version;
private static final Network network = Network.newNetwork();

static {
Properties properties = new Properties();
Expand All @@ -24,19 +27,27 @@ public class ContainerConfig {
*
* @return a {@link org.testcontainers.containers.GenericContainer} instance of a stable sync flagd server with the port 9090 exposed
*/
public static GenericContainer sync() {
return sync(false);
public static GenericContainer sync() {
return sync(false, false);
}

/**
*
* @param unstable if an unstable version of the container, which terminates the connection regularly should be used.
* @param addNetwork if set to true a custom network is attached for cross container access e.g. envoy --> sync:9090
* @return a {@link org.testcontainers.containers.GenericContainer} instance of a sync flagd server with the port 9090 exposed
*/
public static GenericContainer sync(boolean unstable) {
public static GenericContainer sync(boolean unstable, boolean addNetwork) {
String container = generateContainerName("sync", unstable);
return new GenericContainer(DockerImageName.parse(container))
GenericContainer genericContainer = new GenericContainer(DockerImageName.parse(container))
.withExposedPorts(9090);

if (addNetwork) {
genericContainer.withNetwork(network);
genericContainer.withNetworkAliases("sync-service");
}

return genericContainer;
}

/**
Expand All @@ -58,6 +69,22 @@ public static GenericContainer flagd(boolean unstable) {
.withExposedPorts(8013);
}


/**
* @return a {@link org.testcontainers.containers.GenericContainer} instance of envoy container using
* flagd sync service as backend expose on port 9211
*
*/
public static GenericContainer envoy() {
final String container = "envoyproxy/envoy:v1.31.0";
return new GenericContainer(DockerImageName.parse(container))
.withCopyFileToContainer(MountableFile.forClasspathResource("/envoy-config/envoy-custom.yaml"),
"/etc/envoy/envoy.yaml")
.withExposedPorts(9211)
.withNetwork(network)
.withNetworkAliases("envoy");
}

private static @NotNull String generateContainerName(String type, boolean unstable) {
String container = "ghcr.io/open-feature/";
container += type;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package dev.openfeature.contrib.providers.flagd.e2e;

import org.junit.jupiter.api.Order;
import org.junit.platform.suite.api.ConfigurationParameter;
import org.junit.platform.suite.api.IncludeEngines;
import org.junit.platform.suite.api.SelectClasspathResource;
import org.junit.platform.suite.api.Suite;
import org.testcontainers.junit.jupiter.Testcontainers;

import static io.cucumber.junit.platform.engine.Constants.GLUE_PROPERTY_NAME;
import static io.cucumber.junit.platform.engine.Constants.PLUGIN_PROPERTY_NAME;

/**
* Class for running the tests associated with "stable" e2e tests (no fake disconnection) for the in-process provider
*/
@Order(value = Integer.MAX_VALUE)
@Suite
@IncludeEngines("cucumber")
@SelectClasspathResource("features/evaluation.feature")
@SelectClasspathResource("features/flagd-json-evaluator.feature")
@SelectClasspathResource("features/flagd.feature")
@ConfigurationParameter(key = PLUGIN_PROPERTY_NAME, value = "pretty")
@ConfigurationParameter(key = GLUE_PROPERTY_NAME, value = "dev.openfeature.contrib.providers.flagd.e2e.process.envoy,dev.openfeature.contrib.providers.flagd.e2e.steps")
@Testcontainers
public class RunFlagdInProcessEnvoyCucumberTest {

}
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,4 @@ public static void setup() throws InterruptedException {
public static void tearDown() {
flagdContainer.stop();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package dev.openfeature.contrib.providers.flagd.e2e.process.envoy;

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.ContainerConfig;
import dev.openfeature.contrib.providers.flagd.e2e.steps.StepDefinitions;
import dev.openfeature.sdk.FeatureProvider;
import io.cucumber.java.AfterAll;
import io.cucumber.java.BeforeAll;
import org.junit.jupiter.api.Order;
import org.junit.jupiter.api.parallel.Isolated;
import org.testcontainers.containers.GenericContainer;

@Isolated()
@Order(value = Integer.MAX_VALUE)
public class FlagdInProcessSetup {

private static FeatureProvider provider;

private static final GenericContainer flagdContainer = ContainerConfig.sync(false, true);
private static final GenericContainer envoyContainer = ContainerConfig.envoy();

@BeforeAll()
public static void setup() throws InterruptedException {
flagdContainer.start();
envoyContainer.start();
final String targetUri = String.format("envoy://localhost:%s/flagd-sync.service",
envoyContainer.getFirstMappedPort());

FlagdInProcessSetup.provider = new FlagdProvider(FlagdOptions.builder()
.resolverType(Config.Resolver.IN_PROCESS)
// set a generous deadline, to prevent timeouts in actions
.deadline(3000)
.targetUri(targetUri)
.build());
StepDefinitions.setProvider(provider);
}

@AfterAll
public static void tearDown() {
flagdContainer.stop();
envoyContainer.stop();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
@Order(value = Integer.MAX_VALUE)
public class FlagdInProcessSetup {

private static final GenericContainer flagdContainer = ContainerConfig.sync(true);
private static final GenericContainer flagdContainer = ContainerConfig.sync(true, false);
@BeforeAll()
public static void setup() throws InterruptedException {
flagdContainer.start();
Expand Down
49 changes: 49 additions & 0 deletions providers/flagd/src/test/resources/envoy-config/envoy-custom.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
static_resources:
listeners:
- name: local-envoy
address:
socket_address:
address: 0.0.0.0
port_value: 9211
filter_chains:
- filters:
- name: envoy.filters.network.http_connection_manager
typed_config:
"@type": type.googleapis.com/envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager
stat_prefix: ingress_http
access_log:
- name: envoy.access_loggers.stdout
typed_config:
"@type": type.googleapis.com/envoy.extensions.access_loggers.stream.v3.StdoutAccessLog
http_filters:
- name: envoy.filters.http.router
typed_config:
"@type": type.googleapis.com/envoy.extensions.filters.http.router.v3.Router
route_config:
name: local_route
virtual_hosts:
- name: local_service
domains:
- "flagd-sync.service"
routes:
- match:
prefix: "/"
grpc: {}
route:
cluster: local-sync-service

clusters:
- name: local-sync-service
type: LOGICAL_DNS
# Comment out the following line to test on v6 networks
dns_lookup_family: V4_ONLY
http2_protocol_options: {}
load_assignment:
cluster_name: local-sync-service
endpoints:
- lb_endpoints:
- endpoint:
address:
socket_address:
address: sync-service
port_value: 9090

0 comments on commit 8d7cee6

Please sign in to comment.