X-Git-Url: https://git.tokkee.org/?p=sysdb.git;a=blobdiff_plain;f=t%2Funit%2Fcore%2Fstore_json_test.c;h=b880f7b99a43c5bf9c5381491b9649d43bd53c5a;hp=d887c439f0bddbb4c21572402d27e9d490245d24;hb=3e4817902cb7285e5ab7a4f546861194f6e4ea1c;hpb=873627f033f749c6dc48293de1183ca4f6961926 diff --git a/t/unit/core/store_json_test.c b/t/unit/core/store_json_test.c index d887c43..b880f7b 100644 --- a/t/unit/core/store_json_test.c +++ b/t/unit/core/store_json_test.c @@ -29,7 +29,6 @@ # include "config.h" #endif -#include "core/plugin.h" #include "core/store.h" #include "testutils.h" @@ -103,16 +102,14 @@ scan_tojson(sdb_store_obj_t *obj, sdb_store_matcher_t __attribute__((unused)) *filter, void *user_data) { - sdb_store_json_formatter_t *f = user_data; - return sdb_store_json_emit(f, obj); + return sdb_store_emit(obj, &sdb_store_json_writer, user_data); } /* scan_tojson */ static int scan_tojson_full(sdb_store_obj_t *obj, sdb_store_matcher_t *filter, void *user_data) { - sdb_store_json_formatter_t *f = user_data; - return sdb_store_json_emit_full(f, obj, filter); + return sdb_store_emit_full(obj, filter, &sdb_store_json_writer, user_data); } /* scan_tojson_full */ static void @@ -173,9 +170,6 @@ struct { "\"last_update\": \"1970-01-01 00:00:02 +0000\", " "\"update_interval\": \"0s\", \"backends\": [], " "\"attributes\": [" - "{\"name\": \"hostname\", \"value\": \"h1\", " - "\"last_update\": \"1970-01-01 00:00:02 +0000\", " - "\"update_interval\": \"0s\", \"backends\": []}," "{\"name\": \"k3\", \"value\": 42, " "\"last_update\": \"1970-01-01 00:00:02 +0000\", " "\"update_interval\": \"0s\", \"backends\": []}" @@ -183,12 +177,7 @@ struct { "{\"name\": \"m2\", " "\"timeseries\": false, " "\"last_update\": \"1970-01-01 00:00:01 +0000\", " - "\"update_interval\": \"0s\", \"backends\": [], " - "\"attributes\": [" - "{\"name\": \"hostname\", \"value\": \"h1\", " - "\"last_update\": \"1970-01-01 00:00:01 +0000\", " - "\"update_interval\": \"0s\", \"backends\": []}" - "]}" + "\"update_interval\": \"0s\", \"backends\": []}" "]}," "{\"name\": \"h2\", \"last_update\": \"1970-01-01 00:00:03 +0000\", " "\"update_interval\": \"0s\", \"backends\": [], " @@ -196,29 +185,16 @@ struct { "{\"name\": \"m1\", " "\"timeseries\": false, " "\"last_update\": \"1970-01-01 00:00:01 +0000\", " - "\"update_interval\": \"0s\", \"backends\": [], " - "\"attributes\": [" - "{\"name\": \"hostname\", \"value\": \"h2\", " - "\"last_update\": \"1970-01-01 00:00:01 +0000\", " - "\"update_interval\": \"0s\", \"backends\": []}" - "]}" + "\"update_interval\": \"0s\", \"backends\": []}" "], " "\"services\": [" "{\"name\": \"s1\", " "\"last_update\": \"1970-01-01 00:00:01 +0000\", " - "\"update_interval\": \"0s\", \"backends\": [], " - "\"attributes\": [" - "{\"name\": \"hostname\", \"value\": \"h2\", " - "\"last_update\": \"1970-01-01 00:00:01 +0000\", " - "\"update_interval\": \"0s\", \"backends\": []}" - "]}," + "\"update_interval\": \"0s\", \"backends\": []}," "{\"name\": \"s2\", " "\"last_update\": \"1970-01-01 00:00:02 +0000\", " "\"update_interval\": \"0s\", \"backends\": [], " "\"attributes\": [" - "{\"name\": \"hostname\", \"value\": \"h2\", " - "\"last_update\": \"1970-01-01 00:00:02 +0000\", " - "\"update_interval\": \"0s\", \"backends\": []}," "{\"name\": \"k1\", \"value\": 123, " "\"last_update\": \"1970-01-01 00:00:02 +0000\", " "\"update_interval\": \"0s\", \"backends\": []}," @@ -254,9 +230,6 @@ struct { "\"last_update\": \"1970-01-01 00:00:02 +0000\", " "\"update_interval\": \"0s\", \"backends\": [], " "\"attributes\": [" - "{\"name\": \"hostname\", \"value\": \"h2\", " - "\"last_update\": \"1970-01-01 00:00:02 +0000\", " - "\"update_interval\": \"0s\", \"backends\": []}," "{\"name\": \"k1\", \"value\": 123, " "\"last_update\": \"1970-01-01 00:00:02 +0000\", " "\"update_interval\": \"0s\", \"backends\": []}" @@ -278,12 +251,7 @@ struct { "{\"name\": \"m2\", " "\"timeseries\": false, " "\"last_update\": \"1970-01-01 00:00:01 +0000\", " - "\"update_interval\": \"0s\", \"backends\": [], " - "\"attributes\": [" - "{\"name\": \"hostname\", \"value\": \"h1\", " - "\"last_update\": \"1970-01-01 00:00:01 +0000\", " - "\"update_interval\": \"0s\", \"backends\": []}" - "]}" + "\"update_interval\": \"0s\", \"backends\": []}" "]}" "]" }, { { sdb_store_ge_matcher, SDB_FIELD_LAST_UPDATE, @@ -301,65 +269,42 @@ struct { { { NULL, 0, SDB_DATA_INIT }, SDB_SERVICE, scan_tojson_full, "[" - "{\"name\": \"h2\", \"last_update\": \"1970-01-01 00:00:03 +0000\", " + "{\"name\": \"s1\", " + "\"last_update\": \"1970-01-01 00:00:01 +0000\", " + "\"update_interval\": \"0s\", \"backends\": []}," + "{\"name\": \"s2\", " + "\"last_update\": \"1970-01-01 00:00:02 +0000\", " "\"update_interval\": \"0s\", \"backends\": [], " - "\"services\": [" - "{\"name\": \"s1\", " - "\"last_update\": \"1970-01-01 00:00:01 +0000\", " - "\"update_interval\": \"0s\", \"backends\": [], " - "\"attributes\": [" - "{\"name\": \"hostname\", \"value\": \"h2\", " - "\"last_update\": \"1970-01-01 00:00:01 +0000\", " - "\"update_interval\": \"0s\", \"backends\": []}" - "]}," - "{\"name\": \"s2\", " + "\"attributes\": [" + "{\"name\": \"k1\", \"value\": 123, " "\"last_update\": \"1970-01-01 00:00:02 +0000\", " - "\"update_interval\": \"0s\", \"backends\": [], " - "\"attributes\": [" - "{\"name\": \"hostname\", \"value\": \"h2\", " - "\"last_update\": \"1970-01-01 00:00:02 +0000\", " - "\"update_interval\": \"0s\", \"backends\": []}," - "{\"name\": \"k1\", \"value\": 123, " - "\"last_update\": \"1970-01-01 00:00:02 +0000\", " - "\"update_interval\": \"0s\", \"backends\": []}," - "{\"name\": \"k2\", \"value\": 4711, " - "\"last_update\": \"1970-01-01 00:00:01 +0000\", " - "\"update_interval\": \"0s\", \"backends\": []}" - "]}" + "\"update_interval\": \"0s\", \"backends\": []}," + "{\"name\": \"k2\", \"value\": 4711, " + "\"last_update\": \"1970-01-01 00:00:01 +0000\", " + "\"update_interval\": \"0s\", \"backends\": []}" "]}" "]" }, { { NULL, 0, SDB_DATA_INIT }, SDB_SERVICE, scan_tojson, "[" - "{\"name\": \"h2\", \"last_update\": \"1970-01-01 00:00:03 +0000\", " - "\"update_interval\": \"0s\", \"backends\": [], " - "\"services\": [" - "{\"name\": \"s1\", " - "\"last_update\": \"1970-01-01 00:00:01 +0000\", " - "\"update_interval\": \"0s\", \"backends\": []}," - "{\"name\": \"s2\", " - "\"last_update\": \"1970-01-01 00:00:02 +0000\", " - "\"update_interval\": \"0s\", \"backends\": []}" - "]}" + "{\"name\": \"s1\", " + "\"last_update\": \"1970-01-01 00:00:01 +0000\", " + "\"update_interval\": \"0s\", \"backends\": []}," + "{\"name\": \"s2\", " + "\"last_update\": \"1970-01-01 00:00:02 +0000\", " + "\"update_interval\": \"0s\", \"backends\": []}" "]" }, { { sdb_store_gt_matcher, SDB_FIELD_LAST_UPDATE, { SDB_TYPE_DATETIME, { .datetime = 1 * SDB_INTERVAL_SECOND } } }, SDB_SERVICE, scan_tojson_full, "[" - "{\"name\": \"h2\", \"last_update\": \"1970-01-01 00:00:03 +0000\", " + "{\"name\": \"s2\", " + "\"last_update\": \"1970-01-01 00:00:02 +0000\", " "\"update_interval\": \"0s\", \"backends\": [], " - "\"services\": [" - "{\"name\": \"s2\", " + "\"attributes\": [" + "{\"name\": \"k1\", \"value\": 123, " "\"last_update\": \"1970-01-01 00:00:02 +0000\", " - "\"update_interval\": \"0s\", \"backends\": [], " - "\"attributes\": [" - "{\"name\": \"hostname\", \"value\": \"h2\", " - "\"last_update\": \"1970-01-01 00:00:02 +0000\", " - "\"update_interval\": \"0s\", \"backends\": []}," - "{\"name\": \"k1\", \"value\": 123, " - "\"last_update\": \"1970-01-01 00:00:02 +0000\", " - "\"update_interval\": \"0s\", \"backends\": []}" - "]}" + "\"update_interval\": \"0s\", \"backends\": []}" "]}" "]" }, { { sdb_store_lt_matcher, SDB_FIELD_LAST_UPDATE, @@ -369,86 +314,48 @@ struct { { { NULL, 0, SDB_DATA_INIT }, SDB_METRIC, scan_tojson_full, "[" - "{\"name\": \"h1\", \"last_update\": \"1970-01-01 00:00:01 +0000\", " + "{\"name\": \"m1\", " + "\"timeseries\": false, " + "\"last_update\": \"1970-01-01 00:00:02 +0000\", " "\"update_interval\": \"0s\", \"backends\": [], " - "\"metrics\": [" - "{\"name\": \"m1\", " - "\"timeseries\": false, " + "\"attributes\": [" + "{\"name\": \"k3\", \"value\": 42, " "\"last_update\": \"1970-01-01 00:00:02 +0000\", " - "\"update_interval\": \"0s\", \"backends\": [], " - "\"attributes\": [" - "{\"name\": \"hostname\", \"value\": \"h1\", " - "\"last_update\": \"1970-01-01 00:00:02 +0000\", " - "\"update_interval\": \"0s\", \"backends\": []}," - "{\"name\": \"k3\", \"value\": 42, " - "\"last_update\": \"1970-01-01 00:00:02 +0000\", " - "\"update_interval\": \"0s\", \"backends\": []}" - "]}," - "{\"name\": \"m2\", " - "\"timeseries\": false, " - "\"last_update\": \"1970-01-01 00:00:01 +0000\", " - "\"update_interval\": \"0s\", \"backends\": [], " - "\"attributes\": [" - "{\"name\": \"hostname\", \"value\": \"h1\", " - "\"last_update\": \"1970-01-01 00:00:01 +0000\", " - "\"update_interval\": \"0s\", \"backends\": []}" - "]}" + "\"update_interval\": \"0s\", \"backends\": []}" "]}," - "{\"name\": \"h2\", \"last_update\": \"1970-01-01 00:00:03 +0000\", " - "\"update_interval\": \"0s\", \"backends\": [], " - "\"metrics\": [" - "{\"name\": \"m1\", " - "\"timeseries\": false, " - "\"last_update\": \"1970-01-01 00:00:01 +0000\", " - "\"update_interval\": \"0s\", \"backends\": [], " - "\"attributes\": [" - "{\"name\": \"hostname\", \"value\": \"h2\", " - "\"last_update\": \"1970-01-01 00:00:01 +0000\", " - "\"update_interval\": \"0s\", \"backends\": []}" - "]}" - "]}" + "{\"name\": \"m2\", " + "\"timeseries\": false, " + "\"last_update\": \"1970-01-01 00:00:01 +0000\", " + "\"update_interval\": \"0s\", \"backends\": []}," + "{\"name\": \"m1\", " + "\"timeseries\": false, " + "\"last_update\": \"1970-01-01 00:00:01 +0000\", " + "\"update_interval\": \"0s\", \"backends\": []}" "]" }, { { NULL, 0, SDB_DATA_INIT }, SDB_METRIC, scan_tojson, "[" - "{\"name\": \"h1\", \"last_update\": \"1970-01-01 00:00:01 +0000\", " - "\"update_interval\": \"0s\", \"backends\": [], " - "\"metrics\": [" - "{\"name\": \"m1\", " - "\"timeseries\": false, " - "\"last_update\": \"1970-01-01 00:00:02 +0000\", " - "\"update_interval\": \"0s\", \"backends\": []}," - "{\"name\": \"m2\", " - "\"timeseries\": false, " - "\"last_update\": \"1970-01-01 00:00:01 +0000\", " - "\"update_interval\": \"0s\", \"backends\": []}" - "]}," - "{\"name\": \"h2\", \"last_update\": \"1970-01-01 00:00:03 +0000\", " - "\"update_interval\": \"0s\", \"backends\": [], " - "\"metrics\": [" - "{\"name\": \"m1\", " - "\"timeseries\": false, " - "\"last_update\": \"1970-01-01 00:00:01 +0000\", " - "\"update_interval\": \"0s\", \"backends\": []}" - "]}" + "{\"name\": \"m1\", " + "\"timeseries\": false, " + "\"last_update\": \"1970-01-01 00:00:02 +0000\", " + "\"update_interval\": \"0s\", \"backends\": []}," + "{\"name\": \"m2\", " + "\"timeseries\": false, " + "\"last_update\": \"1970-01-01 00:00:01 +0000\", " + "\"update_interval\": \"0s\", \"backends\": []}," + "{\"name\": \"m1\", " + "\"timeseries\": false, " + "\"last_update\": \"1970-01-01 00:00:01 +0000\", " + "\"update_interval\": \"0s\", \"backends\": []}" "]" }, { { sdb_store_le_matcher, SDB_FIELD_LAST_UPDATE, { SDB_TYPE_DATETIME, { .datetime = 1 * SDB_INTERVAL_SECOND } } }, SDB_METRIC, scan_tojson_full, "[" - "{\"name\": \"h1\", \"last_update\": \"1970-01-01 00:00:01 +0000\", " - "\"update_interval\": \"0s\", \"backends\": [], " - "\"metrics\": [" - "{\"name\": \"m2\", " - "\"timeseries\": false, " - "\"last_update\": \"1970-01-01 00:00:01 +0000\", " - "\"update_interval\": \"0s\", \"backends\": [], " - "\"attributes\": [" - "{\"name\": \"hostname\", \"value\": \"h1\", " - "\"last_update\": \"1970-01-01 00:00:01 +0000\", " - "\"update_interval\": \"0s\", \"backends\": []}" - "]}" - "]}" + "{\"name\": \"m2\", " + "\"timeseries\": false, " + "\"last_update\": \"1970-01-01 00:00:01 +0000\", " + "\"update_interval\": \"0s\", \"backends\": []}" "]" }, { { sdb_store_lt_matcher, SDB_FIELD_LAST_UPDATE, { SDB_TYPE_DATETIME, { .datetime = 0 } } }, @@ -483,8 +390,7 @@ START_TEST(test_store_tojson) } sdb_strbuf_clear(buf); - f = sdb_store_json_formatter(buf, - store_tojson_data[_i].type, SDB_WANT_ARRAY); + f = sdb_store_json_formatter(buf, store_tojson_data[_i].type, SDB_WANT_ARRAY); ck_assert(f != NULL); status = sdb_store_scan(store, store_tojson_data[_i].type,