Skip to content

Commit fa2d193

Browse files
committed
update json logic engine to v3
Signed-off-by: Michael Beemer <[email protected]>
1 parent 8824708 commit fa2d193

File tree

15 files changed

+2252
-1516
lines changed

15 files changed

+2252
-1516
lines changed

libs/providers/flagd-web/schemas

Submodule schemas updated 41 files

libs/providers/flagd-web/spec

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Subproject commit eaa44da2110d97376d3292ea3963c54bea498a77
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
Feature: Flag evaluation
2+
3+
# This test suite contains scenarios to test the flag evaluation API.
4+
5+
Background:
6+
Given a provider is registered
7+
8+
# basic evaluation
9+
Scenario: Resolves boolean value
10+
When a boolean flag with key "boolean-flag" is evaluated with default value "false"
11+
Then the resolved boolean value should be "true"
12+
13+
Scenario: Resolves string value
14+
When a string flag with key "string-flag" is evaluated with default value "bye"
15+
Then the resolved string value should be "hi"
16+
17+
Scenario: Resolves integer value
18+
When an integer flag with key "integer-flag" is evaluated with default value 1
19+
Then the resolved integer value should be 10
20+
21+
Scenario: Resolves float value
22+
When a float flag with key "float-flag" is evaluated with default value 0.1
23+
Then the resolved float value should be 0.5
24+
25+
Scenario: Resolves object value
26+
When an object flag with key "object-flag" is evaluated with a null default value
27+
Then the resolved object value should be contain fields "showImages", "title", and "imagesPerPage", with values "true", "Check out these pics!" and 100, respectively
28+
29+
# detailed evaluation
30+
Scenario: Resolves boolean details
31+
When a boolean flag with key "boolean-flag" is evaluated with details and default value "false"
32+
Then the resolved boolean details value should be "true", the variant should be "on", and the reason should be "STATIC"
33+
34+
Scenario: Resolves string details
35+
When a string flag with key "string-flag" is evaluated with details and default value "bye"
36+
Then the resolved string details value should be "hi", the variant should be "greeting", and the reason should be "STATIC"
37+
38+
Scenario: Resolves integer details
39+
When an integer flag with key "integer-flag" is evaluated with details and default value 1
40+
Then the resolved integer details value should be 10, the variant should be "ten", and the reason should be "STATIC"
41+
42+
Scenario: Resolves float details
43+
When a float flag with key "float-flag" is evaluated with details and default value 0.1
44+
Then the resolved float details value should be 0.5, the variant should be "half", and the reason should be "STATIC"
45+
46+
Scenario: Resolves object details
47+
When an object flag with key "object-flag" is evaluated with details and a null default value
48+
Then the resolved object details value should be contain fields "showImages", "title", and "imagesPerPage", with values "true", "Check out these pics!" and 100, respectively
49+
And the variant should be "template", and the reason should be "STATIC"
50+
51+
# context-aware evaluation
52+
Scenario: Resolves based on context
53+
When context contains keys "fn", "ln", "age", "customer" with values "Sulisław", "Świętopełk", 29, "false"
54+
And a flag with key "context-aware" is evaluated with default value "EXTERNAL"
55+
Then the resolved string response should be "INTERNAL"
56+
And the resolved flag value is "EXTERNAL" when the context is empty
57+
58+
# errors
59+
Scenario: Flag not found
60+
When a non-existent string flag with key "missing-flag" is evaluated with details and a default value "uh-oh"
61+
Then the default string value should be returned
62+
And the reason should indicate an error and the error code should indicate a missing flag with "FLAG_NOT_FOUND"
63+
64+
Scenario: Type error
65+
When a string flag with key "wrong-flag" is evaluated as an integer, with details and a default value 13
66+
Then the default integer value should be returned
67+
And the reason should indicate an error and the error code should indicate a type mismatch with "TYPE_MISMATCH"

libs/providers/flagd/flagd-testbed

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Subproject commit ed7e0ba660b01e1a22849e1b28ec37453921552e

libs/providers/flagd/schemas

