Skip to content

Commit 7c25665

Browse files
edsipercosmo0920
authored andcommitted
tests: internal: fstore: add regression test for chunk and fstore deletion
Signed-off-by: Eduardo Silva <eduardo@chronosphere.io>
1 parent 4a40def commit 7c25665

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

tests/internal/fstore.c

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030

3131
#include <sys/types.h>
3232
#include <sys/stat.h>
33+
#include <errno.h>
3334

3435
#ifdef FLB_SYSTEM_WINDOWS
3536
/* Not yet implemented! */
@@ -78,7 +79,57 @@ void cb_all()
7879
flb_fstore_destroy(fs);
7980
}
8081

82+
void cb_delete_after_external_close()
83+
{
84+
int ret;
85+
struct stat st_data;
86+
struct flb_fstore *fs;
87+
struct flb_fstore_stream *st;
88+
struct flb_fstore_file *fsf;
89+
struct cio_chunk *chunk;
90+
91+
cio_utils_recursive_delete(FSF_STORE_PATH);
92+
93+
fs = flb_fstore_create(FSF_STORE_PATH, FLB_FSTORE_FS);
94+
TEST_CHECK(fs != NULL);
95+
if (!fs) {
96+
return;
97+
}
98+
99+
st = flb_fstore_stream_create(fs, "abc");
100+
TEST_CHECK(st != NULL);
101+
if (!st) {
102+
flb_fstore_destroy(fs);
103+
return;
104+
}
105+
106+
fsf = flb_fstore_file_create(fs, st, "example.txt", 100);
107+
TEST_CHECK(fsf != NULL);
108+
if (!fsf) {
109+
flb_fstore_destroy(fs);
110+
return;
111+
}
112+
113+
chunk = fsf->chunk;
114+
TEST_CHECK(chunk != NULL);
115+
if (!chunk) {
116+
flb_fstore_destroy(fs);
117+
return;
118+
}
119+
120+
cio_chunk_close(chunk, CIO_TRUE);
121+
122+
ret = stat(FSF_STORE_PATH "/abc/example.txt", &st_data);
123+
TEST_CHECK(ret == -1 && errno == ENOENT);
124+
125+
ret = flb_fstore_file_delete(fs, fsf);
126+
TEST_CHECK(ret == 0);
127+
128+
flb_fstore_destroy(fs);
129+
}
130+
81131
TEST_LIST = {
82132
{ "all" , cb_all},
133+
{ "delete_after_external_close", cb_delete_after_external_close},
83134
{ NULL }
84135
};

0 commit comments

Comments
 (0)