Skip to content

Commit 31afd6e

Browse files
aepfliCopilottoddbaert
authored
feat(semver): add edge case scenarios for v-prefix, partial versions, and build metadata (#341)
Signed-off-by: Simon Schrottner <simon.schrottner@dynatrace.com> Signed-off-by: Todd Baert <todd.baert@dynatrace.com> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Co-authored-by: Todd Baert <todd.baert@dynatrace.com>
1 parent f469a7c commit 31afd6e

4 files changed

Lines changed: 149 additions & 0 deletions

File tree

evaluator/flags/testkit-flags.json

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -487,6 +487,30 @@
487487
["two", 50]
488488
]
489489
}
490+
},
491+
"semver-v-prefix-flag": {
492+
"state": "ENABLED",
493+
"variants": { "match": "match", "no-match": "no-match" },
494+
"defaultVariant": "no-match",
495+
"targeting": {
496+
"if": [{"sem_ver": [{"var": "version"}, "=", "v1.0.0"]}, "match", "no-match"]
497+
}
498+
},
499+
"semver-partial-version-flag": {
500+
"state": "ENABLED",
501+
"variants": { "match": "match", "no-match": "no-match" },
502+
"defaultVariant": "no-match",
503+
"targeting": {
504+
"if": [{"sem_ver": [{"var": "version"}, "^", "1"]}, "match", "no-match"]
505+
}
506+
},
507+
"semver-build-metadata-flag": {
508+
"state": "ENABLED",
509+
"variants": { "match": "match", "no-match": "no-match" },
510+
"defaultVariant": "no-match",
511+
"targeting": {
512+
"if": [{"sem_ver": [{"var": "version"}, "=", "1.0.0+build"]}, "match", "no-match"]
513+
}
490514
}
491515
},
492516
"$evaluators": {

evaluator/gherkin/semver.feature

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,46 @@ Feature: Evaluator semantic version operator
4343
| key | context_value |
4444
| semver-invalid-version-flag | not-a-version |
4545
| semver-invalid-operator-flag | 1.0.0 |
46+
47+
@semver-edge-cases @semver-v-prefix
48+
Scenario Outline: v-prefix handling
49+
Given an evaluator
50+
And a String-flag with key "semver-v-prefix-flag" and a fallback value "fallback"
51+
And a context containing a key "version", with type "String" and with value "<version>"
52+
When the flag was evaluated with details
53+
Then the resolved details value should be "<value>"
54+
Examples:
55+
| version | value |
56+
| 1.0.0 | match |
57+
| v1.0.0 | match |
58+
| V1.0.0 | match |
59+
| 2.0.0 | no-match |
60+
61+
@semver-edge-cases @semver-partial-version
62+
Scenario Outline: partial version handling
63+
Given an evaluator
64+
And a String-flag with key "semver-partial-version-flag" and a fallback value "fallback"
65+
And a context containing a key "version", with type "<type>" and with value "<version>"
66+
When the flag was evaluated with details
67+
Then the resolved details value should be "<value>"
68+
Examples:
69+
| version | type | value |
70+
| 1.5.0 | String | match |
71+
| 1.0.0 | String | match |
72+
| 1.0 | String | match |
73+
| 1 | String | match |
74+
| 1 | Integer | match |
75+
| 2.0.0 | String | no-match |
76+
77+
@semver-edge-cases @semver-build-metadata
78+
Scenario Outline: build metadata ignored in comparison
79+
Given an evaluator
80+
And a String-flag with key "semver-build-metadata-flag" and a fallback value "fallback"
81+
And a context containing a key "version", with type "String" and with value "<version>"
82+
When the flag was evaluated with details
83+
Then the resolved details value should be "<value>"
84+
Examples:
85+
| version | value |
86+
| 1.0.0 | match |
87+
| 1.0.0+other | match |
88+
| 2.0.0 | no-match |

flags/custom-ops.json

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,48 @@
312312
}
313313
]
314314
}
315+
},
316+
"semver-v-prefix-flag": {
317+
"state": "ENABLED",
318+
"variants": {
319+
"match": "match",
320+
"no-match": "no-match"
321+
},
322+
"defaultVariant": "no-match",
323+
"targeting": {
324+
"if": [
325+
{"sem_ver": [{"var": "version"}, "=", "v1.0.0"]},
326+
"match", "no-match"
327+
]
328+
}
329+
},
330+
"semver-partial-version-flag": {
331+
"state": "ENABLED",
332+
"variants": {
333+
"match": "match",
334+
"no-match": "no-match"
335+
},
336+
"defaultVariant": "no-match",
337+
"targeting": {
338+
"if": [
339+
{"sem_ver": [{"var": "version"}, "^", "1"]},
340+
"match", "no-match"
341+
]
342+
}
343+
},
344+
"semver-build-metadata-flag": {
345+
"state": "ENABLED",
346+
"variants": {
347+
"match": "match",
348+
"no-match": "no-match"
349+
},
350+
"defaultVariant": "no-match",
351+
"targeting": {
352+
"if": [
353+
{"sem_ver": [{"var": "version"}, "=", "1.0.0+build"]},
354+
"match", "no-match"
355+
]
356+
}
315357
}
316358
}
317359
}

gherkin/targeting.feature

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,46 @@ Feature: Targeting rules
246246
| 3.1.0 | major |
247247
| 4.0.0 | none |
248248

249+
@semver @semver-edge-cases @semver-v-prefix
250+
Scenario Outline: sem_ver v-prefix handling
251+
Given a String-flag with key "semver-v-prefix-flag" and a default value "fallback"
252+
And a context containing a key "version", with type "String" and with value "<version>"
253+
When the flag was evaluated with details
254+
Then the resolved details value should be "<value>"
255+
Examples:
256+
| version | value |
257+
| 1.0.0 | match |
258+
| v1.0.0 | match |
259+
| V1.0.0 | match |
260+
| 2.0.0 | no-match |
261+
262+
@semver @semver-edge-cases @semver-partial-version
263+
Scenario Outline: sem_ver partial version handling
264+
Given a String-flag with key "semver-partial-version-flag" and a default value "fallback"
265+
And a context containing a key "version", with type "<type>" and with value "<version>"
266+
When the flag was evaluated with details
267+
Then the resolved details value should be "<value>"
268+
Examples:
269+
| version | type | value |
270+
| 1.5.0 | String | match |
271+
| 1.0.0 | String | match |
272+
| 1.0 | String | match |
273+
| 1 | String | match |
274+
| 1 | Integer | match |
275+
| 2.0.0 | String | no-match |
276+
277+
@semver @semver-edge-cases @semver-build-metadata
278+
Scenario Outline: sem_ver build metadata ignored
279+
Given a String-flag with key "semver-build-metadata-flag" and a default value "fallback"
280+
And a context containing a key "version", with type "String" and with value "<version>"
281+
When the flag was evaluated with details
282+
Then the resolved details value should be "<value>"
283+
Examples:
284+
| version | value |
285+
| 1.0.0 | match |
286+
| 1.0.0+other | match |
287+
| 2.0.0 | no-match |
288+
249289
Scenario Outline: Time-based operations
250290
Given a Integer-flag with key "timestamp-flag" and a default value "0"
251291
And a context containing a key "time", with type "Integer" and with value "<time>"

0 commit comments

Comments
 (0)