Skip to content

Commit eb3fa72

Browse files
aepfliCopilot
andauthored
feat(operators): add error return scenarios for custom operator null fallback (#342)
Signed-off-by: Simon Schrottner <simon.schrottner@dynatrace.com> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 2684a3e commit eb3fa72

5 files changed

Lines changed: 104 additions & 0 deletions

File tree

evaluator/flags/testkit-flags.json

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,34 @@
446446
"small"
447447
]
448448
}
449+
},
450+
"semver-invalid-version-flag": {
451+
"state": "ENABLED",
452+
"variants": { "match": "match", "no-match": "no-match", "fallback": "fallback" },
453+
"defaultVariant": "fallback",
454+
"targeting": {
455+
"sem_ver": [{"var": "version"}, "=", "1.0.0"]
456+
}
457+
},
458+
"semver-invalid-operator-flag": {
459+
"state": "ENABLED",
460+
"variants": { "match": "match", "no-match": "no-match", "fallback": "fallback" },
461+
"defaultVariant": "fallback",
462+
"targeting": {
463+
"sem_ver": [{"var": "version"}, "===", "1.0.0"]
464+
}
465+
},
466+
"fractional-null-bucket-key-flag": {
467+
"state": "ENABLED",
468+
"variants": { "one": "one", "two": "two", "fallback": "fallback" },
469+
"defaultVariant": "fallback",
470+
"targeting": {
471+
"fractional": [
472+
{"var": "missing_key"},
473+
["one", 50],
474+
["two", 50]
475+
]
476+
}
449477
}
450478
},
451479
"$evaluators": {

evaluator/gherkin/fractional.feature

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,3 +181,10 @@ Feature: Evaluator fractional operator
181181
And a context containing a targeting key with value "some-targeting-key"
182182
When the flag was evaluated with details
183183
Then the resolved details value should be "ones"
184+
185+
@operator-errors
186+
Scenario: fractional operator with missing bucket key falls back to default variant
187+
Given an evaluator
188+
And a String-flag with key "fractional-null-bucket-key-flag" and a fallback value "wrong"
189+
When the flag was evaluated with details
190+
Then the resolved details value should be "fallback"

evaluator/gherkin/semver.feature

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,15 @@ Feature: Evaluator semantic version operator
3131
| 3.0.1 | minor |
3232
| 3.1.0 | major |
3333
| 4.0.0 | none |
34+
35+
@operator-errors
36+
Scenario Outline: sem_ver returns null for invalid input and falls back to default variant
37+
Given an evaluator
38+
And a String-flag with key "<key>" and a fallback value "wrong"
39+
And a context containing a key "version", with type "String" and with value "<context_value>"
40+
When the flag was evaluated with details
41+
Then the resolved details value should be "fallback"
42+
Examples:
43+
| key | context_value |
44+
| semver-invalid-version-flag | not-a-version |
45+
| semver-invalid-operator-flag | 1.0.0 |

flags/edge-case-flags.json

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,46 @@
5252
},
5353
"defaultVariant": "false",
5454
"targeting": {}
55+
},
56+
"semver-invalid-version-flag": {
57+
"state": "ENABLED",
58+
"variants": {
59+
"match": "match",
60+
"no-match": "no-match",
61+
"fallback": "fallback"
62+
},
63+
"defaultVariant": "fallback",
64+
"targeting": {
65+
"sem_ver": [{"var": "version"}, "=", "1.0.0"]
66+
}
67+
},
68+
"semver-invalid-operator-flag": {
69+
"state": "ENABLED",
70+
"variants": {
71+
"match": "match",
72+
"no-match": "no-match",
73+
"fallback": "fallback"
74+
},
75+
"defaultVariant": "fallback",
76+
"targeting": {
77+
"sem_ver": [{"var": "version"}, "===", "1.0.0"]
78+
}
79+
},
80+
"fractional-null-bucket-key-flag": {
81+
"state": "ENABLED",
82+
"variants": {
83+
"one": "one",
84+
"two": "two",
85+
"fallback": "fallback"
86+
},
87+
"defaultVariant": "fallback",
88+
"targeting": {
89+
"fractional": [
90+
{"var": "missing_key"},
91+
["one", 50],
92+
["two", 50]
93+
]
94+
}
5595
}
5696
}
5797
}

gherkin/targeting.feature

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,3 +273,20 @@ Feature: Targeting rules
273273
| missing-variant-targeting-flag | 3 | GENERAL |
274274
| non-string-variant-targeting-flag | 2 | |
275275
| empty-targeting-flag | 1 | |
276+
277+
@operator-errors
278+
Scenario Outline: Custom operator errors return null and fall back to default variant
279+
Given a String-flag with key "<key>" and a default value "wrong"
280+
And a context containing a key "version", with type "String" and with value "<context_value>"
281+
When the flag was evaluated with details
282+
Then the resolved details value should be "fallback"
283+
Examples:
284+
| key | context_value |
285+
| semver-invalid-version-flag | not-a-version |
286+
| semver-invalid-operator-flag | 1.0.0 |
287+
288+
@operator-errors
289+
Scenario: fractional operator with missing bucket key falls back to default variant
290+
Given a String-flag with key "fractional-null-bucket-key-flag" and a default value "wrong"
291+
When the flag was evaluated with details
292+
Then the resolved details value should be "fallback"

0 commit comments

Comments
 (0)