Skip to content

Commit 8d7cee6

Browse files
committed
fix: added e2e test
Signed-off-by: Pradeep <pradeepbbl@gmail.com>
1 parent cce43cd commit 8d7cee6

File tree

6 files changed

+154
-6
lines changed

6 files changed

+154
-6
lines changed

providers/flagd/src/test/java/dev/openfeature/contrib/providers/flagd/e2e/ContainerConfig.java

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,16 @@
22

33
import org.jetbrains.annotations.NotNull;
44
import org.testcontainers.containers.GenericContainer;
5+
import org.testcontainers.containers.Network;
56
import org.testcontainers.utility.DockerImageName;
7+
import org.testcontainers.utility.MountableFile;
68

79
import java.io.IOException;
810
import java.util.Properties;
911

1012
public class ContainerConfig {
1113
private static final String version;
14+
private static final Network network = Network.newNetwork();
1215

1316
static {
1417
Properties properties = new Properties();
@@ -24,19 +27,27 @@ public class ContainerConfig {
2427
*
2528
* @return a {@link org.testcontainers.containers.GenericContainer} instance of a stable sync flagd server with the port 9090 exposed
2629
*/
27-
public static GenericContainer sync() {
28-
return sync(false);
30+
public static GenericContainer sync() {
31+
return sync(false, false);
2932
}
3033

3134
/**
3235
*
3336
* @param unstable if an unstable version of the container, which terminates the connection regularly should be used.
37+
* @param addNetwork if set to true a custom network is attached for cross container access e.g. envoy --> sync:9090
3438
* @return a {@link org.testcontainers.containers.GenericContainer} instance of a sync flagd server with the port 9090 exposed
3539
*/
36-
public static GenericContainer sync(boolean unstable) {
40+
public static GenericContainer sync(boolean unstable, boolean addNetwork) {
3741
String container = generateContainerName("sync", unstable);
38-
return new GenericContainer(DockerImageName.parse(container))
42+
GenericContainer genericContainer = new GenericContainer(DockerImageName.parse(container))
3943
.withExposedPorts(9090);
44+
45+
if (addNetwork) {
46+
genericContainer.withNetwork(network);
47+
genericContainer.withNetworkAliases("sync-service");
48+
}
49+
50+
return genericContainer;
4051
}
4152

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

72+
73+
/**
74+
* @return a {@link org.testcontainers.containers.GenericContainer} instance of envoy container using
75+
* flagd sync service as backend expose on port 9211
76+
*
77+
*/
78+
public static GenericContainer envoy() {
79+
final String container = "envoyproxy/envoy:v1.31.0";
80+
return new GenericContainer(DockerImageName.parse(container))
81+
.withCopyFileToContainer(MountableFile.forClasspathResource("/envoy-config/envoy-custom.yaml"),
82+
"/etc/envoy/envoy.yaml")
83+
.withExposedPorts(9211)
84+
.withNetwork(network)
85+
.withNetworkAliases("envoy");
86+
}
87+
6188
private static @NotNull String generateContainerName(String type, boolean unstable) {
6289
String container = "ghcr.io/open-feature/";
6390
container += type;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package dev.openfeature.contrib.providers.flagd.e2e;
2+
3+
import org.junit.jupiter.api.Order;
4+
import org.junit.platform.suite.api.ConfigurationParameter;
5+
import org.junit.platform.suite.api.IncludeEngines;
6+
import org.junit.platform.suite.api.SelectClasspathResource;
7+
import org.junit.platform.suite.api.Suite;
8+
import org.testcontainers.junit.jupiter.Testcontainers;
9+
10+
import static io.cucumber.junit.platform.engine.Constants.GLUE_PROPERTY_NAME;
11+
import static io.cucumber.junit.platform.engine.Constants.PLUGIN_PROPERTY_NAME;
12+
13+
/**
14+
* Class for running the tests associated with "stable" e2e tests (no fake disconnection) for the in-process provider
15+
*/
16+
@Order(value = Integer.MAX_VALUE)
17+
@Suite
18+
@IncludeEngines("cucumber")
19+
@SelectClasspathResource("features/evaluation.feature")
20+
@SelectClasspathResource("features/flagd-json-evaluator.feature")
21+
@SelectClasspathResource("features/flagd.feature")
22+
@ConfigurationParameter(key = PLUGIN_PROPERTY_NAME, value = "pretty")
23+
@ConfigurationParameter(key = GLUE_PROPERTY_NAME, value = "dev.openfeature.contrib.providers.flagd.e2e.process.envoy,dev.openfeature.contrib.providers.flagd.e2e.steps")
24+
@Testcontainers
25+
public class RunFlagdInProcessEnvoyCucumberTest {
26+
27+
}

providers/flagd/src/test/java/dev/openfeature/contrib/providers/flagd/e2e/process/FlagdInProcessSetup.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,4 @@ public static void setup() throws InterruptedException {
3737
public static void tearDown() {
3838
flagdContainer.stop();
3939
}
40-
}
40+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package dev.openfeature.contrib.providers.flagd.e2e.process.envoy;
2+
3+
import dev.openfeature.contrib.providers.flagd.Config;
4+
import dev.openfeature.contrib.providers.flagd.FlagdOptions;
5+
import dev.openfeature.contrib.providers.flagd.FlagdProvider;
6+
import dev.openfeature.contrib.providers.flagd.e2e.ContainerConfig;
7+
import dev.openfeature.contrib.providers.flagd.e2e.steps.StepDefinitions;
8+
import dev.openfeature.sdk.FeatureProvider;
9+
import io.cucumber.java.AfterAll;
10+
import io.cucumber.java.BeforeAll;
11+
import org.junit.jupiter.api.Order;
12+
import org.junit.jupiter.api.parallel.Isolated;
13+
import org.testcontainers.containers.GenericContainer;
14+
15+
@Isolated()
16+
@Order(value = Integer.MAX_VALUE)
17+
public class FlagdInProcessSetup {
18+
19+
private static FeatureProvider provider;
20+
21+
private static final GenericContainer flagdContainer = ContainerConfig.sync(false, true);
22+
private static final GenericContainer envoyContainer = ContainerConfig.envoy();
23+
24+
@BeforeAll()
25+
public static void setup() throws InterruptedException {
26+
flagdContainer.start();
27+
envoyContainer.start();
28+
final String targetUri = String.format("envoy://localhost:%s/flagd-sync.service",
29+
envoyContainer.getFirstMappedPort());
30+
31+
FlagdInProcessSetup.provider = new FlagdProvider(FlagdOptions.builder()
32+
.resolverType(Config.Resolver.IN_PROCESS)
33+
// set a generous deadline, to prevent timeouts in actions
34+
.deadline(3000)
35+
.targetUri(targetUri)
36+
.build());
37+
StepDefinitions.setProvider(provider);
38+
}
39+
40+
@AfterAll
41+
public static void tearDown() {
42+
flagdContainer.stop();
43+
envoyContainer.stop();
44+
}
45+
}

providers/flagd/src/test/java/dev/openfeature/contrib/providers/flagd/e2e/reconnect/process/FlagdInProcessSetup.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
@Order(value = Integer.MAX_VALUE)
1818
public class FlagdInProcessSetup {
1919

20-
private static final GenericContainer flagdContainer = ContainerConfig.sync(true);
20+
private static final GenericContainer flagdContainer = ContainerConfig.sync(true, false);
2121
@BeforeAll()
2222
public static void setup() throws InterruptedException {
2323
flagdContainer.start();
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
static_resources:
2+
listeners:
3+
- name: local-envoy
4+
address:
5+
socket_address:
6+
address: 0.0.0.0
7+
port_value: 9211
8+
filter_chains:
9+
- filters:
10+
- name: envoy.filters.network.http_connection_manager
11+
typed_config:
12+
"@type": type.googleapis.com/envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager
13+
stat_prefix: ingress_http
14+
access_log:
15+
- name: envoy.access_loggers.stdout
16+
typed_config:
17+
"@type": type.googleapis.com/envoy.extensions.access_loggers.stream.v3.StdoutAccessLog
18+
http_filters:
19+
- name: envoy.filters.http.router
20+
typed_config:
21+
"@type": type.googleapis.com/envoy.extensions.filters.http.router.v3.Router
22+
route_config:
23+
name: local_route
24+
virtual_hosts:
25+
- name: local_service
26+
domains:
27+
- "flagd-sync.service"
28+
routes:
29+
- match:
30+
prefix: "/"
31+
grpc: {}
32+
route:
33+
cluster: local-sync-service
34+
35+
clusters:
36+
- name: local-sync-service
37+
type: LOGICAL_DNS
38+
# Comment out the following line to test on v6 networks
39+
dns_lookup_family: V4_ONLY
40+
http2_protocol_options: {}
41+
load_assignment:
42+
cluster_name: local-sync-service
43+
endpoints:
44+
- lb_endpoints:
45+
- endpoint:
46+
address:
47+
socket_address:
48+
address: sync-service
49+
port_value: 9090

0 commit comments

Comments
 (0)