Skip to content

feat(flagd): testcontainers instead of docker compose #860

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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
21 changes: 0 additions & 21 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,6 @@ on:
jobs:
main:
runs-on: ubuntu-latest
services:
# flagd-testbed for flagd RPC provider e2e tests
flagd:
image: ghcr.io/open-feature/flagd-testbed:v0.5.5
ports:
- 8013:8013
# flagd-testbed for flagd RPC provider reconnect e2e tests
flagd-unstable:
image: ghcr.io/open-feature/flagd-testbed-unstable:v0.5.5
ports:
- 8014:8013
# sync-testbed for flagd in-process provider e2e tests
sync:
image: ghcr.io/open-feature/sync-testbed:v0.5.5
ports:
- 9090:9090
# sync-testbed for flagd in-process provider reconnect e2e tests
sync-unstable:
image: ghcr.io/open-feature/sync-testbed-unstable:v0.5.5
ports:
- 9091:9090

steps:
- name: Checkout Repository
Expand Down
17 changes: 0 additions & 17 deletions providers/flagd/docker-compose.yaml

This file was deleted.

21 changes: 20 additions & 1 deletion providers/flagd/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,25 @@
<version>1.17.0</version>
</dependency>

<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>5.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>testcontainers</artifactId>
<version>1.19.8</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>junit-jupiter</artifactId>
<version>1.19.8</version>
<scope>test</scope>
</dependency>

</dependencies>

<build>
Expand Down Expand Up @@ -402,4 +421,4 @@
</profile>
</profiles>

</project>
</project>
2 changes: 1 addition & 1 deletion providers/flagd/schemas
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package dev.openfeature.contrib.providers.flagd.e2e;

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

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

