Skip to content

Commit 2dcf451

Browse files
committed
in_blob: fix glob function for win32
Signed-off-by: zshuang0316 <zshuang0316@163.com>
1 parent 10ebd3a commit 2dcf451

File tree

3 files changed

+82
-0
lines changed

3 files changed

+82
-0
lines changed

plugins/in_blob/win32_glob.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ static int glob(const char *path,
150150
return result;
151151
}
152152
}
153+
context->gl_pathc = entries;
153154
}
154155

155156
return result;

tests/internal/CMakeLists.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,13 @@ if(FLB_HAVE_LIBYAML)
8181
)
8282
endif()
8383

84+
if (WIN32)
85+
set(UNIT_TESTS_FILES
86+
${UNIT_TESTS_FILES}
87+
win32_glob.c
88+
)
89+
endif()
90+
8491
if (NOT WIN32)
8592
set(UNIT_TESTS_FILES
8693
${UNIT_TESTS_FILES}

tests/internal/win32_glob.c

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
#include <fluent-bit/flb_info.h>
2+
#include <fluent-bit/flb_mem.h>
3+
#include <fluent-bit/flb_str.h>
4+
#include "flb_tests_internal.h"
5+
6+
#ifdef FLB_SYSTEM_WINDOWS
7+
#include "../../plugins/in_blob/win32_glob.c"
8+
9+
void test_glob_basic()
10+
{
11+
glob_t glob_data;
12+
int ret;
13+
FILE *fp;
14+
15+
/* Create some dummy files */
16+
fp = fopen("test_glob_1.txt", "w");
17+
if (fp) fclose(fp);
18+
fp = fopen("test_glob_2.txt", "w");
19+
if (fp) fclose(fp);
20+
21+
ret = glob("test_glob_*.txt", 0, NULL, &glob_data);
22+
TEST_CHECK(ret == 0);
23+
TEST_CHECK(glob_data.gl_pathc == 2);
24+
25+
globfree(&glob_data);
26+
27+
/* Cleanup */
28+
unlink("test_glob_1.txt");
29+
unlink("test_glob_2.txt");
30+
}
31+
32+
void test_glob_nomatch()
33+
{
34+
glob_t glob_data = {0};
35+
int ret;
36+
37+
ret = glob("non_existent_*.txt", 0, NULL, &glob_data);
38+
TEST_CHECK(ret == GLOB_NOMATCH);
39+
40+
globfree(&glob_data);
41+
}
42+
43+
void test_glob_wildcard()
44+
{
45+
glob_t glob_data;
46+
int ret;
47+
FILE *fp;
48+
49+
/* Create dummy file */
50+
fp = fopen("test_wildcard.txt", "w");
51+
if (fp) fclose(fp);
52+
53+
ret = glob("test_wild*.txt", 0, NULL, &glob_data);
54+
TEST_CHECK(ret == 0);
55+
TEST_CHECK(glob_data.gl_pathc == 1);
56+
if (glob_data.gl_pathc > 0) {
57+
TEST_CHECK(strstr(glob_data.gl_pathv[0], "test_wildcard.txt") != NULL);
58+
}
59+
60+
globfree(&glob_data);
61+
unlink("test_wildcard.txt");
62+
}
63+
64+
TEST_LIST = {
65+
{ "basic", test_glob_basic },
66+
{ "nomatch", test_glob_nomatch },
67+
{ "wildcard", test_glob_wildcard },
68+
{ 0 }
69+
};
70+
#else
71+
TEST_LIST = {
72+
{ 0 }
73+
};
74+
#endif

0 commit comments

Comments
 (0)