From 1a5b9b4c92eca5eaeb027c7153ba3695f6a4a5ef Mon Sep 17 00:00:00 2001 From: Simon Schrottner Date: Sat, 11 Jan 2025 20:45:48 +0100 Subject: [PATCH] test(flagd): add socket path tests Signed-off-by: Simon Schrottner --- .gitignore | 5 +- .../e2e/RunFlagdInProcessSSLCucumberTest.java | 5 +- .../RunFlagdInProcessSocketCucumberTest.java | 28 ++++++++ .../e2e/RunFlagdRpcReconnectCucumberTest.java | 1 - .../e2e/RunFlagdRpcSocketCucumberTest.java | 26 +++++++ .../socket/process/FlagdInProcessSetup.java | 71 +++++++++++++++++++ .../flagd/e2e/socket/rpc/FlagdRpcSetup.java | 69 ++++++++++++++++++ 7 files changed, 201 insertions(+), 4 deletions(-) create mode 100644 providers/flagd/src/test/java/dev/openfeature/contrib/providers/flagd/e2e/RunFlagdInProcessSocketCucumberTest.java create mode 100644 providers/flagd/src/test/java/dev/openfeature/contrib/providers/flagd/e2e/RunFlagdRpcSocketCucumberTest.java create mode 100644 providers/flagd/src/test/java/dev/openfeature/contrib/providers/flagd/e2e/socket/process/FlagdInProcessSetup.java create mode 100644 providers/flagd/src/test/java/dev/openfeature/contrib/providers/flagd/e2e/socket/rpc/FlagdRpcSetup.java diff --git a/.gitignore b/.gitignore index 76f2436f5..1f99b4e4b 100644 --- a/.gitignore +++ b/.gitignore @@ -12,4 +12,7 @@ target .vscode/ # IntelliJ files -*.iml \ No newline at end of file +*.iml + +# tmp files +providers/flagd/tmp diff --git a/providers/flagd/src/test/java/dev/openfeature/contrib/providers/flagd/e2e/RunFlagdInProcessSSLCucumberTest.java b/providers/flagd/src/test/java/dev/openfeature/contrib/providers/flagd/e2e/RunFlagdInProcessSSLCucumberTest.java index ae7ca415b..2d0dbe10e 100644 --- a/providers/flagd/src/test/java/dev/openfeature/contrib/providers/flagd/e2e/RunFlagdInProcessSSLCucumberTest.java +++ b/providers/flagd/src/test/java/dev/openfeature/contrib/providers/flagd/e2e/RunFlagdInProcessSSLCucumberTest.java @@ -4,16 +4,17 @@ import static io.cucumber.junit.platform.engine.Constants.PLUGIN_PROPERTY_NAME; import org.apache.logging.log4j.core.config.Order; +import org.junit.jupiter.api.Disabled; import org.junit.platform.suite.api.ConfigurationParameter; import org.junit.platform.suite.api.IncludeEngines; import org.junit.platform.suite.api.Suite; import org.testcontainers.junit.jupiter.Testcontainers; -/** Class for running the reconnection tests for the RPC provider */ @Order(value = Integer.MAX_VALUE) @Suite(failIfNoTests = false) @IncludeEngines("cucumber") -// @SelectFile("spec/specification/assets/gherkin/evaluation.feature") +// Not implemented in flagd +//@SelectFile("spec/specification/assets/gherkin/evaluation.feature") @ConfigurationParameter(key = PLUGIN_PROPERTY_NAME, value = "pretty") @ConfigurationParameter( key = GLUE_PROPERTY_NAME, diff --git a/providers/flagd/src/test/java/dev/openfeature/contrib/providers/flagd/e2e/RunFlagdInProcessSocketCucumberTest.java b/providers/flagd/src/test/java/dev/openfeature/contrib/providers/flagd/e2e/RunFlagdInProcessSocketCucumberTest.java new file mode 100644 index 000000000..14246d14f --- /dev/null +++ b/providers/flagd/src/test/java/dev/openfeature/contrib/providers/flagd/e2e/RunFlagdInProcessSocketCucumberTest.java @@ -0,0 +1,28 @@ +package dev.openfeature.contrib.providers.flagd.e2e; + +import org.apache.logging.log4j.core.config.Order; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.condition.EnabledOnOs; +import org.junit.jupiter.api.condition.OS; +import org.junit.platform.suite.api.ConfigurationParameter; +import org.junit.platform.suite.api.IncludeEngines; +import org.junit.platform.suite.api.SelectFile; +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; + +@Order(value = Integer.MAX_VALUE) +@Suite(failIfNoTests = false) +@IncludeEngines("cucumber") +// Not implemented in flagd +//@SelectFile("spec/specification/assets/gherkin/evaluation.feature") +@ConfigurationParameter(key = PLUGIN_PROPERTY_NAME, value = "pretty") +@ConfigurationParameter( + key = GLUE_PROPERTY_NAME, + value = + "dev.openfeature.contrib.providers.flagd.e2e.socket.process,dev.openfeature.contrib.providers.flagd.e2e.steps") +@Testcontainers +@EnabledOnOs(OS.LINUX) +public class RunFlagdInProcessSocketCucumberTest {} diff --git a/providers/flagd/src/test/java/dev/openfeature/contrib/providers/flagd/e2e/RunFlagdRpcReconnectCucumberTest.java b/providers/flagd/src/test/java/dev/openfeature/contrib/providers/flagd/e2e/RunFlagdRpcReconnectCucumberTest.java index 436ebf00f..33af91b9d 100644 --- a/providers/flagd/src/test/java/dev/openfeature/contrib/providers/flagd/e2e/RunFlagdRpcReconnectCucumberTest.java +++ b/providers/flagd/src/test/java/dev/openfeature/contrib/providers/flagd/e2e/RunFlagdRpcReconnectCucumberTest.java @@ -10,7 +10,6 @@ import org.junit.platform.suite.api.Suite; import org.testcontainers.junit.jupiter.Testcontainers; -/** Class for running the reconnection tests for the RPC provider */ @Order(value = Integer.MAX_VALUE) @Suite @IncludeEngines("cucumber") diff --git a/providers/flagd/src/test/java/dev/openfeature/contrib/providers/flagd/e2e/RunFlagdRpcSocketCucumberTest.java b/providers/flagd/src/test/java/dev/openfeature/contrib/providers/flagd/e2e/RunFlagdRpcSocketCucumberTest.java new file mode 100644 index 000000000..3c086f2ca --- /dev/null +++ b/providers/flagd/src/test/java/dev/openfeature/contrib/providers/flagd/e2e/RunFlagdRpcSocketCucumberTest.java @@ -0,0 +1,26 @@ +package dev.openfeature.contrib.providers.flagd.e2e; + +import static io.cucumber.junit.platform.engine.Constants.GLUE_PROPERTY_NAME; +import static io.cucumber.junit.platform.engine.Constants.PLUGIN_PROPERTY_NAME; + +import org.apache.logging.log4j.core.config.Order; +import org.junit.jupiter.api.condition.EnabledOnOs; +import org.junit.jupiter.api.condition.OS; +import org.junit.platform.suite.api.ConfigurationParameter; +import org.junit.platform.suite.api.IncludeEngines; +import org.junit.platform.suite.api.SelectFile; +import org.junit.platform.suite.api.Suite; +import org.testcontainers.junit.jupiter.Testcontainers; + +@Order(value = Integer.MAX_VALUE) +@Suite +@IncludeEngines("cucumber") +@SelectFile("spec/specification/assets/gherkin/evaluation.feature") +@ConfigurationParameter(key = PLUGIN_PROPERTY_NAME, value = "pretty") +@ConfigurationParameter( + key = GLUE_PROPERTY_NAME, + value = + "dev.openfeature.contrib.providers.flagd.e2e.socket.rpc,dev.openfeature.contrib.providers.flagd.e2e.steps") +@Testcontainers +@EnabledOnOs(OS.LINUX) +public class RunFlagdRpcSocketCucumberTest {} diff --git a/providers/flagd/src/test/java/dev/openfeature/contrib/providers/flagd/e2e/socket/process/FlagdInProcessSetup.java b/providers/flagd/src/test/java/dev/openfeature/contrib/providers/flagd/e2e/socket/process/FlagdInProcessSetup.java new file mode 100644 index 000000000..ae0b40d3d --- /dev/null +++ b/providers/flagd/src/test/java/dev/openfeature/contrib/providers/flagd/e2e/socket/process/FlagdInProcessSetup.java @@ -0,0 +1,71 @@ +package dev.openfeature.contrib.providers.flagd.e2e.socket.process; + +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.Before; +import io.cucumber.java.BeforeAll; +import java.io.File; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.nio.file.attribute.FileAttribute; +import java.nio.file.attribute.PosixFilePermission; +import java.nio.file.attribute.PosixFilePermissions; +import java.util.Set; +import org.apache.commons.lang3.RandomStringUtils; +import org.junit.jupiter.api.Order; +import org.junit.jupiter.api.parallel.Isolated; +import org.testcontainers.containers.BindMode; +import org.testcontainers.containers.GenericContainer; +import org.testcontainers.shaded.org.apache.commons.io.FileUtils; +import org.testcontainers.utility.DockerImageName; + + +@Isolated() +@Order(value = Integer.MAX_VALUE) +public class FlagdInProcessSetup { + + static Path sharedTempDir; + + static { + try { + sharedTempDir = Files.createDirectories( + Paths.get("tmp/" + RandomStringUtils.randomAlphanumeric(8).toLowerCase() +"/")); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + + private static final GenericContainer flagdContainer = new GenericContainer( + DockerImageName.parse(ContainerConfig.generateContainerName("flagd", "socket"))) + .withFileSystemBind(sharedTempDir.toAbsolutePath().toString(), "/tmp", BindMode.READ_WRITE); + + @BeforeAll() + public static void setups() throws InterruptedException, IOException { + flagdContainer.start(); + } + + @AfterAll() + public static void cleanup() throws IOException { + flagdContainer.stop(); + FileUtils.deleteDirectory(sharedTempDir.toFile()); + } + + @Before() + public static void setupTest() throws InterruptedException { + String string = sharedTempDir.resolve("socket.sock").toAbsolutePath().toString(); + FeatureProvider workingProvider = new FlagdProvider(FlagdOptions.builder() + .resolverType(Config.Resolver.IN_PROCESS) + .deadline(10000) + .streamDeadlineMs(0) // this makes reconnect tests more predictable + .socketPath(string) + .build()); + StepDefinitions.setProvider(workingProvider); + } +} diff --git a/providers/flagd/src/test/java/dev/openfeature/contrib/providers/flagd/e2e/socket/rpc/FlagdRpcSetup.java b/providers/flagd/src/test/java/dev/openfeature/contrib/providers/flagd/e2e/socket/rpc/FlagdRpcSetup.java new file mode 100644 index 000000000..1c9333dae --- /dev/null +++ b/providers/flagd/src/test/java/dev/openfeature/contrib/providers/flagd/e2e/socket/rpc/FlagdRpcSetup.java @@ -0,0 +1,69 @@ +package dev.openfeature.contrib.providers.flagd.e2e.socket.rpc; + +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.Before; +import io.cucumber.java.BeforeAll; +import java.io.File; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.nio.file.attribute.FileAttribute; +import java.nio.file.attribute.PosixFilePermission; +import java.nio.file.attribute.PosixFilePermissions; +import java.util.Set; +import org.apache.commons.lang3.RandomStringUtils; +import org.junit.jupiter.api.Order; +import org.junit.jupiter.api.parallel.Isolated; +import org.testcontainers.containers.BindMode; +import org.testcontainers.containers.GenericContainer; +import org.testcontainers.shaded.org.apache.commons.io.FileUtils; +import org.testcontainers.utility.DockerImageName; + +@Isolated() +@Order(value = Integer.MAX_VALUE) +public class FlagdRpcSetup { + + static Path sharedTempDir; + + static { + try { + sharedTempDir = Files.createDirectories(Paths.get("tmp/" + RandomStringUtils.randomAlphanumeric(8).toLowerCase() +"/")); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + + private static final GenericContainer flagdContainer = new GenericContainer( + DockerImageName.parse(ContainerConfig.generateContainerName("flagd", "socket"))) + .withFileSystemBind(sharedTempDir.toAbsolutePath().toString(), "/tmp", BindMode.READ_WRITE); + + @BeforeAll() + public static void setups() throws InterruptedException, IOException { + flagdContainer.start(); + } + + @AfterAll() + public static void cleanup() throws IOException { + flagdContainer.stop(); + FileUtils.deleteDirectory(sharedTempDir.toFile()); + } + + @Before() + public static void setupTest() throws InterruptedException { + String string = sharedTempDir.resolve("socket.sock").toAbsolutePath().toString(); + FeatureProvider workingProvider = new FlagdProvider(FlagdOptions.builder() + .resolverType(Config.Resolver.RPC) + .deadline(10000) + .streamDeadlineMs(0) // this makes reconnect tests more predictable + .socketPath(string) + .build()); + StepDefinitions.setProvider(workingProvider); + } +}