-
Notifications
You must be signed in to change notification settings - Fork 51
feat: $flagd.timestamp
added to in-process evaluator
#512
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
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
8380b5e
time stamp and testing
DBlanchard88 495eb6c
time stamp and testing
DBlanchard88 0db7446
Update providers/flagd/src/main/java/dev/openfeature/contrib/provider…
toddbaert d819194
Update providers/flagd/src/test/java/dev/openfeature/contrib/provider…
DBlanchard88 0f04fc5
Update providers/flagd/src/test/java/dev/openfeature/contrib/provider…
DBlanchard88 cf0f3c1
extract test
DBlanchard88 f6b3fa5
yml file fix
DBlanchard88 5fa3f5f
extractSubPro back to private
DBlanchard88 687ae40
extractSubPro back to private
DBlanchard88 ecb8b3c
Merge branch 'main' into timestamptest
Kavindu-Dodan 768774a
Merge branch 'main' into timestamptest
toddbaert 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
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,9 +1,11 @@ | ||
package dev.openfeature.contrib.providers.flagd.resolver.process.targeting; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.time.Instant; | ||
|
||
import org.junit.jupiter.api.BeforeAll; | ||
import org.junit.jupiter.api.Test; | ||
|
@@ -33,6 +35,45 @@ void flagKeyPresent() throws TargetingRuleException { | |
assertEquals(true, evalVariant); | ||
} | ||
|
||
@Test | ||
void timestampPresent() throws TargetingRuleException { | ||
// given | ||
|
||
// rule asserting $flagd.timestamp is a number (i.e., a Unix timestamp) | ||
final String targetingRule = "{\"var\":[\"$flagd.timestamp\"]}"; | ||
|
||
// when | ||
Object timestampString = OPERATOR.apply("some-key", targetingRule, new ImmutableContext()); | ||
|
||
long timestamp = (long) Double.parseDouble(timestampString.toString()); | ||
|
||
// generating current unix timestamp & 5 minute threshold | ||
DBlanchard88 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
long currentTimestamp = Instant.now().getEpochSecond(); | ||
long thresholdPast = currentTimestamp - (5); | ||
long thresholdFuture = currentTimestamp + (5); | ||
|
||
// checks if the timestamp is within 5 minutes of the current time | ||
DBlanchard88 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
assertTrue(timestamp >= thresholdPast && timestamp <= thresholdFuture); | ||
} | ||
|
||
@Test | ||
void testFlagPropertiesConstructor() { | ||
// Given | ||
Map<String, Object> flagdProperties = new HashMap<>(); | ||
flagdProperties.put(Operator.FLAG_KEY, "some-key"); | ||
flagdProperties.put(Operator.TIME_STAMP, 1634000000L); | ||
|
||
Map<String, Object> dataMap = new HashMap<>(); | ||
dataMap.put(Operator.FLAGD_PROPS_KEY, flagdProperties); | ||
|
||
// When | ||
Operator.FlagProperties flagProperties = new Operator.FlagProperties(dataMap); | ||
|
||
// Then | ||
assertEquals("some-key", flagProperties.getFlagKey()); | ||
assertEquals(1634000000L, flagProperties.getTimestamp()); | ||
toddbaert marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
@Test | ||
void fractionalTestA() throws TargetingRuleException { | ||
// given | ||
|
@@ -64,7 +105,6 @@ void fractionalTestA() throws TargetingRuleException { | |
Map<String, Value> ctxData = new HashMap<>(); | ||
ctxData.put("email", new Value("[email protected]")); | ||
|
||
|
||
// when | ||
Object evalVariant = OPERATOR.apply("headerColor", targetingRule, new ImmutableContext(ctxData)); | ||
|
||
|
@@ -103,7 +143,6 @@ void fractionalTestB() throws TargetingRuleException { | |
Map<String, Value> ctxData = new HashMap<>(); | ||
ctxData.put("email", new Value("[email protected]")); | ||
|
||
|
||
// when | ||
Object evalVariant = OPERATOR.apply("headerColor", targetingRule, new ImmutableContext(ctxData)); | ||
|
||
|
@@ -142,7 +181,6 @@ void fractionalTestC() throws TargetingRuleException { | |
Map<String, Value> ctxData = new HashMap<>(); | ||
ctxData.put("email", new Value("[email protected]")); | ||
|
||
|
||
// when | ||
Object evalVariant = OPERATOR.apply("headerColor", targetingRule, new ImmutableContext(ctxData)); | ||
|
||
|
@@ -166,7 +204,6 @@ void stringCompStartsWith() throws TargetingRuleException { | |
Map<String, Value> ctxData = new HashMap<>(); | ||
ctxData.put("email", new Value("[email protected]")); | ||
|
||
|
||
// when | ||
Object evalVariant = OPERATOR.apply("adminRule", targetingRule, new ImmutableContext(ctxData)); | ||
|
||
|
@@ -190,7 +227,6 @@ void stringCompEndsWith() throws TargetingRuleException { | |
Map<String, Value> ctxData = new HashMap<>(); | ||
ctxData.put("email", new Value("[email protected]")); | ||
|
||
|
||
// when | ||
Object evalVariant = OPERATOR.apply("isFaas", targetingRule, new ImmutableContext(ctxData)); | ||
|
||
|
@@ -215,7 +251,6 @@ void semVerA() throws TargetingRuleException { | |
Map<String, Value> ctxData = new HashMap<>(); | ||
ctxData.put("version", new Value("1.1.0")); | ||
|
||
|
||
// when | ||
Object evalVariant = OPERATOR.apply("versionFlag", targetingRule, new ImmutableContext(ctxData)); | ||
|
||
|
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.