public class ContainerConfig {
private static final String version;

static {
Properties properties = new Properties();
try {
properties.load(Thread.currentThread().getContextClassLoader().getResourceAsStream("flagdTestbed.properties"));
version = properties.getProperty("version");
} catch (IOException e) {
throw new RuntimeException(e);
}
}

/**
*
* @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);
}

/**
*
* @param unstable if an unstable version of the container, which terminates the connection regularly should be used.
* @return a {@link org.testcontainers.containers.GenericContainer} instance of a sync flagd server with the port 9090 exposed
*/
public static GenericContainer sync(boolean unstable) {
String container = generateContainerName("sync", unstable);
return new GenericContainer(DockerImageName.parse(container))
.withExposedPorts(9090);
}

/**
*
* @return a {@link org.testcontainers.containers.GenericContainer} instance of a stable flagd server with the port 8013 exposed
*/
public static GenericContainer flagd() {
return flagd(false);
}

/**
*
* @param unstable if an unstable version of the container, which terminates the connection regularly should be used.
* @return a {@link org.testcontainers.containers.GenericContainer} instance of a flagd server with the port 8013 exposed
*/
public static GenericContainer flagd(boolean unstable) {
String container = generateContainerName("flagd", unstable);
return new GenericContainer(DockerImageName.parse(container))
.withExposedPorts(8013);
}

private static @NotNull String generateContainerName(String type, boolean unstable) {
String container = "ghcr.io/open-feature/";
container += type;
container += "-testbed";
if (unstable) {
container += "-unstable";
}
container += ":" + version;
return container;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
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.PLUGIN_PROPERTY_NAME;
import static io.cucumber.junit.platform.engine.Constants.GLUE_PROPERTY_NAME;
Expand All @@ -20,6 +21,7 @@
@SelectClasspathResource("features/flagd.feature")
@ConfigurationParameter(key = PLUGIN_PROPERTY_NAME, value = "pretty")
@ConfigurationParameter(key = GLUE_PROPERTY_NAME, value = "dev.openfeature.contrib.providers.flagd.e2e.process,dev.openfeature.contrib.providers.flagd.e2e.steps")
@Testcontainers
public class RunFlagdInProcessCucumberTest {

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,21 @@
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.PLUGIN_PROPERTY_NAME;
import static io.cucumber.junit.platform.engine.Constants.GLUE_PROPERTY_NAME;

/**
* Class for running the reconnection tests for the in-process provider
* Class for running the reconnection tests for the in-process provider
*/
@Order(value = Integer.MAX_VALUE)
@Suite
@IncludeEngines("cucumber")
@SelectClasspathResource("features/flagd-reconnect.feature")
@ConfigurationParameter(key = PLUGIN_PROPERTY_NAME, value = "pretty")
@ConfigurationParameter(key = GLUE_PROPERTY_NAME, value = "dev.openfeature.contrib.providers.flagd.e2e.reconnect.process,dev.openfeature.contrib.providers.flagd.e2e.reconnect.steps")
@Testcontainers
public class RunFlagdInProcessReconnectCucumberTest {

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
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.PLUGIN_PROPERTY_NAME;
import static io.cucumber.junit.platform.engine.Constants.GLUE_PROPERTY_NAME;
Expand All @@ -20,7 +21,8 @@
@SelectClasspathResource("features/flagd.feature")
@ConfigurationParameter(key = PLUGIN_PROPERTY_NAME, value = "pretty")
@ConfigurationParameter(key = GLUE_PROPERTY_NAME, value = "dev.openfeature.contrib.providers.flagd.e2e.rpc,dev.openfeature.contrib.providers.flagd.e2e.steps")
@Testcontainers
public class RunFlagdRpcCucumberTest {

}

Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,22 @@
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.PLUGIN_PROPERTY_NAME;
import static io.cucumber.junit.platform.engine.Constants.GLUE_PROPERTY_NAME;

/**
* Class for running the reconnection tests for the RPC provider
* Class for running the reconnection tests for the RPC provider
*/
@Order(value = Integer.MAX_VALUE)
@Suite
@IncludeEngines("cucumber")
@SelectClasspathResource("features/flagd-reconnect.feature")
@ConfigurationParameter(key = PLUGIN_PROPERTY_NAME, value = "pretty")
@ConfigurationParameter(key = GLUE_PROPERTY_NAME, value = "dev.openfeature.contrib.providers.flagd.e2e.reconnect.rpc,dev.openfeature.contrib.providers.flagd.e2e.reconnect.steps")
@Testcontainers
public class RunFlagdRpcReconnectCucumberTest {

}

Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package dev.openfeature.contrib.providers.flagd.e2e.process;

import dev.openfeature.contrib.providers.flagd.e2e.ContainerConfig;
import io.cucumber.java.AfterAll;
import org.junit.jupiter.api.Order;
import org.junit.jupiter.api.parallel.Isolated;

Expand All @@ -9,20 +11,30 @@
import dev.openfeature.contrib.providers.flagd.e2e.steps.StepDefinitions;
import dev.openfeature.sdk.FeatureProvider;
import io.cucumber.java.BeforeAll;
import org.testcontainers.containers.GenericContainer;
import org.testcontainers.utility.DockerImageName;

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

private static FeatureProvider provider;


private static final GenericContainer flagdContainer = ContainerConfig.sync();

@BeforeAll()
public static void setup() throws InterruptedException {
flagdContainer.start();
FlagdInProcessSetup.provider = new FlagdProvider(FlagdOptions.builder()
.resolverType(Config.Resolver.IN_PROCESS)
.deadline(3000)
.port(9090)
.port(flagdContainer.getFirstMappedPort())
.build());
StepDefinitions.setProvider(provider);
}

@AfterAll
public static void tearDown() {
flagdContainer.stop();
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package dev.openfeature.contrib.providers.flagd.e2e.reconnect.process;

import dev.openfeature.contrib.providers.flagd.e2e.ContainerConfig;
import io.cucumber.java.AfterAll;
import org.junit.jupiter.api.Order;
import org.junit.jupiter.api.parallel.Isolated;

Expand All @@ -9,17 +11,20 @@
import dev.openfeature.contrib.providers.flagd.e2e.reconnect.steps.StepDefinitions;
import dev.openfeature.sdk.FeatureProvider;
import io.cucumber.java.BeforeAll;
import org.testcontainers.containers.GenericContainer;

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


private static final GenericContainer flagdContainer = ContainerConfig.sync(true);
@BeforeAll()
public static void setup() throws InterruptedException {
flagdContainer.start();
FeatureProvider workingProvider = new FlagdProvider(FlagdOptions.builder()
.resolverType(Config.Resolver.IN_PROCESS)
.deadline(3000)
.port(9091)
.port(flagdContainer.getFirstMappedPort())
.build());
StepDefinitions.setUnstableProvider(workingProvider);

Expand All @@ -30,4 +35,9 @@ public static void setup() throws InterruptedException {
.build());
StepDefinitions.setUnavailableProvider(unavailableProvider);
}

@AfterAll
public static void tearDown() {
flagdContainer.stop();
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package dev.openfeature.contrib.providers.flagd.e2e.reconnect.rpc;

import dev.openfeature.contrib.providers.flagd.e2e.ContainerConfig;
import io.cucumber.java.AfterAll;
import org.junit.jupiter.api.Order;
import org.junit.jupiter.api.parallel.Isolated;

Expand All @@ -10,16 +12,22 @@
import dev.openfeature.contrib.providers.flagd.resolver.grpc.cache.CacheType;
import dev.openfeature.sdk.FeatureProvider;
import io.cucumber.java.BeforeAll;
import org.testcontainers.containers.GenericContainer;
import org.testcontainers.junit.jupiter.Container;
import org.testcontainers.utility.DockerImageName;

@Isolated()
@Order(value = Integer.MAX_VALUE)
public class FlagdRpcSetup {
private static final GenericContainer flagdContainer = ContainerConfig.flagd(true);

@BeforeAll()
public static void setup() throws InterruptedException {
flagdContainer.start();

FeatureProvider workingProvider = new FlagdProvider(FlagdOptions.builder()
.resolverType(Config.Resolver.RPC)
.port(8014)
.port(flagdContainer.getFirstMappedPort())
// set a generous deadline, to prevent timeouts in actions
.deadline(3000)
.cacheType(CacheType.DISABLED.getValue())
Expand All @@ -35,4 +43,9 @@ public static void setup() throws InterruptedException {
.build());
StepDefinitions.setUnavailableProvider(unavailableProvider);
}

@AfterAll
public static void tearDown() {
flagdContainer.stop();
}
}
Loading
Loading