From 6ec10b9f4183c88895b6f8c47ebcc6a06ffa939a Mon Sep 17 00:00:00 2001 From: Hiroshi Hatake Date: Fri, 1 Nov 2024 20:19:04 +0900 Subject: [PATCH] cfl_record_accessor: test: internal: Add internal test cases for generic CFL based RA Signed-off-by: Hiroshi Hatake --- tests/internal/CMakeLists.txt | 1 + tests/internal/cfl_record_accessor.c | 293 +++++++++++++-------------- tests/internal/record_accessor.c | 2 +- 3 files changed, 141 insertions(+), 155 deletions(-) diff --git a/tests/internal/CMakeLists.txt b/tests/internal/CMakeLists.txt index 99fc600e15a..c8225739b8c 100644 --- a/tests/internal/CMakeLists.txt +++ b/tests/internal/CMakeLists.txt @@ -87,6 +87,7 @@ if(FLB_RECORD_ACCESSOR) set(UNIT_TESTS_FILES ${UNIT_TESTS_FILES} record_accessor.c + cfl_record_accessor.c ) endif() diff --git a/tests/internal/cfl_record_accessor.c b/tests/internal/cfl_record_accessor.c index 02887c80769..43498d391aa 100644 --- a/tests/internal/cfl_record_accessor.c +++ b/tests/internal/cfl_record_accessor.c @@ -87,7 +87,7 @@ void cb_keys() void cb_dash_key() { struct cfl_kvlist *kvlist = NULL; - struct cfl_object *cobj = NULL; + struct cfl_variant *vobj = NULL; char *fmt; char *fmt_out; flb_sds_t str; @@ -98,16 +98,15 @@ void cb_dash_key() if (kvlist == NULL) { exit(EXIT_FAILURE); } - cobj = cfl_object_create(); - if (cobj == NULL) { - exit(EXIT_FAILURE); - } /* kvlist: "{\"key-dash\" => \"something\"}" */ cfl_kvlist_insert_string(kvlist, "key-dash", "something"); - /* Set up CFL object(cobj) */ - cfl_object_set(cobj, CFL_OBJECT_KVLIST, kvlist); + /* Set up CFL variant(vobj) */ + vobj = cfl_variant_create_from_kvlist(kvlist); + if (vobj == NULL) { + exit(EXIT_FAILURE); + } /* Formatter */ fmt = flb_sds_create("$key-dash"); @@ -120,7 +119,7 @@ void cb_dash_key() } /* Do translation */ - str = flb_cfl_ra_translate(cra, NULL, -1, *cobj, NULL); + str = flb_cfl_ra_translate(cra, NULL, -1, *vobj, NULL); TEST_CHECK(str != NULL); if (!str) { exit(EXIT_FAILURE); @@ -132,7 +131,7 @@ void cb_dash_key() flb_sds_destroy(str); flb_sds_destroy(fmt); - cfl_object_destroy(cobj); + cfl_variant_destroy(vobj); flb_cfl_ra_destroy(cra); } @@ -145,7 +144,7 @@ void cb_translate() struct cfl_kvlist *kvlist = NULL; struct cfl_kvlist *nested = NULL; struct cfl_kvlist *inner = NULL; - struct cfl_object *cobj = NULL; + struct cfl_variant *vobj = NULL; /* Sample kvlist */ kvlist = cfl_kvlist_create(); @@ -160,10 +159,6 @@ void cb_translate() if (nested == NULL) { exit(EXIT_FAILURE); } - cobj = cfl_object_create(); - if (cobj == NULL) { - exit(EXIT_FAILURE); - } /* /\* Sample message structure *\/ */ /* "{\"k1\": \"string\", \"k2\": true, \"k3\": false," \ */ @@ -178,8 +173,11 @@ void cb_translate() cfl_kvlist_insert_kvlist(inner, "s1", nested); cfl_kvlist_insert_kvlist(kvlist, "k6", inner); - /* Set up CFL object(cobj) */ - cfl_object_set(cobj, CFL_OBJECT_KVLIST, kvlist); + /* Set up CFL variant(vobj) */ + vobj = cfl_variant_create_from_kvlist(kvlist); + if (vobj == NULL) { + exit(EXIT_FAILURE); + } /* Set environment variables */ putenv("FLB_ENV=translated"); @@ -203,7 +201,7 @@ void cb_translate() } /* Do translation */ - str = flb_cfl_ra_translate(cra, NULL, -1, *cobj, NULL); + str = flb_cfl_ra_translate(cra, NULL, -1, *vobj, NULL); TEST_CHECK(str != NULL); if (!str) { goto error; @@ -215,7 +213,7 @@ void cb_translate() error: flb_sds_destroy(str); - cfl_object_destroy(cobj); + cfl_variant_destroy(vobj); flb_cfl_ra_destroy(cra); } @@ -227,7 +225,7 @@ void cb_translate_tag() struct cfl_kvlist *kvlist = NULL; struct cfl_kvlist *nested = NULL; struct cfl_kvlist *inner = NULL; - struct cfl_object *cobj = NULL; + struct cfl_variant *vobj = NULL; /* Sample kvlist */ kvlist = cfl_kvlist_create(); @@ -242,10 +240,6 @@ void cb_translate_tag() if (nested == NULL) { exit(EXIT_FAILURE); } - cobj = cfl_object_create(); - if (cobj == NULL) { - exit(EXIT_FAILURE); - } /* /\* Sample message structure *\/ */ /* "{\"k1\": \"string\", \"k2\": true, \"k3\": false," \ */ @@ -260,8 +254,11 @@ void cb_translate_tag() cfl_kvlist_insert_kvlist(inner, "s1", nested); cfl_kvlist_insert_kvlist(kvlist, "k6", inner); - /* Set up CFL object(cobj) */ - cfl_object_set(cobj, CFL_OBJECT_KVLIST, kvlist); + /* Set up CFL variant(vobj) */ + vobj = cfl_variant_create_from_kvlist(kvlist); + if (vobj == NULL) { + exit(EXIT_FAILURE); + } fmt = "$TAG"; cra = flb_cfl_ra_create(fmt, FLB_TRUE); @@ -271,7 +268,7 @@ void cb_translate_tag() } /* Do translation */ - str = flb_cfl_ra_translate(cra, "testapp", 7, *cobj, NULL); + str = flb_cfl_ra_translate(cra, "testapp", 7, *vobj, NULL); TEST_CHECK(str != NULL); if (!str) { exit(EXIT_FAILURE); @@ -279,7 +276,7 @@ void cb_translate_tag() TEST_CHECK(flb_sds_len(str) == 7); flb_sds_destroy(str); - cfl_object_destroy(cobj); + cfl_variant_destroy(vobj); flb_cfl_ra_destroy(cra); } @@ -292,7 +289,7 @@ void cb_dots_subkeys() struct cfl_kvlist *kvlist = NULL; struct cfl_kvlist *nested = NULL; struct cfl_kvlist *inner = NULL; - struct cfl_object *cobj = NULL; + struct cfl_variant *vobj = NULL; /* Sample kvlist */ kvlist = cfl_kvlist_create(); @@ -307,10 +304,6 @@ void cb_dots_subkeys() if (nested == NULL) { exit(EXIT_FAILURE); } - cobj = cfl_object_create(); - if (cobj == NULL) { - exit(EXIT_FAILURE); - } /* /\* Sample message structure *\/ */ /* "{\"key1\": \"something\", \"kubernetes\": {\"annotations\": " */ @@ -320,8 +313,11 @@ void cb_dots_subkeys() cfl_kvlist_insert_kvlist(inner, "annotations", nested); cfl_kvlist_insert_kvlist(kvlist, "kubernetes", inner); - /* Set up CFL object(cobj) */ - cfl_object_set(cobj, CFL_OBJECT_KVLIST, kvlist); + /* Set up CFL variant(vobj) */ + vobj = cfl_variant_create_from_kvlist(kvlist); + if (vobj == NULL) { + exit(EXIT_FAILURE); + } /* Formatter */ fmt = flb_sds_create("$kubernetes['annotations']['fluentbit.io/tag']"); @@ -334,7 +330,7 @@ void cb_dots_subkeys() } /* Do translation */ - str = flb_cfl_ra_translate(cra, NULL, -1, *cobj, NULL); + str = flb_cfl_ra_translate(cra, NULL, -1, *vobj, NULL); TEST_CHECK(str != NULL); if (!str) { exit(EXIT_FAILURE); @@ -346,7 +342,7 @@ void cb_dots_subkeys() flb_sds_destroy(str); flb_sds_destroy(fmt); - cfl_object_destroy(cobj); + cfl_variant_destroy(vobj); flb_cfl_ra_destroy(cra); } @@ -360,7 +356,7 @@ void cb_array_id() struct cfl_kvlist *nested = NULL; struct cfl_kvlist *inner = NULL; struct cfl_array *array = NULL; - struct cfl_object *cobj = NULL; + struct cfl_variant *vobj = NULL; /* Sample kvlist */ kvlist = cfl_kvlist_create(); @@ -379,10 +375,6 @@ void cb_array_id() if (array == NULL) { exit(EXIT_FAILURE); } - cobj = cfl_object_create(); - if (cobj == NULL) { - exit(EXIT_FAILURE); - } /* /\* Sample message structure *\/ */ /* "{\"key1\": \"something\", " */ @@ -402,8 +394,11 @@ void cb_array_id() cfl_array_append_kvlist(array, inner); cfl_kvlist_insert_array(kvlist, "kubernetes", array); - /* Set up CFL object(cobj) */ - cfl_object_set(cobj, CFL_OBJECT_KVLIST, kvlist); + /* Set up CFL variant(vobj) */ + vobj = cfl_variant_create_from_kvlist(kvlist); + if (vobj == NULL) { + exit(EXIT_FAILURE); + } /* Formatter */ fmt = flb_sds_create("$kubernetes[2]['annotations']['fluentbit.io/tag']"); @@ -416,7 +411,7 @@ void cb_array_id() } /* Do translation */ - str = flb_cfl_ra_translate(cra, NULL, -1, *cobj, NULL); + str = flb_cfl_ra_translate(cra, NULL, -1, *vobj, NULL); TEST_CHECK(str != NULL); if (!str) { exit(EXIT_FAILURE); @@ -428,7 +423,7 @@ void cb_array_id() flb_sds_destroy(str); flb_sds_destroy(fmt); - cfl_object_destroy(cobj); + cfl_variant_destroy(vobj); flb_cfl_ra_destroy(cra); } @@ -442,7 +437,7 @@ void cb_get_kv_pair() struct cfl_kvlist *nested = NULL; struct cfl_kvlist *inner = NULL; struct cfl_array *array = NULL; - struct cfl_object *cobj = NULL; + struct cfl_variant *vobj = NULL; cfl_sds_t start_key; cfl_sds_t out_key; struct cfl_variant *out_val; @@ -464,10 +459,6 @@ void cb_get_kv_pair() if (array == NULL) { exit(EXIT_FAILURE); } - cobj = cfl_object_create(); - if (cobj == NULL) { - exit(EXIT_FAILURE); - } /* /\* Sample message structure *\/ */ /* "{\"key1\": \"something\", " */ @@ -487,8 +478,11 @@ void cb_get_kv_pair() cfl_array_append_kvlist(array, inner); cfl_kvlist_insert_array(kvlist, "kubernetes", array); - /* Set up CFL object(cobj) */ - cfl_object_set(cobj, CFL_OBJECT_KVLIST, kvlist); + /* Set up CFL variant(vobj) */ + vobj = cfl_variant_create_from_kvlist(kvlist); + if (vobj == NULL) { + exit(EXIT_FAILURE); + } /* Formatter */ fmt = flb_sds_create("$kubernetes[2]['annotations']['fluentbit.io/tag']"); @@ -501,7 +495,7 @@ void cb_get_kv_pair() } /* Do translation */ - ret = flb_cfl_ra_get_kv_pair(cra, *cobj, &start_key, &out_key, &out_val); + ret = flb_cfl_ra_get_kv_pair(cra, *vobj, &start_key, &out_key, &out_val); TEST_CHECK(ret == 0); if (ret != 0) { exit(EXIT_FAILURE); @@ -512,11 +506,11 @@ void cb_get_kv_pair() TEST_CHECK(memcmp(out_val->data.as_string, fmt_out, strlen(fmt_out)) == 0); flb_sds_destroy(fmt); - cfl_object_destroy(cobj); + cfl_variant_destroy(vobj); flb_cfl_ra_destroy(cra); } -static int order_lookup_check(struct cfl_object *cobj, +static int order_lookup_check(struct cfl_variant *vobj, char *fmt, char *expected_out) { char *fmt_out; @@ -537,7 +531,7 @@ static int order_lookup_check(struct cfl_object *cobj, } /* Do translation */ - str = flb_cfl_ra_translate(cra, NULL, -1, *cobj, NULL); + str = flb_cfl_ra_translate(cra, NULL, -1, *vobj, NULL); TEST_CHECK(str != NULL); if (!str) { exit(EXIT_FAILURE); @@ -560,17 +554,13 @@ static int order_lookup_check(struct cfl_object *cobj, void cb_key_order_lookup() { struct cfl_kvlist *kvlist = NULL; - struct cfl_object *cobj = NULL; + struct cfl_variant *vobj = NULL; /* Sample kvlist */ kvlist = cfl_kvlist_create(); if (kvlist == NULL) { exit(EXIT_FAILURE); } - cobj = cfl_object_create(); - if (cobj == NULL) { - exit(EXIT_FAILURE); - } /* Sample cfl_object structure */ /* "{\"key\": \"abc\", \"bool\": false, \"bool\": true, " */ @@ -584,18 +574,21 @@ void cb_key_order_lookup() cfl_kvlist_insert_int64(kvlist, "num", 0); cfl_kvlist_insert_int64(kvlist, "num", 1); - /* Set up CFL object(cobj) */ - cfl_object_set(cobj, CFL_OBJECT_KVLIST, kvlist); + /* Set up CFL variant(vobj) */ + vobj = cfl_variant_create_from_kvlist(kvlist); + if (vobj == NULL) { + exit(EXIT_FAILURE); + } printf("\n-- record --\n"); - cfl_object_print(stdout, cobj); + cfl_variant_print(stdout, vobj); /* check expected outputs per record accessor pattern */ - order_lookup_check(cobj, "$bool", "true"); - order_lookup_check(cobj, "$str" , "second"); - order_lookup_check(cobj, "$num" , "1"); + order_lookup_check(vobj, "$bool", "true"); + order_lookup_check(vobj, "$str" , "second"); + order_lookup_check(vobj, "$num" , "1"); - cfl_object_destroy(cobj); + cfl_variant_destroy(vobj); } void cb_update_key_val() @@ -605,7 +598,7 @@ void cb_update_key_val() struct cfl_kvlist *nested = NULL; struct cfl_kvlist *inner = NULL; struct cfl_array *array = NULL; - struct cfl_object *cobj = NULL; + struct cfl_variant *vobj = NULL; flb_sds_t fmt = NULL; flb_sds_t updated_fmt = NULL; @@ -639,10 +632,6 @@ void cb_update_key_val() if (array == NULL) { exit(EXIT_FAILURE); } - cobj = cfl_object_create(); - if (cobj == NULL) { - exit(EXIT_FAILURE); - } /* create key object to overwrite */ in_key = cfl_sds_create("updated_key"); @@ -670,8 +659,11 @@ void cb_update_key_val() cfl_array_append_kvlist(array, inner); cfl_kvlist_insert_array(kvlist, "kubernetes", array); - /* Set up CFL object(cobj) */ - cfl_object_set(cobj, CFL_OBJECT_KVLIST, kvlist); + /* Set up CFL variant(vobj) */ + vobj = cfl_variant_create_from_kvlist(kvlist); + if (vobj == NULL) { + exit(EXIT_FAILURE); + } /* Formatter */ fmt = flb_sds_create("$kubernetes[2]['annotations']['fluentbit.io/tag']"); @@ -688,13 +680,13 @@ void cb_update_key_val() } /* Update only value */ - ret = flb_cfl_ra_update_kv_pair(cra, *cobj, in_key, in_val); + ret = flb_cfl_ra_update_kv_pair(cra, *vobj, in_key, in_val); TEST_CHECK(ret == 0); - ret = flb_cfl_ra_get_kv_pair(updated_cra, *cobj, &start_key, &out_key, &out_val); + ret = flb_cfl_ra_get_kv_pair(updated_cra, *vobj, &start_key, &out_key, &out_val); if (!TEST_CHECK(ret == 0)) { printf("print out_result\n"); - cfl_object_print(stdout, cobj); + cfl_variant_print(stdout, vobj); exit(EXIT_FAILURE); } @@ -711,7 +703,7 @@ void cb_update_key_val() flb_sds_destroy(fmt); flb_cfl_ra_destroy(updated_cra); flb_cfl_ra_destroy(cra); - cfl_object_destroy(cobj); + cfl_variant_destroy(vobj); cfl_sds_destroy(in_key); } @@ -722,7 +714,7 @@ void cb_update_val() struct cfl_kvlist *nested = NULL; struct cfl_kvlist *inner = NULL; struct cfl_array *array = NULL; - struct cfl_object *cobj = NULL; + struct cfl_variant *vobj = NULL; flb_sds_t fmt = NULL; flb_sds_t updated_fmt = NULL; @@ -753,10 +745,6 @@ void cb_update_val() if (array == NULL) { exit(EXIT_FAILURE); } - cobj = cfl_object_create(); - if (cobj == NULL) { - exit(EXIT_FAILURE); - } /* create value object to overwrite */ in_val = cfl_variant_create_from_string("updated_val"); @@ -782,8 +770,11 @@ void cb_update_val() cfl_array_append_kvlist(array, inner); cfl_kvlist_insert_array(kvlist, "kubernetes", array); - /* Set up CFL object(cobj) */ - cfl_object_set(cobj, CFL_OBJECT_KVLIST, kvlist); + /* Set up CFL variant(vobj) */ + vobj = cfl_variant_create_from_kvlist(kvlist); + if (vobj == NULL) { + exit(EXIT_FAILURE); + } /* Formatter */ fmt = flb_sds_create("$kubernetes[2]['annotations']['fluentbit.io/tag']"); @@ -793,13 +784,13 @@ void cb_update_val() } /* Update only value */ - ret = flb_cfl_ra_update_kv_pair(cra, *cobj, NULL, in_val); + ret = flb_cfl_ra_update_kv_pair(cra, *vobj, NULL, in_val); TEST_CHECK(ret == 0); - ret = flb_cfl_ra_get_kv_pair(cra, *cobj, &start_key, &out_key, &out_val); + ret = flb_cfl_ra_get_kv_pair(cra, *vobj, &start_key, &out_key, &out_val); if (!TEST_CHECK(ret == 0)) { printf("print out_result\n"); - cfl_object_print(stdout, cobj); + cfl_variant_print(stdout, vobj); exit(EXIT_FAILURE); } @@ -811,7 +802,7 @@ void cb_update_val() flb_sds_destroy(updated_fmt); flb_sds_destroy(fmt); flb_cfl_ra_destroy(cra); - cfl_object_destroy(cobj); + cfl_variant_destroy(vobj); } void cb_update_key() @@ -821,7 +812,7 @@ void cb_update_key() struct cfl_kvlist *nested = NULL; struct cfl_kvlist *inner = NULL; struct cfl_array *array = NULL; - struct cfl_object *cobj = NULL; + struct cfl_variant *vobj = NULL; flb_sds_t fmt = NULL; flb_sds_t updated_fmt = NULL; @@ -853,10 +844,6 @@ void cb_update_key() if (array == NULL) { exit(EXIT_FAILURE); } - cobj = cfl_object_create(); - if (cobj == NULL) { - exit(EXIT_FAILURE); - } /* create key object to overwrite */ in_key = cfl_sds_create("updated_key"); @@ -879,8 +866,11 @@ void cb_update_key() cfl_array_append_kvlist(array, inner); cfl_kvlist_insert_array(kvlist, "kubernetes", array); - /* Set up CFL object(cobj) */ - cfl_object_set(cobj, CFL_OBJECT_KVLIST, kvlist); + /* Set up CFL variant(vobj) */ + vobj = cfl_variant_create_from_kvlist(kvlist); + if (vobj == NULL) { + exit(EXIT_FAILURE); + } /* Formatter */ fmt = flb_sds_create("$kubernetes[2]['annotations']['fluentbit.io/tag']"); @@ -897,13 +887,13 @@ void cb_update_key() } /* Update only value */ - ret = flb_cfl_ra_update_kv_pair(cra, *cobj, in_key, NULL); + ret = flb_cfl_ra_update_kv_pair(cra, *vobj, in_key, NULL); TEST_CHECK(ret == 0); - ret = flb_cfl_ra_get_kv_pair(updated_cra, *cobj, &start_key, &out_key, &out_val); + ret = flb_cfl_ra_get_kv_pair(updated_cra, *vobj, &start_key, &out_key, &out_val); if (!TEST_CHECK(ret == 0)) { printf("print out_result\n"); - cfl_object_print(stdout, cobj); + cfl_variant_print(stdout, vobj); goto error; } @@ -916,7 +906,7 @@ void cb_update_key() flb_sds_destroy(fmt); flb_cfl_ra_destroy(cra); flb_cfl_ra_destroy(updated_cra); - cfl_object_destroy(cobj); + cfl_variant_destroy(vobj); cfl_sds_destroy(in_key); } @@ -927,7 +917,7 @@ void cb_update_root_key() struct cfl_kvlist *nested = NULL; struct cfl_kvlist *inner = NULL; struct cfl_array *array = NULL; - struct cfl_object *cobj = NULL; + struct cfl_variant *vobj = NULL; flb_sds_t fmt = NULL; flb_sds_t updated_fmt = NULL; @@ -960,10 +950,6 @@ void cb_update_root_key() if (array == NULL) { exit(EXIT_FAILURE); } - cobj = cfl_object_create(); - if (cobj == NULL) { - exit(EXIT_FAILURE); - } /* create key object to overwrite */ in_key = flb_sds_create("updated_key"); @@ -986,8 +972,11 @@ void cb_update_root_key() cfl_array_append_kvlist(array, inner); cfl_kvlist_insert_array(kvlist, "kubernetes", array); - /* Set up CFL object(cobj) */ - cfl_object_set(cobj, CFL_OBJECT_KVLIST, kvlist); + /* Set up CFL variant(vobj) */ + vobj = cfl_variant_create_from_kvlist(kvlist); + if (vobj == NULL) { + exit(EXIT_FAILURE); + } /* Formatter */ fmt = flb_sds_create("$key1"); @@ -1004,13 +993,13 @@ void cb_update_root_key() } /* Update only value */ - ret = flb_cfl_ra_update_kv_pair(cra, *cobj, in_key, in_val); + ret = flb_cfl_ra_update_kv_pair(cra, *vobj, in_key, in_val); TEST_CHECK(ret == 0); - ret = flb_cfl_ra_get_kv_pair(updated_cra, *cobj, &start_key, &out_key, &out_val); + ret = flb_cfl_ra_get_kv_pair(updated_cra, *vobj, &start_key, &out_key, &out_val); if (!TEST_CHECK(ret == 0)) { printf("print out_result\n"); - cfl_object_print(stdout, cobj); + cfl_variant_print(stdout, vobj); exit(EXIT_FAILURE); } @@ -1022,7 +1011,7 @@ void cb_update_root_key() flb_sds_destroy(fmt); flb_cfl_ra_destroy(updated_cra); flb_cfl_ra_destroy(cra); - cfl_object_destroy(cobj); + cfl_variant_destroy(vobj); cfl_sds_destroy(in_key); } @@ -1033,7 +1022,7 @@ void cb_update_root_key_val() struct cfl_kvlist *nested = NULL; struct cfl_kvlist *inner = NULL; struct cfl_array *array = NULL; - struct cfl_object *cobj = NULL; + struct cfl_variant *vobj = NULL; flb_sds_t fmt = NULL; flb_sds_t updated_fmt = NULL; @@ -1067,10 +1056,6 @@ void cb_update_root_key_val() if (array == NULL) { exit(EXIT_FAILURE); } - cobj = cfl_object_create(); - if (cobj == NULL) { - exit(EXIT_FAILURE); - } /* create key object to overwrite */ in_key = flb_sds_create("updated_key"); @@ -1098,8 +1083,11 @@ void cb_update_root_key_val() cfl_array_append_kvlist(array, inner); cfl_kvlist_insert_array(kvlist, "kubernetes", array); - /* Set up CFL object(cobj) */ - cfl_object_set(cobj, CFL_OBJECT_KVLIST, kvlist); + /* Set up CFL variant(vobj) */ + vobj = cfl_variant_create_from_kvlist(kvlist); + if (vobj == NULL) { + exit(EXIT_FAILURE); + } /* Formatter */ fmt = flb_sds_create("$key1"); @@ -1116,13 +1104,13 @@ void cb_update_root_key_val() } /* Update only value */ - ret = flb_cfl_ra_update_kv_pair(cra, *cobj, in_key, in_val); + ret = flb_cfl_ra_update_kv_pair(cra, *vobj, in_key, in_val); TEST_CHECK(ret == 0); - ret = flb_cfl_ra_get_kv_pair(updated_cra, *cobj, &start_key, &out_key, &out_val); + ret = flb_cfl_ra_get_kv_pair(updated_cra, *vobj, &start_key, &out_key, &out_val); if (!TEST_CHECK(ret == 0)) { printf("print out_result\n"); - cfl_object_print(stdout, cobj); + cfl_variant_print(stdout, vobj); exit(EXIT_FAILURE); } @@ -1139,7 +1127,7 @@ void cb_update_root_key_val() flb_sds_destroy(fmt); flb_cfl_ra_destroy(updated_cra); flb_cfl_ra_destroy(cra); - cfl_object_destroy(cobj); + cfl_variant_destroy(vobj); cfl_sds_destroy(in_key); } @@ -1149,24 +1137,23 @@ void cb_ra_translate_check() flb_sds_t str; struct flb_cfl_record_accessor *cra; struct cfl_kvlist *kvlist = NULL; - struct cfl_object *cobj = NULL; + struct cfl_variant *vobj = NULL; /* Sample kvlist */ kvlist = cfl_kvlist_create(); if (kvlist == NULL) { exit(EXIT_FAILURE); } - cobj = cfl_object_create(); - if (cobj == NULL) { - exit(EXIT_FAILURE); - } /* /\* Sample message structure *\/ */ /* "{\"root.with/symbols\": \"something\"}"; */ cfl_kvlist_insert_string(kvlist, "root.with/symbols", "something"); - /* Set up CFL object(cobj) */ - cfl_object_set(cobj, CFL_OBJECT_KVLIST, kvlist); + /* Set up CFL variant(vobj) */ + vobj = cfl_variant_create_from_kvlist(kvlist); + if (vobj == NULL) { + exit(EXIT_FAILURE); + } int check_translation = FLB_TRUE; @@ -1183,7 +1170,7 @@ void cb_ra_translate_check() } /* Do translation - with check enabled */ - str = flb_cfl_ra_translate_check(cra, NULL, -1, *cobj, NULL, check_translation); + str = flb_cfl_ra_translate_check(cra, NULL, -1, *vobj, NULL, check_translation); /* since translation fails and check is enabled, it returns NULL */ TEST_CHECK(str == NULL); if (str) { @@ -1193,7 +1180,7 @@ void cb_ra_translate_check() flb_sds_destroy(str); flb_sds_destroy(fmt); flb_cfl_ra_destroy(cra); - cfl_object_destroy(cobj); + cfl_variant_destroy(vobj); } struct char_list_cobj_ra_str{ @@ -1273,7 +1260,7 @@ void cb_add_key_val() struct cfl_kvlist *nested = NULL; struct cfl_kvlist *inner = NULL; struct cfl_array *array = NULL; - struct cfl_object *cobj = NULL; + struct cfl_variant *vobj = NULL; flb_sds_t fmt = NULL; flb_sds_t updated_fmt = NULL; @@ -1306,10 +1293,6 @@ void cb_add_key_val() if (array == NULL) { exit(EXIT_FAILURE); } - cobj = cfl_object_create(); - if (cobj == NULL) { - exit(EXIT_FAILURE); - } /* create value object to overwrite */ in_val = cfl_variant_create_from_string("add_val"); @@ -1335,8 +1318,11 @@ void cb_add_key_val() cfl_array_append_kvlist(array, inner); cfl_kvlist_insert_array(kvlist, "kubernetes", array); - /* Set up CFL object(cobj) */ - cfl_object_set(cobj, CFL_OBJECT_KVLIST, kvlist); + /* Set up CFL variant(vobj) */ + vobj = cfl_variant_create_from_kvlist(kvlist); + if (vobj == NULL) { + exit(EXIT_FAILURE); + } /* Formatter */ fmt = flb_sds_create("$kubernetes[2]['annotations']['add_key']"); @@ -1353,13 +1339,13 @@ void cb_add_key_val() } /* Add key/value */ - ret = flb_cfl_ra_append_kv_pair(cra, *cobj, in_val); + ret = flb_cfl_ra_append_kv_pair(cra, *vobj, in_val); TEST_CHECK(ret == 0); - ret = flb_cfl_ra_get_kv_pair(updated_cra, *cobj, &start_key, &out_key, &out_val); + ret = flb_cfl_ra_get_kv_pair(updated_cra, *vobj, &start_key, &out_key, &out_val); if (!TEST_CHECK(ret == 0)) { printf("print out_result\n"); - cfl_object_print(stdout, cobj); + cfl_variant_print(stdout, vobj); exit(EXIT_FAILURE); } @@ -1376,7 +1362,7 @@ void cb_add_key_val() flb_sds_destroy(fmt); flb_cfl_ra_destroy(updated_cra); flb_cfl_ra_destroy(cra); - cfl_object_destroy(cobj); + cfl_variant_destroy(vobj); } void cb_add_root_key_val() @@ -1386,7 +1372,7 @@ void cb_add_root_key_val() struct cfl_kvlist *nested = NULL; struct cfl_kvlist *inner = NULL; struct cfl_array *array = NULL; - struct cfl_object *cobj = NULL; + struct cfl_variant *vobj = NULL; flb_sds_t fmt = NULL; flb_sds_t updated_fmt = NULL; @@ -1419,10 +1405,6 @@ void cb_add_root_key_val() if (array == NULL) { exit(EXIT_FAILURE); } - cobj = cfl_object_create(); - if (cobj == NULL) { - exit(EXIT_FAILURE); - } /* create value object to overwrite */ in_val = cfl_variant_create_from_string("add_val"); @@ -1448,8 +1430,11 @@ void cb_add_root_key_val() cfl_array_append_kvlist(array, inner); cfl_kvlist_insert_array(kvlist, "kubernetes", array); - /* Set up CFL object(cobj) */ - cfl_object_set(cobj, CFL_OBJECT_KVLIST, kvlist); + /* Set up CFL variant(vobj) */ + vobj = cfl_variant_create_from_kvlist(kvlist); + if (vobj == NULL) { + exit(EXIT_FAILURE); + } /* Formatter */ fmt = flb_sds_create("$add_key"); @@ -1466,13 +1451,13 @@ void cb_add_root_key_val() } /* Add key/value */ - ret = flb_cfl_ra_append_kv_pair(cra, *cobj, in_val); + ret = flb_cfl_ra_append_kv_pair(cra, *vobj, in_val); TEST_CHECK(ret == 0); - ret = flb_cfl_ra_get_kv_pair(updated_cra, *cobj, &start_key, &out_key, &out_val); + ret = flb_cfl_ra_get_kv_pair(updated_cra, *vobj, &start_key, &out_key, &out_val); if (!TEST_CHECK(ret == 0)) { printf("print out_result\n"); - cfl_object_print(stdout, cobj); + cfl_variant_print(stdout, vobj); exit(EXIT_FAILURE); } @@ -1489,7 +1474,7 @@ void cb_add_root_key_val() flb_sds_destroy(fmt); flb_cfl_ra_destroy(updated_cra); flb_cfl_ra_destroy(cra); - cfl_object_destroy(cobj); + cfl_variant_destroy(vobj); } TEST_LIST = { diff --git a/tests/internal/record_accessor.c b/tests/internal/record_accessor.c index 5f62b846dc9..e5aa18a5ec9 100644 --- a/tests/internal/record_accessor.c +++ b/tests/internal/record_accessor.c @@ -742,7 +742,7 @@ void cb_update_key() flb_ra_destroy(ra); flb_free(out_buf); } - + void cb_dash_key() { int len;