-
Notifications
You must be signed in to change notification settings - Fork 51
feat(flagd): Improve e2e coverage #1092
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
aepfli
merged 8 commits into
open-feature:main
from
open-feature-forking:feat/use_more_gherkin_files
Dec 18, 2024
Merged
Changes from 4 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
c0e2e79
feat(flagd): Improve e2e coverage
aepfli ac411ae
Merge branch 'main' into feat/use_more_gherkin_files
aepfli 4c9010f
feat(flagd): Improve e2e coverage
aepfli 5c684aa
Merge branch 'main' into feat/use_more_gherkin_files
aepfli ac044fd
feat(flagd): Improve e2e coverage
aepfli 5d6f145
Merge branch 'main' into feat/use_more_gherkin_files
toddbaert d619327
fixup: remove comments
aepfli 38ef96d
Merge branch 'main' into feat/use_more_gherkin_files
aepfli File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
...lagd/src/test/java/dev/openfeature/contrib/providers/flagd/e2e/RunConfigCucumberTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
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 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/config.feature") | ||
@ConfigurationParameter(key = PLUGIN_PROPERTY_NAME, value = "pretty") | ||
@ConfigurationParameter(key = GLUE_PROPERTY_NAME, value = "dev.openfeature.contrib.providers.flagd.e2e.steps.config") | ||
public class RunConfigCucumberTest { | ||
|
||
|
||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
103 changes: 103 additions & 0 deletions
103
...d/src/test/java/dev/openfeature/contrib/providers/flagd/e2e/steps/config/ConfigSteps.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
package dev.openfeature.contrib.providers.flagd.e2e.steps.config; | ||
|
||
import dev.openfeature.contrib.providers.flagd.Config; | ||
import dev.openfeature.contrib.providers.flagd.FlagdOptions; | ||
import dev.openfeature.contrib.providers.flagd.resolver.grpc.cache.CacheType; | ||
import io.cucumber.java.en.Then; | ||
import io.cucumber.java.en.When; | ||
|
||
import java.lang.reflect.InvocationTargetException; | ||
import java.lang.reflect.Method; | ||
import java.util.Arrays; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.Objects; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
public class ConfigSteps { | ||
|
||
FlagdOptions.FlagdOptionsBuilder builder = FlagdOptions.builder(); | ||
FlagdOptions options; | ||
|
||
@When("we initialize a config") | ||
aepfli marked this conversation as resolved.
Show resolved
Hide resolved
|
||
public void we_initialize_a_config() { | ||
options = builder.build(); | ||
} | ||
|
||
@When("we initialize a config for {string}") | ||
public void we_initialize_a_config_for(String string) { | ||
switch (string.toLowerCase()) { | ||
case "in-process": | ||
options = builder.resolverType(Config.Resolver.IN_PROCESS).build(); | ||
break; | ||
case "rpc": | ||
options = builder.resolverType(Config.Resolver.RPC).build(); | ||
break; | ||
default: | ||
throw new RuntimeException("Unknown resolver type: " + string); | ||
} | ||
} | ||
|
||
@When("we have an option {string} of type {string} with value {string}") | ||
public void we_have_an_option_of_type_with_value(String option, String type, String value) throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, IllegalAccessException { | ||
Object converted = convert(value, type); | ||
Method method = Arrays.stream(builder.getClass().getMethods()) | ||
.filter(method1 -> method1.getName().equals(option)) | ||
.findFirst() | ||
.orElseThrow(RuntimeException::new); | ||
method.invoke(builder, converted); | ||
} | ||
|
||
|
||
Map<String, String> envVarsSet = new HashMap<>(); | ||
|
||
@When("we have an environment variable {string} with value {string}") | ||
public void we_have_an_environment_variable_with_value(String string, String string2) throws IllegalAccessException, NoSuchFieldException { | ||
aepfli marked this conversation as resolved.
Show resolved
Hide resolved
|
||
String getenv = System.getenv(string); | ||
envVarsSet.put(string, getenv); | ||
EnvironmentVariableUtils.set(string, string2); | ||
} | ||
|
||
private Object convert(String value, String type) throws ClassNotFoundException { | ||
if (Objects.equals(value, "null")) return null; | ||
switch (type) { | ||
case "Boolean": | ||
return Boolean.parseBoolean(value); | ||
case "String": | ||
return value; | ||
case "Integer": | ||
return Integer.parseInt(value); | ||
case "Long": | ||
return Long.parseLong(value); | ||
case "ResolverType": | ||
switch (value.toLowerCase()) { | ||
case "in-process": | ||
return Config.Resolver.IN_PROCESS; | ||
case "rpc": | ||
return Config.Resolver.RPC; | ||
default: | ||
throw new RuntimeException("Unknown resolver type: " + value); | ||
} | ||
case "CacheType": | ||
return CacheType.valueOf(value.toUpperCase()).getValue(); | ||
} | ||
throw new RuntimeException("Unknown config type: " + type); | ||
} | ||
|
||
@Then("the option {string} of type {string} should have the value {string}") | ||
public void the_option_of_type_should_have_the_value(String option, String type, String value) throws Throwable { | ||
Object convert = convert(value, type); | ||
|
||
assertThat(options).hasFieldOrPropertyWithValue(option, convert); | ||
|
||
// Resetting env vars | ||
for (Map.Entry<String, String> envVar : envVarsSet.entrySet()) { | ||
if (envVar.getValue() == null) { | ||
EnvironmentVariableUtils.clear(envVar.getKey()); | ||
} else { | ||
EnvironmentVariableUtils.set(envVar.getKey(), envVar.getValue()); | ||
} | ||
} | ||
} | ||
} |
106 changes: 106 additions & 0 deletions
106
...va/dev/openfeature/contrib/providers/flagd/e2e/steps/config/EnvironmentVariableUtils.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
package dev.openfeature.contrib.providers.flagd.e2e.steps.config; | ||
|
||
/* | ||
* Copy of JUnit Pioneer's EnvironmentVariable Utils | ||
* https://github.com/junit-pioneer/junit-pioneer/blob/main/src/main/java/org/junitpioneer/jupiter/EnvironmentVariableUtils.java | ||
*/ | ||
|
||
import java.lang.reflect.Field; | ||
import java.util.Map; | ||
import java.util.function.Consumer; | ||
|
||
import org.junit.platform.commons.PreconditionViolationException; | ||
|
||
/** | ||
* This class modifies the internals of the environment variables map with reflection. | ||
* Warning: If your {@link SecurityManager} does not allow modifications, it fails. | ||
*/ | ||
class EnvironmentVariableUtils { | ||
|
||
private EnvironmentVariableUtils() { | ||
// private constructor to prevent instantiation of utility class | ||
} | ||
|
||
/** | ||
* Set a value of an environment variable. | ||
* | ||
* @param name of the environment variable | ||
* @param value of the environment variable | ||
*/ | ||
public static void set(String name, String value) { | ||
modifyEnvironmentVariables(map -> map.put(name, value)); | ||
} | ||
|
||
/** | ||
* Clear an environment variable. | ||
* | ||
* @param name of the environment variable | ||
*/ | ||
public static void clear(String name) { | ||
modifyEnvironmentVariables(map -> map.remove(name)); | ||
} | ||
|
||
private static void modifyEnvironmentVariables(Consumer<Map<String, String>> consumer) { | ||
try { | ||
setInProcessEnvironmentClass(consumer); | ||
} | ||
catch (ReflectiveOperationException ex) { | ||
trySystemEnvClass(consumer, ex); | ||
} | ||
} | ||
|
||
private static void trySystemEnvClass(Consumer<Map<String, String>> consumer, | ||
ReflectiveOperationException processEnvironmentClassEx) { | ||
try { | ||
setInSystemEnvClass(consumer); | ||
} | ||
catch (ReflectiveOperationException ex) { | ||
ex.addSuppressed(processEnvironmentClassEx); | ||
throw new PreconditionViolationException("Could not modify environment variables", ex); | ||
} | ||
} | ||
|
||
/* | ||
* Works on Windows | ||
*/ | ||
private static void setInProcessEnvironmentClass(Consumer<Map<String, String>> consumer) | ||
throws ReflectiveOperationException { | ||
Class<?> processEnvironmentClass = Class.forName("java.lang.ProcessEnvironment"); | ||
// The order of operations is critical here: On some operating systems, theEnvironment is present but | ||
// theCaseInsensitiveEnvironment is not present. In such cases, this method must throw a | ||
// ReflectiveOperationException without modifying theEnvironment. Otherwise, the contents of theEnvironment will | ||
// be corrupted. For this reason, both fields are fetched by reflection before either field is modified. | ||
Map<String, String> theEnvironment = getFieldValue(processEnvironmentClass, null, "theEnvironment"); | ||
Map<String, String> theCaseInsensitiveEnvironment = getFieldValue(processEnvironmentClass, null, | ||
"theCaseInsensitiveEnvironment"); | ||
consumer.accept(theEnvironment); | ||
consumer.accept(theCaseInsensitiveEnvironment); | ||
} | ||
|
||
/* | ||
* Works on Linux and OSX | ||
*/ | ||
private static void setInSystemEnvClass(Consumer<Map<String, String>> consumer) | ||
throws ReflectiveOperationException { | ||
Map<String, String> env = System.getenv(); //NOSONAR access required to implement the extension | ||
consumer.accept(getFieldValue(env.getClass(), env, "m")); | ||
} | ||
|
||
@SuppressWarnings("unchecked") | ||
private static Map<String, String> getFieldValue(Class<?> clazz, Object object, String name) | ||
throws ReflectiveOperationException { | ||
Field field = clazz.getDeclaredField(name); | ||
try { | ||
field.setAccessible(true); //NOSONAR illegal access required to implement the extension | ||
} | ||
catch (Exception ex) { | ||
throw new PreconditionViolationException( | ||
"Cannot access and modify JDK internals to modify environment variables. " | ||
+ "Have a look at the documentation for possible solutions: " | ||
+ "https://junit-pioneer.org/docs/environment-variables/#warnings-for-reflective-access", | ||
ex); | ||
} | ||
return (Map<String, String>) field.get(object); | ||
} | ||
|
||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
# todo: properly configure renovate with a regex matcher to update this version | ||
# renovate: datasource=docker packageName=docker versioning=docker | ||
version=v0.5.13 | ||
version=v0.5.15 |
Submodule test-harness
updated
from ed7e0b to 536d48
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.