Skip to content
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
72 changes: 72 additions & 0 deletions evaluator/flags/testkit-flags.json
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,78 @@
"targeting": {
"if": [{"sem_ver": [{"var": "version"}, "=", "1.0.0+build"]}, "match", "no-match"]
}
},
"ref-whitespace-compact-flag": {
"state": "ENABLED",
"variants": {
"hi": "hi",
"bye": "bye",
"fallback": "fallback"
},
"defaultVariant": "fallback",
"targeting": {
"if": [
{
"$ref":"is_ballmer"
},
"hi",
"bye"
]
}
},
"ref-whitespace-space-after-colon-flag": {
"state": "ENABLED",
"variants": {
"hi": "hi",
"bye": "bye",
"fallback": "fallback"
},
"defaultVariant": "fallback",
"targeting": {
"if": [
{
"$ref": "is_ballmer"
},
"hi",
"bye"
]
}
},
"ref-whitespace-space-around-colon-flag": {
"state": "ENABLED",
"variants": {
"hi": "hi",
"bye": "bye",
"fallback": "fallback"
},
"defaultVariant": "fallback",
"targeting": {
"if": [
{
"$ref" : "is_ballmer"
},
"hi",
"bye"
]
}
},
"ref-to-nonexistent-evaluator-flag": {
"state": "ENABLED",
"variants": {
"hit": "hit",
"miss": "miss",
"fallback": "fallback"
},
"defaultVariant": "fallback",
"targeting": {
"if": [
{
"$ref": "nonexistent_evaluator"
},
"hit",
"miss"
]
}
}
},
"$evaluators": {
Expand Down
25 changes: 25 additions & 0 deletions evaluator/gherkin/evaluator-refs.feature
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,28 @@ Feature: Evaluator evaluator refs
| key | value |
| some-email-targeted-flag | hi |
| some-other-email-targeted-flag | yes |

@evaluator-refs @evaluator-refs-whitespace
Scenario Outline: Evaluator $ref resolves regardless of whitespace around the colon
Given an evaluator
And a String-flag with key "<key>" and a fallback value "fallback"
And a context containing a key "email", with type "String" and with value "<email>"
When the flag was evaluated with details
Then the resolved details value should be "<value>"
And the reason should be "TARGETING_MATCH"
Examples:
| key | email | value |
| ref-whitespace-compact-flag | ballmer@macrosoft.com | hi |
| ref-whitespace-space-after-colon-flag | ballmer@macrosoft.com | hi |
| ref-whitespace-space-around-colon-flag | ballmer@macrosoft.com | hi |
| ref-whitespace-compact-flag | user@example.com | bye |
| ref-whitespace-space-after-colon-flag | user@example.com | bye |
| ref-whitespace-space-around-colon-flag | user@example.com | bye |

@evaluator-refs @non-existent-evaluator-ref
Scenario: Ref to nonexistent evaluator yields parse error
Given an evaluator
And a String-flag with key "ref-to-nonexistent-evaluator-flag" and a fallback value "fallback"
When the flag was evaluated with details
Then the resolved details value should be "fallback"
And the error-code should be "PARSE_ERROR"
72 changes: 72 additions & 0 deletions flags/evaluator-refs.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,78 @@
"no"
]
}
},
"ref-whitespace-compact-flag": {
"state": "ENABLED",
"variants": {
"hi": "hi",
"bye": "bye",
"fallback": "fallback"
},
"defaultVariant": "fallback",
"targeting": {
"if": [
{
"$ref":"is_ballmer"
},
"hi",
"bye"
]
}
},
"ref-whitespace-space-after-colon-flag": {
"state": "ENABLED",
"variants": {
"hi": "hi",
"bye": "bye",
"fallback": "fallback"
},
"defaultVariant": "fallback",
"targeting": {
"if": [
{
"$ref": "is_ballmer"
},
"hi",
"bye"
]
}
},
"ref-whitespace-space-around-colon-flag": {
"state": "ENABLED",
"variants": {
"hi": "hi",
"bye": "bye",
"fallback": "fallback"
},
"defaultVariant": "fallback",
"targeting": {
"if": [
{
"$ref" : "is_ballmer"
},
"hi",
"bye"
]
}
},
"ref-to-nonexistent-evaluator-flag": {
"state": "ENABLED",
"variants": {
"hit": "hit",
"miss": "miss",
"fallback": "fallback"
},
"defaultVariant": "fallback",
"targeting": {
"if": [
{
"$ref": "nonexistent_evaluator"
},
"hit",
"miss"
]
}
}
},
"$evaluators": {
Expand Down
23 changes: 23 additions & 0 deletions gherkin/targeting.feature
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,29 @@ Feature: Targeting rules
| some-email-targeted-flag | hi |
| some-other-email-targeted-flag | yes |

@evaluator-refs @evaluator-refs-whitespace
Scenario Outline: Evaluator $ref resolves regardless of whitespace around the colon
Given a String-flag with key "<key>" and a default value "fallback"
And a context containing a key "email", with type "String" and with value "<email>"
When the flag was evaluated with details
Then the resolved details value should be "<value>"
And the reason should be "TARGETING_MATCH"
Examples:
| key | email | value |
| ref-whitespace-compact-flag | ballmer@macrosoft.com | hi |
| ref-whitespace-space-after-colon-flag | ballmer@macrosoft.com | hi |
| ref-whitespace-space-around-colon-flag | ballmer@macrosoft.com | hi |
| ref-whitespace-compact-flag | user@example.com | bye |
| ref-whitespace-space-after-colon-flag | user@example.com | bye |
| ref-whitespace-space-around-colon-flag | user@example.com | bye |

@evaluator-refs @non-existent-evaluator-ref
Scenario: Ref to nonexistent evaluator yields parse error
Given a String-flag with key "ref-to-nonexistent-evaluator-flag" and a default value "fallback"
When the flag was evaluated with details
Then the resolved details value should be "fallback"
Comment on lines +41 to +43
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

To ensure the test correctly verifies that the evaluator falls back to the evaluation default value (as required by the OpenFeature specification for a PARSE_ERROR) rather than the flag's defaultVariant, it is better to use a unique value for the default in the evaluation call. Currently, both the flag's defaultVariant (in evaluator-refs.json) and the evaluation default are set to "fallback", making it impossible to distinguish which one is being returned.

    Given a String-flag with key "ref-to-nonexistent-evaluator-flag" and a default value "evaluation-default"
    When the flag was evaluated with details
    Then the resolved details value should be "evaluation-default"

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Should we differentiate here? I saw that other testcases don't differentiate either.

And the error-code should be "PARSE_ERROR"

# custom operators
# @fractional-v1: legacy float-based bucketing (abs(hash) / i32::MAX * 100)
# @fractional-v2: high-precision integer bucketing ((hash * totalWeight) >> 32)
Expand Down
Loading