Skip to content

Commit f3f7908

Browse files
committed
tests: plugin_alias: Add internal tests for handling plugin aliases
Signed-off-by: Hiroshi Hatake <hiroshi@chronosphere.io>
1 parent 4b06c62 commit f3f7908

2 files changed

Lines changed: 97 additions & 0 deletions

File tree

tests/internal/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ set(UNIT_TESTS_FILES
5353
endianness.c
5454
task_map.c
5555
strptime.c
56+
plugin_alias.c
5657
storage_inherit.c
5758
unicode.c
5859
opentelemetry.c

tests/internal/plugin_alias.c

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2+
3+
/* Fluent Bit
4+
* ==========
5+
* Copyright (C) 2015-2026 The Fluent Bit Authors
6+
*
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
*/
19+
20+
#include <fluent-bit/flb_info.h>
21+
#include <fluent-bit/flb_mem.h>
22+
#include <fluent-bit/flb_plugin.h>
23+
#include <fluent-bit/flb_plugin_alias.h>
24+
#include <fluent-bit/flb_network.h>
25+
26+
#include <string.h>
27+
28+
#include "flb_tests_internal.h"
29+
30+
void plugin_alias_lookup_test()
31+
{
32+
const char *alias_target;
33+
34+
alias_target = flb_plugin_alias_get(FLB_PLUGIN_OUTPUT, "elasticsearch",
35+
strlen("elasticsearch"));
36+
if (!TEST_CHECK(alias_target != NULL)) {
37+
TEST_MSG("output plugin alias was not resolved");
38+
return;
39+
}
40+
41+
if (!TEST_CHECK(strcmp(alias_target, "es") == 0)) {
42+
TEST_MSG("unexpected alias target: %s", alias_target);
43+
}
44+
}
45+
46+
void plugin_alias_rewrite_test()
47+
{
48+
char *rewritten_name;
49+
50+
rewritten_name = flb_plugin_alias_rewrite(FLB_PLUGIN_OUTPUT,
51+
"elasticsearch://127.0.0.1:9200");
52+
if (!TEST_CHECK(rewritten_name != NULL)) {
53+
TEST_MSG("could not rewrite output plugin alias");
54+
return;
55+
}
56+
57+
if (!TEST_CHECK(strcmp(rewritten_name, "es://127.0.0.1:9200") == 0)) {
58+
TEST_MSG("unexpected rewritten output plugin name: %s", rewritten_name);
59+
}
60+
61+
flb_free(rewritten_name);
62+
}
63+
64+
void network_alias_address_parse_test()
65+
{
66+
int ret;
67+
struct flb_net_host host;
68+
69+
ret = flb_net_host_set("es", &host, "elasticsearch://127.0.0.1:9200/path");
70+
if (!TEST_CHECK(ret == 0)) {
71+
TEST_MSG("could not parse alias output address");
72+
return;
73+
}
74+
75+
if (!TEST_CHECK(strcmp(host.name, "127.0.0.1") == 0)) {
76+
TEST_MSG("unexpected host name parsed from alias output address: %s",
77+
host.name);
78+
}
79+
80+
if (!TEST_CHECK(host.port == 9200)) {
81+
TEST_MSG("unexpected host port parsed from alias output address: %d",
82+
host.port);
83+
}
84+
85+
flb_sds_destroy(host.name);
86+
flb_sds_destroy(host.listen);
87+
flb_uri_destroy(host.uri);
88+
flb_sds_destroy(host.address);
89+
}
90+
91+
TEST_LIST = {
92+
{ "plugin_alias_lookup_test", plugin_alias_lookup_test },
93+
{ "plugin_alias_rewrite_test", plugin_alias_rewrite_test },
94+
{ "network_alias_address_parse_test", network_alias_address_parse_test },
95+
{ 0 }
96+
};

0 commit comments

Comments
 (0)