Skip to content

Commit d31f2f9

Browse files
authored
feat: add tests for no defaultVariant (#269)
Signed-off-by: Todd Baert <[email protected]>
1 parent 07a700b commit d31f2f9

File tree

2 files changed

+77
-0
lines changed

2 files changed

+77
-0
lines changed

flags/testing-flags.json

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,62 @@
151151
null
152152
]
153153
}
154+
},
155+
"null-default-flag": {
156+
"state": "ENABLED",
157+
"variants": {
158+
"on": true,
159+
"off": false
160+
},
161+
"defaultVariant": null
162+
},
163+
"undefined-default-flag": {
164+
"state": "ENABLED",
165+
"variants": {
166+
"small": 10,
167+
"big": 1000
168+
}
169+
},
170+
"no-default-flag-null-targeting-variant": {
171+
"state": "ENABLED",
172+
"variants": {
173+
"normal": "CFO",
174+
"special": "CEO"
175+
},
176+
"targeting": {
177+
"if": [
178+
{
179+
"==": [
180+
181+
{
182+
"var": ["email"]
183+
}
184+
]
185+
},
186+
"special",
187+
null
188+
]
189+
}
190+
},
191+
"no-default-flag-undefined-targeting-variant": {
192+
"state": "ENABLED",
193+
"variants": {
194+
"normal": "CFO",
195+
"special": "CEO"
196+
},
197+
"targeting": {
198+
"if": [
199+
{
200+
"==": [
201+
202+
{
203+
"var": ["email"]
204+
}
205+
]
206+
},
207+
"special"
208+
]
209+
}
154210
}
155211
}
156212
}

gherkin/evaluation.feature

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,24 @@ Feature: flagd evaluations
6363
| string-targeted-zero-flag | String | hi | |
6464
| integer-targeted-zero-flag | Integer | 1 | 0 |
6565
| float-targeted-zero-flag | Float | 0.1 | 0.0 |
66+
67+
@no-default
68+
Scenario Outline: Resolves flag with no defaultValue correctly
69+
Given a <type>-flag with key "<key>" and a default value "<default>"
70+
And a context containing a key "email", with type "String" and with value "<email>"
71+
When the flag was evaluated with details
72+
Then the resolved details value should be "<resolved_value>"
73+
And the reason should be "<reason>"
74+
And the error-code should be "<error_code>"
75+
76+
# For now, no defaultValue is resolved as FLAG_NOT_FOUND to result in a code default.
77+
# This may be handled more gracefully in the future.
78+
Examples:
79+
| key | type | email | default | resolved_value | reason | error_code |
80+
| null-default-flag | Boolean | | true | true | ERROR | FLAG_NOT_FOUND |
81+
| null-default-flag | Boolean | | false | false | ERROR | FLAG_NOT_FOUND |
82+
| undefined-default-flag | Integer | | 100 | 100 | ERROR | FLAG_NOT_FOUND |
83+
| no-default-flag-null-targeting-variant | String | wozniak@orange.com | Inventor | Inventor | ERROR | FLAG_NOT_FOUND |
84+
| no-default-flag-null-targeting-variant | String | wozniak@orange.com | Founder | Founder | ERROR | FLAG_NOT_FOUND |
85+
| no-default-flag-null-targeting-variant | String | jobs@orange.com | CEO | CEO | TARGETING_MATCH | |
86+
| no-default-flag-undefined-targeting-variant | String | wozniak@orange.com | Retired | Retired | ERROR | FLAG_NOT_FOUND |

0 commit comments

Comments
 (0)