Skip to content

Commit 311d930

Browse files
committed
tests: internal: conditionals: NULL record should fail condition
Signed-off-by: Eduardo Silva <[email protected]>
1 parent ae04ea2 commit 311d930

File tree

1 file changed

+27
-4
lines changed

1 file changed

+27
-4
lines changed

tests/internal/conditionals.c

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ void test_condition_equals()
364364
cond = flb_condition_create(FLB_COND_OP_AND);
365365
TEST_CHECK(cond != NULL);
366366

367-
TEST_CHECK(flb_condition_add_rule(cond, "$level", FLB_RULE_OP_EQ,
367+
TEST_CHECK(flb_condition_add_rule(cond, "$level", FLB_RULE_OP_EQ,
368368
"error", 0, RECORD_CONTEXT_BODY) == FLB_TRUE);
369369

370370
result = flb_condition_evaluate(cond, &record_data->chunk);
@@ -445,7 +445,7 @@ void test_condition_not_equals()
445445
cond = flb_condition_create(FLB_COND_OP_AND);
446446
TEST_CHECK(cond != NULL);
447447

448-
TEST_CHECK(flb_condition_add_rule(cond, "$level", FLB_RULE_OP_NEQ,
448+
TEST_CHECK(flb_condition_add_rule(cond, "$level", FLB_RULE_OP_NEQ,
449449
"error", 0, RECORD_CONTEXT_BODY) == FLB_TRUE);
450450

451451
result = flb_condition_evaluate(cond, &record_data->chunk);
@@ -734,15 +734,38 @@ void test_condition_invalid_expressions()
734734
result = flb_condition_evaluate(NULL, &record_data->chunk);
735735
TEST_CHECK(result == FLB_TRUE);
736736

737-
/* Test NULL record */
737+
/* Test NULL record with AND condition */
738738
cond = flb_condition_create(FLB_COND_OP_AND);
739739
TEST_CHECK(cond != NULL);
740740

741741
TEST_CHECK(flb_condition_add_rule(cond, "$level", FLB_RULE_OP_EQ,
742742
"error", 0, RECORD_CONTEXT_BODY) == FLB_TRUE);
743743

744744
result = flb_condition_evaluate(cond, NULL);
745-
TEST_CHECK(result == FLB_TRUE);
745+
TEST_CHECK(result == FLB_FALSE); /* NULL record should fail condition */
746+
747+
flb_condition_destroy(cond);
748+
749+
/* Test NULL record with OR condition */
750+
cond = flb_condition_create(FLB_COND_OP_OR);
751+
TEST_CHECK(cond != NULL);
752+
753+
TEST_CHECK(flb_condition_add_rule(cond, "$level", FLB_RULE_OP_EQ,
754+
"error", 0, RECORD_CONTEXT_BODY) == FLB_TRUE);
755+
TEST_CHECK(flb_condition_add_rule(cond, "$level", FLB_RULE_OP_EQ,
756+
"warn", 0, RECORD_CONTEXT_BODY) == FLB_TRUE);
757+
758+
result = flb_condition_evaluate(cond, NULL);
759+
TEST_CHECK(result == FLB_FALSE); /* NULL record should fail condition */
760+
761+
flb_condition_destroy(cond);
762+
763+
/* Test NULL record with empty condition */
764+
cond = flb_condition_create(FLB_COND_OP_AND);
765+
TEST_CHECK(cond != NULL);
766+
767+
result = flb_condition_evaluate(cond, NULL);
768+
TEST_CHECK(result == FLB_FALSE); /* NULL record should fail even with empty condition */
746769

747770
flb_condition_destroy(cond);
748771

0 commit comments

Comments
 (0)