Skip to content

Commit

Permalink
feat: add tests for config edge cases (#85)
Browse files Browse the repository at this point in the history
Signed-off-by: Todd Baert <[email protected]>
  • Loading branch information
toddbaert authored Dec 5, 2023
1 parent 550af35 commit 14eadc1
Show file tree
Hide file tree
Showing 7 changed files with 116 additions and 6 deletions.
3 changes: 2 additions & 1 deletion flagd/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# we NEED flagd v0.6.4 as a minimum
FROM ghcr.io/open-feature/flagd:v0.7.0 as flagd
FROM ghcr.io/open-feature/flagd:v0.7.2 as flagd

FROM busybox:1.36

Expand All @@ -13,4 +13,5 @@ ENTRYPOINT ["sh", "change-flag-wrapper.sh", "./flagd", "start", \
"-f", "file:changing-flag.json", \
"-f", "file:custom-ops.json", \
"-f", "file:evaluator-refs.json", \
"-f", "file:edge-case-flags.json", \
"-f", "file:zero-flags.json"]
2 changes: 1 addition & 1 deletion flagd/Dockerfile.unstable
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# we NEED flagd v0.6.4 as a minimum
FROM ghcr.io/open-feature/flagd:v0.6.6 as flagd
FROM ghcr.io/open-feature/flagd:v0.7.2 as flagd

FROM busybox:1.36

Expand Down
18 changes: 16 additions & 2 deletions flags/custom-ops.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,14 @@
{
"ends_with": [{"var": "id"}, "xyz"]
},
"postfix", "none"
"postfix", {
"if": [
{
"ends_with": [{"var": "id"}, 3]
},
"fail", "none"
]
}
]
}
]
Expand Down Expand Up @@ -68,7 +75,14 @@
{
"sem_ver": [{"var": "version"}, "<", "2.0.0"]
},
"lesser", "none"
"lesser", {
"if": [
{
"sem_ver": [{"var": "version"}, "=", "2.0.0.0"]
},
"fail", "none"
]
}
]
}
]
Expand Down
48 changes: 48 additions & 0 deletions flags/edge-case-flags.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{
"flags": {
"targeting-null-variant-flag": {
"state": "ENABLED",
"variants": {
"one": 1,
"two": 2
},
"defaultVariant": "two",
"targeting": {
"if": [true, null, "one"]
}
},
"error-targeting-flag": {
"state": "ENABLED",
"variants": {
"one": 1,
"two": 2
},
"defaultVariant": "two",
"targeting": {
"invalid": ["this is not valid targeting"]
}
},
"missing-variant-targeting-flag": {
"state": "ENABLED",
"variants": {
"one": 1,
"two": 2
},
"defaultVariant": "two",
"targeting": {
"if": [true, "three", "one"]
}
},
"non-string-variant-targeting-flag": {
"state": "ENABLED",
"variants": {
"false": 1,
"true": 2
},
"defaultVariant": "false",
"targeting": {
"if": [true, true, false]
}
}
}
}
25 changes: 25 additions & 0 deletions flags/testing-flags.json
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,31 @@
]
}
},
"timestamp-flag": {
"state": "ENABLED",
"variants": {
"past": -1,
"future": 1,
"none": 0
},
"defaultVariant": "none",
"targeting": {
"if": [
{
">": [ { "var": "$flagd.timestamp" }, { "var": "time" } ]
},
"past",
{
"if": [
{
"<": [ { "var": "$flagd.timestamp" }, { "var": "time" } ]
},
"future", "none"
]
}
]
}
},
"wrong-flag": {
"state": "ENABLED",
"variants": {
Expand Down
25 changes: 23 additions & 2 deletions gherkin/flagd-json-evaluator.feature
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ Feature: flagd json evaluation
| "queen" | "clubs" |
| "ten" | "diamonds" |
| "nine" | "hearts" |
| 3 | "wild" |

Scenario Outline: Substring operators
When a string flag with key "starts-ends-flag" is evaluated with default value "fallback"
Expand All @@ -38,7 +39,8 @@ Feature: flagd json evaluation
| "abcdef" | "prefix" |
| "uvwxyz" | "postfix" |
| "abcxyz" | "prefix" |
| "lmnopq" | "none" |
| "lmnopq" | "none" |
| 3 | "none" |

Scenario Outline: Semantic version operator numeric comparision
When a string flag with key "equal-greater-lesser-version-flag" is evaluated with default value "fallback"
Expand All @@ -50,7 +52,7 @@ Feature: flagd json evaluation
| "2.1.0" | "greater" |
| "1.9.0" | "lesser" |
| "2.0.0-alpha" | "lesser" |
| "2.0.0.0" | "none" |
| "2.0.0.0" | "none" |

Scenario Outline: Semantic version operator semantic comparision
When a string flag with key "major-minor-version-flag" is evaluated with default value "fallback"
Expand All @@ -61,3 +63,22 @@ Feature: flagd json evaluation
| "3.0.1" | "minor" |
| "3.1.0" | "major" |
| "4.0.0" | "none" |

Scenario Outline: Time-based operations
When an integer flag with key "timestamp-flag" is evaluated with default value 0
And a context containing a key "time", with value <time>
Then the returned value should be <value>
Examples:
| time | value |
| 1 | -1 |
| 4133980802 | 1 |

Scenario Outline: Errors and edge cases
When an integer flag with key <key> is evaluated with default value 3
Then the returned value should be <value>
Examples:
| key | value |
| "targeting-null-variant-flag" | 2 |
| "error-targeting-flag" | 3 |
| "missing-variant-targeting-flag" | 3 |
| "non-string-variant-targeting-flag" | 2 |
1 change: 1 addition & 0 deletions sync/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ ENTRYPOINT ["sh", "change-flag-wrapper.sh", "./sync", "start", \
"-f", "changing-flag.json", \
"-f", "custom-ops.json", \
"-f", "evaluator-refs.json", \
"-f", "edge-case-flags.json", \
"-f", "zero-flags.json"]

0 comments on commit 14eadc1

Please sign in to comment.