Skip to content

Commit f22e80f

Browse files
committed
test(openfeature): add NOT_MATCHES invalid-regex test and fix comment
- Add test case for NOT_MATCHES with invalid regex pattern, which follows the same PatternSyntaxException propagation path as MATCHES - Fix misleading comment on integer-string-variant-flag test case to accurately describe the PARSE_ERROR trigger (unparseable variant value)
1 parent 38c11be commit f22e80f

1 file changed

Lines changed: 29 additions & 1 deletion

File tree

  • products/feature-flagging/feature-flagging-api/src/test/java/datadog/trace/api/openfeature

products/feature-flagging/feature-flagging-api/src/test/java/datadog/trace/api/openfeature/DDEvaluatorTest.java

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,8 @@ private static List<TestCase<?>> evaluateTestCases() {
314314
.flag("integer-flag")
315315
.targetingKey("user-123")
316316
.result(new Result<>(0.0).reason(ERROR.name()).errorCode(ErrorCode.TYPE_MISMATCH)),
317-
// Variant value type mismatch: INTEGER flag with string variant value
317+
// Variant stores "not-a-number" for an INTEGER flag; Double.parseDouble fails ->
318+
// PARSE_ERROR
318319
new TestCase<>(0)
319320
.flag("integer-string-variant-flag")
320321
.targetingKey("user-123")
@@ -494,6 +495,11 @@ private static List<TestCase<?>> evaluateTestCases() {
494495
.flag("invalid-regex-flag")
495496
.targetingKey("user-123")
496497
.context("email", "user@example.com")
498+
.result(new Result<>("default").reason(ERROR.name()).errorCode(ErrorCode.PARSE_ERROR)),
499+
new TestCase<>("default")
500+
.flag("invalid-regex-not-matches-flag")
501+
.targetingKey("user-123")
502+
.context("email", "user@example.com")
497503
.result(new Result<>("default").reason(ERROR.name()).errorCode(ErrorCode.PARSE_ERROR)));
498504
}
499505

@@ -587,6 +593,7 @@ private ServerConfiguration createTestConfiguration() {
587593
"integer-string-variant-flag",
588594
createSimpleFlag("integer-string-variant-flag", ValueType.INTEGER, "not-a-number", "bad"));
589595
flags.put("invalid-regex-flag", createInvalidRegexFlag());
596+
flags.put("invalid-regex-not-matches-flag", createInvalidRegexNotMatchesFlag());
590597
return new ServerConfiguration(null, null, null, flags);
591598
}
592599

@@ -1288,6 +1295,27 @@ private Flag createInvalidRegexFlag() {
12881295
"invalid-regex-flag", true, ValueType.STRING, variants, singletonList(allocation));
12891296
}
12901297

1298+
private Flag createInvalidRegexNotMatchesFlag() {
1299+
final Map<String, Variant> variants = new HashMap<>();
1300+
variants.put("excluded", new Variant("excluded", "excluded-value"));
1301+
1302+
// Condition with an intentionally invalid regex pattern (unclosed bracket) under NOT_MATCHES
1303+
final List<ConditionConfiguration> conditions =
1304+
singletonList(
1305+
new ConditionConfiguration(ConditionOperator.NOT_MATCHES, "email", "[invalid"));
1306+
final List<Rule> rules = singletonList(new Rule(conditions));
1307+
final List<Split> splits = singletonList(new Split(emptyList(), "excluded", null));
1308+
final Allocation allocation =
1309+
new Allocation("invalid-regex-not-matches-alloc", rules, null, null, splits, false);
1310+
1311+
return new Flag(
1312+
"invalid-regex-not-matches-flag",
1313+
true,
1314+
ValueType.STRING,
1315+
variants,
1316+
singletonList(allocation));
1317+
}
1318+
12911319
private static Map<String, Object> mapOf(final Object... props) {
12921320
final Map<String, Object> result = new HashMap<>(props.length << 1);
12931321
int index = 0;

0 commit comments

Comments
 (0)