Skip to content

Commit ff81e2e

Browse files
committed
tests: added test coverage for added config parameters
Add test coverage for db.sync, db.journal_mode, and db.locking options and guard SQLDB config tests with FLB_HAVE_SQLDB Fixes #11243. Signed-off-by: Eric D. Schabell <[email protected]>
1 parent 7e4c128 commit ff81e2e

File tree

1 file changed

+180
-0
lines changed

1 file changed

+180
-0
lines changed

tests/runtime/in_kubernetes_events.c

Lines changed: 180 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,77 @@ static struct test_ctx *test_ctx_create(struct flb_lib_out_cb *data)
303303
return ctx;
304304
}
305305

306+
#ifdef FLB_HAVE_SQLDB
307+
/* Create test context with additional config options for config parameter testing */
308+
static struct test_ctx *test_ctx_create_with_config(struct flb_lib_out_cb *data,
309+
const char *db_sync,
310+
const char *db_locking,
311+
const char *db_journal_mode)
312+
{
313+
int i_ffd;
314+
int o_ffd;
315+
int ret;
316+
struct test_ctx *ctx = NULL;
317+
char kube_url[512] = {0};
318+
319+
ctx = flb_calloc(1, sizeof(struct test_ctx));
320+
if (!TEST_CHECK(ctx != NULL)) {
321+
TEST_MSG("flb_calloc failed");
322+
flb_errno();
323+
return NULL;
324+
}
325+
326+
/* Service config */
327+
ctx->flb = flb_create();
328+
flb_service_set(ctx->flb,
329+
"Flush", "0.200000000",
330+
"Grace", "3",
331+
"Log_Level", "debug",
332+
NULL);
333+
334+
/* Input */
335+
i_ffd = flb_input(ctx->flb, (char *) "kubernetes_events", NULL);
336+
TEST_CHECK(i_ffd >= 0);
337+
ctx->i_ffd = i_ffd;
338+
339+
sprintf(kube_url, "http://%s:%d", KUBE_API_HOST, KUBE_API_PORT);
340+
ret = flb_input_set(ctx->flb, i_ffd,
341+
"kube_url", kube_url,
342+
"kube_token_file", KUBE_TOKEN_FILE,
343+
"kube_retention_time", "365000d",
344+
"tls", "off",
345+
"interval_sec", "1",
346+
"interval_nsec", "0",
347+
NULL);
348+
TEST_CHECK(ret == 0);
349+
350+
/* Set optional config parameters if provided */
351+
if (db_sync) {
352+
ret = flb_input_set(ctx->flb, i_ffd, "db.sync", db_sync, NULL);
353+
TEST_CHECK(ret == 0);
354+
}
355+
if (db_locking) {
356+
ret = flb_input_set(ctx->flb, i_ffd, "db.locking", db_locking, NULL);
357+
TEST_CHECK(ret == 0);
358+
}
359+
if (db_journal_mode) {
360+
ret = flb_input_set(ctx->flb, i_ffd, "db.journal_mode", db_journal_mode, NULL);
361+
TEST_CHECK(ret == 0);
362+
}
363+
364+
/* Output */
365+
o_ffd = flb_output(ctx->flb, (char *) "lib", (void *) data);
366+
ctx->o_ffd = o_ffd;
367+
368+
flb_output_set(ctx->flb, ctx->o_ffd,
369+
"match", "*",
370+
"format", "json",
371+
NULL);
372+
373+
return ctx;
374+
}
375+
#endif
376+
306377
static void test_ctx_destroy(struct test_ctx *ctx)
307378
{
308379
TEST_CHECK(ctx != NULL);
@@ -444,10 +515,119 @@ void flb_test_events_with_chunkedrecv()
444515
test_ctx_destroy(ctx);
445516
}
446517

