Skip to content

Commit 3cedd69

Browse files
committed
tests: internal: routing: add precedense check
Signed-off-by: Eduardo Silva <[email protected]>
1 parent 62cbf2a commit 3cedd69

File tree

2 files changed

+68
-1
lines changed

2 files changed

+68
-1
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---
2+
pipeline:
3+
inputs:
4+
- name: lib
5+
routes:
6+
logs:
7+
- name: default_route
8+
condition:
9+
default: true
10+
to:
11+
outputs:
12+
- name: lib_route
13+
outputs:
14+
- name: lib_route
15+
type: lib

tests/internal/router_config.c

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include <fluent-bit/flb_config.h>
77
#include <fluent-bit/flb_router.h>
88
#include <fluent-bit/flb_sds.h>
9+
#include <fluent-bit/flb_event.h>
910
#include <fluent-bit/config_format/flb_cf.h>
1011

1112
#include <cfl/cfl.h>
@@ -788,7 +789,9 @@ void test_router_apply_config_missing_output()
788789
cfl_list_add(&route_output._head, &route.outputs);
789790

790791
TEST_CHECK(flb_router_apply_config(&config) == 0);
791-
TEST_CHECK(cfl_list_is_empty(&input.routes_direct));
792+
793+
/* note mk_list_is_empty return 0 if is empty */
794+
TEST_CHECK(!mk_list_is_empty(&input.routes_direct));
792795

793796
flb_router_exit(&config);
794797

@@ -799,6 +802,54 @@ void test_router_apply_config_missing_output()
799802
flb_sds_destroy(route_output.name);
800803
}
801804

805+
void test_router_route_default_precedence()
806+
{
807+
struct cfl_list routes;
808+
struct flb_cf *cf;
809+
struct flb_input_routes *input_routes;
810+
struct flb_route *route;
811+
struct flb_route_output *output;
812+
struct flb_event_chunk chunk;
813+
int ret;
814+
int match;
815+
816+
cf = flb_cf_yaml_create(NULL, (char *) FLB_ROUTER_TEST_FILE("precedence.yaml"), NULL, 0);
817+
TEST_CHECK(cf != NULL);
818+
if (!cf) {
819+
return;
820+
}
821+
822+
cfl_list_init(&routes);
823+
824+
ret = flb_router_config_parse(cf, &routes, NULL);
825+
TEST_CHECK(ret == 0);
826+
if (ret != 0) {
827+
flb_cf_destroy(cf);
828+
return;
829+
}
830+
831+
input_routes = cfl_list_entry(routes.next, struct flb_input_routes, _head);
832+
TEST_CHECK(strcmp(input_routes->input_name, "lib") == 0);
833+
834+
route = cfl_list_entry(input_routes->routes.next, struct flb_route, _head);
835+
TEST_CHECK(route->condition != NULL);
836+
TEST_CHECK(route->condition->is_default == FLB_TRUE);
837+
838+
memset(&chunk, 0, sizeof(chunk));
839+
chunk.type = FLB_EVENT_TYPE_LOGS;
840+
841+
TEST_CHECK(flb_route_condition_eval(&chunk, route) == FLB_TRUE);
842+
843+
output = cfl_list_entry(route->outputs.next, struct flb_route_output, _head);
844+
TEST_CHECK(strcmp(output->name, "lib_route") == 0);
845+
846+
match = flb_router_match("lib.input", strlen("lib.input"), "does-not-match", NULL);
847+
TEST_CHECK(match == FLB_FALSE);
848+
849+
flb_router_routes_destroy(&routes);
850+
flb_cf_destroy(cf);
851+
}
852+
802853
TEST_LIST = {
803854
{ "parse_basic", test_router_config_parse_basic },
804855
{ "duplicate_route", test_router_config_duplicate_route },
@@ -807,5 +858,6 @@ TEST_LIST = {
807858
{ "parse_metrics_file", test_router_config_parse_file_metrics },
808859
{ "apply_config_success", test_router_apply_config_success },
809860
{ "apply_config_missing_output", test_router_apply_config_missing_output },
861+
{ "route_default_precedence", test_router_route_default_precedence },
810862
{ 0 }
811863
};

0 commit comments

Comments
 (0)