Skip to content
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

test(flagd): add socket path tests #1153

Closed
Closed
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: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,7 @@ target
.vscode/

# IntelliJ files
*.iml
*.iml

# tmp files
providers/flagd/tmp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
@@ -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")
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

again, this does not work for in_process connection

@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 {}
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
@@ -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 {}
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -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);
}
}
Loading