summaryrefslogtreecommitdiffstats
path: root/fluent-bit/tests/internal/router.c
blob: 04960a25a46b986c7ef637c63f27bfa6d750b453 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */

#include <fluent-bit/flb_info.h>
#include <fluent-bit/flb_router.h>

#include "flb_tests_internal.h"

struct check {
    char *tag;
    char *match;
    int matched;
};

struct check route_checks[] = {

    {"file.apache.log", "file.*.log" , FLB_TRUE},
    {"cpu.rpi"        , "cpu.rpi"    , FLB_TRUE},
    {"cpu.rpi"        , "cpu.*"      , FLB_TRUE},
    {"cpu.rpi"        , "*"          , FLB_TRUE},
    {"cpu.rpi"        , "*.*"        , FLB_TRUE},
    {"cpu.rpi"        , "*.rpi"      , FLB_TRUE},
    {"cpu.rpi"        , "mem.*"      , FLB_FALSE},
    {"cpu.rpi"        , "*u.r*"      , FLB_TRUE},
    {"hoge"           , "hogeeeeeee" , FLB_FALSE},
    {"test"           , "test"       , FLB_TRUE}
};

void test_router_wildcard()
{
    int i;
    int ret;
    int len;
    int checks = 0;
    struct check *c;

    checks = sizeof(route_checks) / sizeof(struct check);
    for (i = 0; i < checks; i++) {
        c = &route_checks[i];
        len = strlen(c->tag);
        ret = flb_router_match(c->tag, len, c->match, NULL);
        TEST_CHECK(ret == c->matched);
        if (ret != c->matched) {
            fprintf(stderr, "test %i failed: tag=%s match=%s expected_to_match=%s\n",
                    i, c->tag, c->match, c->matched ? "YES": "NO");
        }
    }

    ret = flb_router_match("aaaX", 3, "aaa", NULL);
    TEST_CHECK(ret == FLB_TRUE);
}

TEST_LIST = {
    { "wildcard", test_router_wildcard},
    { 0 }
};