518+
#ifdef FLB_HAVE_SQLDB
519+
/* Test valid db.sync values */
520+
void flb_test_config_db_sync_values()
521+
{
522+
struct flb_lib_out_cb cb_data;
523+
struct test_ctx *ctx;
524+
int ret;
525+
const char *sync_values[] = {"extra", "full", "normal", "off", NULL};
526+
int i;
527+
528+
cb_data.cb = NULL;
529+
cb_data.data = NULL;
530+
531+
for (i = 0; sync_values[i] != NULL; i++) {
532+
ctx = test_ctx_create_with_config(&cb_data,
533+
sync_values[i], /* db.sync */
534+
NULL, /* db.locking */
535+
NULL); /* db.journal_mode */
536+
if (!TEST_CHECK(ctx != NULL)) {
537+
TEST_MSG("test_ctx_create_with_config failed for db.sync=%s", sync_values[i]);
538+
continue;
539+
}
540+
541+
ret = flb_start(ctx->flb);
542+
TEST_CHECK(ret == 0);
543+
if (ret != 0) {
544+
TEST_MSG("flb_start failed for db.sync=%s", sync_values[i]);
545+
}
546+
547+
flb_stop(ctx->flb);
548+
flb_destroy(ctx->flb);
549+
flb_free(ctx);
550+
}
551+
}
552+
553+
/* Test valid db.journal_mode values */
554+
void flb_test_config_db_journal_mode_values()
555+
{
556+
struct flb_lib_out_cb cb_data;
557+
struct test_ctx *ctx;
558+
int ret;
559+
const char *journal_modes[] = {"DELETE", "TRUNCATE", "PERSIST", "MEMORY", "WAL", "OFF", NULL};
560+
int i;
561+
562+
cb_data.cb = NULL;
563+
cb_data.data = NULL;
564+
565+
for (i = 0; journal_modes[i] != NULL; i++) {
566+
ctx = test_ctx_create_with_config(&cb_data,
567+
NULL, /* db.sync */
568+
NULL, /* db.locking */
569+
journal_modes[i]); /* db.journal_mode */
570+
if (!TEST_CHECK(ctx != NULL)) {
571+
TEST_MSG("test_ctx_create_with_config failed for db.journal_mode=%s", journal_modes[i]);
572+
continue;
573+
}
574+
575+
ret = flb_start(ctx->flb);
576+
TEST_CHECK(ret == 0);
577+
if (ret != 0) {
578+
TEST_MSG("flb_start failed for db.journal_mode=%s", journal_modes[i]);
579+
}
580+
581+
flb_stop(ctx->flb);
582+
flb_destroy(ctx->flb);
583+
flb_free(ctx);
584+
}
585+
}
586+
587+
/* Test valid db.locking values */
588+
void flb_test_config_db_locking_values()
589+
{
590+
struct flb_lib_out_cb cb_data;
591+
struct test_ctx *ctx;
592+
int ret;
593+
const char *locking_values[] = {"true", "false", NULL};
594+
int i;
595+
596+
cb_data.cb = NULL;
597+
cb_data.data = NULL;
598+
599+
for (i = 0; locking_values[i] != NULL; i++) {
600+
ctx = test_ctx_create_with_config(&cb_data,
601+
NULL, /* db.sync */
602+
locking_values[i], /* db.locking */
603+
NULL); /* db.journal_mode */
604+
if (!TEST_CHECK(ctx != NULL)) {
605+
TEST_MSG("test_ctx_create_with_config failed for db.locking=%s", locking_values[i]);
606+
continue;
607+
}
608+
609+
ret = flb_start(ctx->flb);
610+
TEST_CHECK(ret == 0);
611+
if (ret != 0) {
612+
TEST_MSG("flb_start failed for db.locking=%s", locking_values[i]);
613+
}
614+
615+
flb_stop(ctx->flb);
616+
flb_destroy(ctx->flb);
617+
flb_free(ctx);
618+
}
619+
}
620+
#endif
621+
447622
TEST_LIST = {
448623
{"events_v1_with_lastTimestamp", flb_test_events_v1_with_lastTimestamp},
449624
{"events_v1_with_creationTimestamp", flb_test_events_v1_with_creationTimestamp},
450625
//{"events_v1_with_chunkedrecv", flb_test_events_with_chunkedrecv},
626+
#ifdef FLB_HAVE_SQLDB
627+
{"config_db_sync_values", flb_test_config_db_sync_values},
628+
{"config_db_journal_mode_values", flb_test_config_db_journal_mode_values},
629+
{"config_db_locking_values", flb_test_config_db_locking_values},
630+
#endif
451631
{NULL, NULL}
452632
};
453633

0 commit comments

Comments
 (0)