Submodule schemas updated 40 files
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
Feature: Flag evaluation
2+
3+
# This test suite contains scenarios to test the flag evaluation API.
4+
5+
Background:
6+
Given a provider is registered
7+
8+
# basic evaluation
9+
Scenario: Resolves boolean value
10+
When a boolean flag with key "boolean-flag" is evaluated with default value "false"
11+
Then the resolved boolean value should be "true"
12+
13+
Scenario: Resolves string value
14+
When a string flag with key "string-flag" is evaluated with default value "bye"
15+
Then the resolved string value should be "hi"
16+
17+
Scenario: Resolves integer value
18+
When an integer flag with key "integer-flag" is evaluated with default value 1
19+
Then the resolved integer value should be 10
20+
21+
Scenario: Resolves float value
22+
When a float flag with key "float-flag" is evaluated with default value 0.1
23+
Then the resolved float value should be 0.5
24+
25+
Scenario: Resolves object value
26+
When an object flag with key "object-flag" is evaluated with a null default value
27+
Then the resolved object value should be contain fields "showImages", "title", and "imagesPerPage", with values "true", "Check out these pics!" and 100, respectively
28+
29+
# detailed evaluation
30+
Scenario: Resolves boolean details
31+
When a boolean flag with key "boolean-flag" is evaluated with details and default value "false"
32+
Then the resolved boolean details value should be "true", the variant should be "on", and the reason should be "STATIC"
33+
34+
Scenario: Resolves string details
35+
When a string flag with key "string-flag" is evaluated with details and default value "bye"
36+
Then the resolved string details value should be "hi", the variant should be "greeting", and the reason should be "STATIC"
37+
38+
Scenario: Resolves integer details
39+
When an integer flag with key "integer-flag" is evaluated with details and default value 1
40+
Then the resolved integer details value should be 10, the variant should be "ten", and the reason should be "STATIC"
41+
42+
Scenario: Resolves float details
43+
When a float flag with key "float-flag" is evaluated with details and default value 0.1
44+
Then the resolved float details value should be 0.5, the variant should be "half", and the reason should be "STATIC"
45+
46+
Scenario: Resolves object details
47+
When an object flag with key "object-flag" is evaluated with details and a null default value
48+
Then the resolved object details value should be contain fields "showImages", "title", and "imagesPerPage", with values "true", "Check out these pics!" and 100, respectively
49+
And the variant should be "template", and the reason should be "STATIC"
50+
51+
# context-aware evaluation
52+
Scenario: Resolves based on context
53+
When context contains keys "fn", "ln", "age", "customer" with values "Sulisław", "Świętopełk", 29, "false"
54+
And a flag with key "context-aware" is evaluated with default value "EXTERNAL"
55+
Then the resolved string response should be "INTERNAL"
56+
And the resolved flag value is "EXTERNAL" when the context is empty
57+
58+
# errors
59+
Scenario: Flag not found
60+
When a non-existent string flag with key "missing-flag" is evaluated with details and a default value "uh-oh"
61+
Then the default string value should be returned
62+
And the reason should indicate an error and the error code should indicate a missing flag with "FLAG_NOT_FOUND"
63+
64+
Scenario: Type error
65+
When a string flag with key "wrong-flag" is evaluated as an integer, with details and a default value 13
66+
Then the default integer value should be returned
67+
And the reason should indicate an error and the error code should indicate a type mismatch with "TYPE_MISMATCH"
Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
Feature: flagd json evaluation
2+
3+
# This test suite contains scenarios to test the json-evaluation of flagd and flag-in-process providers.
4+
# It's associated with the flags configured in flags/changing-flag.json, flags/zero-flags.json, flags/custom-ops.json and evaluator-refs.json.
5+
# It should be used in conjunction with the suites supplied by the OpenFeature specification.
6+
7+
Background:
8+
Given a flagd provider is set
9+
10+
# evaluator refs
11+
Scenario Outline: Evaluator reuse
12+
When a string flag with key <key> is evaluated with default value "fallback"
13+
And a context containing a key "email", with value "[email protected]"
14+
Then the returned value should be <value>
15+
Examples:
16+
| key | value |
17+
| "some-email-targeted-flag" | "hi" |
18+
| "some-other-email-targeted-flag" | "yes" |
19+
20+
# custom operators
21+
Scenario Outline: Fractional operator
22+
When a string flag with key "fractional-flag" is evaluated with default value "fallback"
23+
And a context containing a nested property with outer key "user" and inner key "name", with value <name>
24+
Then the returned value should be <value>
25+
Examples:
26+
| name | value |
27+
| "jack" | "spades" |
28+
| "queen" | "clubs" |
29+
| "ten" | "diamonds" |
30+
| "nine" | "hearts" |
31+
| 3 | "diamonds" |
32+
33+
Scenario Outline: Fractional operator shorthand
34+
When a string flag with key "fractional-flag-shorthand" is evaluated with default value "fallback"
35+
And a context containing a targeting key with value <targeting key>
36+
Then the returned value should be <value>
37+
Examples:
38+
| targeting key | value |
39+
| "jon@company.com" | "heads" |
40+
| "jane@company.com" | "tails" |
41+
42+
Scenario Outline: Fractional operator with shared seed
43+
When a string flag with key "fractional-flag-A-shared-seed" is evaluated with default value "fallback"
44+
And a context containing a nested property with outer key "user" and inner key "name", with value <name>
45+
Then the returned value should be <value>
46+
Examples:
47+
| name | value |
48+
| "jack" | "hearts" |
49+
| "queen" | "spades" |
50+
| "ten" | "hearts" |
51+
| "nine" | "diamonds" |
52+
53+
Scenario Outline: Second fractional operator with shared seed
54+
When a string flag with key "fractional-flag-B-shared-seed" is evaluated with default value "fallback"
55+
And a context containing a nested property with outer key "user" and inner key "name", with value <name>
56+
Then the returned value should be <value>
57+
Examples:
58+
| name | value |
59+
| "jack" | "ace-of-hearts" |
60+
| "queen" | "ace-of-spades" |
61+
| "ten" | "ace-of-hearts" |
62+
| "nine" | "ace-of-diamonds" |
63+
64+
Scenario Outline: Substring operators
65+
When a string flag with key "starts-ends-flag" is evaluated with default value "fallback"
66+
And a context containing a key "id", with value <id>
67+
Then the returned value should be <value>
68+
Examples:
69+
| id | value |
70+
| "abcdef" | "prefix" |
71+
| "uvwxyz" | "postfix" |
72+
| "abcxyz" | "prefix" |
73+
| "lmnopq" | "none" |
74+
| 3 | "none" |
75+
76+
Scenario Outline: Semantic version operator numeric comparison
77+
When a string flag with key "equal-greater-lesser-version-flag" is evaluated with default value "fallback"
78+
And a context containing a key "version", with value <version>
79+
Then the returned value should be <value>
80+
Examples:
81+
| version | value |
82+
| "2.0.0" | "equal" |
83+
| "2.1.0" | "greater" |
84+
| "1.9.0" | "lesser" |
85+
| "2.0.0-alpha" | "lesser" |
86+
| "2.0.0.0" | "none" |
87+
88+
Scenario Outline: Semantic version operator semantic comparison
89+
When a string flag with key "major-minor-version-flag" is evaluated with default value "fallback"
90+
And a context containing a key "version", with value <version>
91+
Then the returned value should be <value>
92+
Examples:
93+
| version | value |
94+
| "3.0.1" | "minor" |
95+
| "3.1.0" | "major" |
96+
| "4.0.0" | "none" |
97+
98+
Scenario Outline: Time-based operations
99+
When an integer flag with key "timestamp-flag" is evaluated with default value 0
100+
And a context containing a key "time", with value <time>
101+
Then the returned value should be <value>
102+
Examples:
103+
| time | value |
104+
| 1 | -1 |
105+
| 4133980802 | 1 |
106+
107+
Scenario Outline: Targeting by targeting key
108+
When a string flag with key "targeting-key-flag" is evaluated with default value "fallback"
109+
And a context containing a targeting key with value <targeting key>
110+
Then the returned value should be <value>
111+
Then the returned reason should be <reason>
112+
Examples:
113+
| targeting key | value | reason |
114+
| "5c3d8535-f81a-4478-a6d3-afaa4d51199e" | "hit" | "TARGETING_MATCH" |
115+
| "f20bd32d-703b-48b6-bc8e-79d53c85134a" | "miss" | "DEFAULT" |
116+
117+
Scenario Outline: Errors and edge cases
118+
When an integer flag with key <key> is evaluated with default value 3
119+
Then the returned value should be <value>
120+
Examples:
121+
| key | value |
122+
| "targeting-null-variant-flag" | 2 |
123+
| "error-targeting-flag" | 3 |
124+
| "missing-variant-targeting-flag" | 3 |
125+
| "non-string-variant-targeting-flag" | 2 |
126+
| "empty-targeting-flag" | 1 |
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
Feature: flagd provider disconnect and reconnect functionality
2+
3+
# This test suite tests the reconnection functionality of flagd providers
4+
5+
Scenario: Provider reconnection
6+
Given a flagd provider is set
7+
When a PROVIDER_READY handler and a PROVIDER_ERROR handler are added
8+
Then the PROVIDER_READY handler must run when the provider connects
9+
And the PROVIDER_ERROR handler must run when the provider's connection is lost
10+
And when the connection is reestablished the PROVIDER_READY handler must run again
11+
12+
Scenario: Provider unavailable
13+
Given flagd is unavailable
14+
When a flagd provider is set and initialization is awaited
15+
Then an error should be indicated within the configured deadline
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
Feature: flagd providers
2+
3+
# This test suite contains scenarios to test flagd providers.
4+
# It's associated with the flags configured in flags/changing-flag.json and flags/zero-flags.json.
5+
# It should be used in conjunction with the suites supplied by the OpenFeature specification.
6+
7+
Background:
8+
Given a flagd provider is set
9+
10+
# events
11+
Scenario: Provider ready event
12+
When a PROVIDER_READY handler is added
13+
Then the PROVIDER_READY handler must run
14+
15+
Scenario: Flag change event
16+
When a PROVIDER_CONFIGURATION_CHANGED handler is added
17+
And a flag with key "changing-flag" is modified
18+
Then the PROVIDER_CONFIGURATION_CHANGED handler must run
19+
And the event details must indicate "changing-flag" was altered
20+
21+
# zero evaluation
22+
Scenario: Resolves boolean zero value
23+
When a zero-value boolean flag with key "boolean-zero-flag" is evaluated with default value "true"
24+
Then the resolved boolean zero-value should be "false"
25+
26+
Scenario: Resolves string zero value
27+
When a zero-value string flag with key "string-zero-flag" is evaluated with default value "hi"
28+
Then the resolved string zero-value should be ""
29+
30+
Scenario: Resolves integer zero value
31+
When a zero-value integer flag with key "integer-zero-flag" is evaluated with default value 1
32+
Then the resolved integer zero-value should be 0
33+
34+
Scenario: Resolves float zero value
35+
When a zero-value float flag with key "float-zero-flag" is evaluated with default value 0.1
36+
Then the resolved float zero-value should be 0.0

0 commit comments

Comments
 (0)