X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=t%2Funit%2Fcore%2Fstore_test.c;h=00e3c64389d3843321bb2fcbb396f8174fb0ed68;hb=ff53c1c6b145e1a0315ee42d316a858f29f7d0a1;hp=e8c77c7b04dc0c649fdc7cb0a00985f2fd760354;hpb=dd74510898e5a480fc18a1acad7aa4196f732efe;p=sysdb.git diff --git a/t/unit/core/store_test.c b/t/unit/core/store_test.c index e8c77c7..00e3c64 100644 --- a/t/unit/core/store_test.c +++ b/t/unit/core/store_test.c @@ -450,7 +450,7 @@ START_TEST(test_store_tojson) const char *expected; } golden_data[] = { { { NULL, 0, SDB_DATA_INIT }, 0, - "{\"hosts\":[" + "[" "{\"name\": \"h1\", \"last_update\": \"1970-01-01 00:00:00 +0000\", " "\"update_interval\": \"0s\", \"backends\": [], " "\"attributes\": [" @@ -500,9 +500,9 @@ START_TEST(test_store_tojson) "\"update_interval\": \"0s\", \"backends\": []}" "]}" "]}" - "]}" }, + "]" }, { { NULL, 0, SDB_DATA_INIT }, SDB_SKIP_SERVICES, - "{\"hosts\":[" + "[" "{\"name\": \"h1\", \"last_update\": \"1970-01-01 00:00:00 +0000\", " "\"update_interval\": \"0s\", \"backends\": [], " "\"attributes\": [" @@ -534,9 +534,9 @@ START_TEST(test_store_tojson) "\"update_interval\": \"0s\", \"backends\": [], " "\"attributes\": [], " "\"metrics\": []}" - "]}" }, + "]" }, { { NULL, 0, SDB_DATA_INIT }, SDB_SKIP_METRICS, - "{\"hosts\":[" + "[" "{\"name\": \"h1\", \"last_update\": \"1970-01-01 00:00:00 +0000\", " "\"update_interval\": \"0s\", \"backends\": [], " "\"attributes\": [" @@ -571,9 +571,9 @@ START_TEST(test_store_tojson) "\"update_interval\": \"0s\", \"backends\": []}" "]}" "]}" - "]}" }, + "]" }, { { NULL, 0, SDB_DATA_INIT }, SDB_SKIP_ATTRIBUTES, - "{\"hosts\":[" + "[" "{\"name\": \"h1\", \"last_update\": \"1970-01-01 00:00:00 +0000\", " "\"update_interval\": \"0s\", \"backends\": [], " "\"metrics\": [" @@ -596,17 +596,24 @@ START_TEST(test_store_tojson) "\"last_update\": \"1970-01-01 00:00:00 +0000\", " "\"update_interval\": \"0s\", \"backends\": []}" "]}" - "]}" }, + "]" }, { { NULL, 0, SDB_DATA_INIT }, SDB_SKIP_ALL, - "{\"hosts\":[" + "[" "{\"name\": \"h1\", \"last_update\": \"1970-01-01 00:00:00 +0000\", " "\"update_interval\": \"0s\", \"backends\": []}," "{\"name\": \"h2\", \"last_update\": \"1970-01-01 00:00:00 +0000\", " "\"update_interval\": \"0s\", \"backends\": []}" - "]}" }, + "]" }, + { { sdb_store_eq_matcher, SDB_FIELD_NAME, + { SDB_TYPE_STRING, { .string = "h1" } } }, 0, + "[" + "{\"name\": \"h1\", \"last_update\": \"1970-01-01 00:00:00 +0000\", " + "\"update_interval\": \"0s\", \"backends\": [], " + "\"attributes\": [], \"metrics\": [], \"services\": []}" + "]" }, { { sdb_store_gt_matcher, SDB_FIELD_LAST_UPDATE, { SDB_TYPE_DATETIME, { .datetime = 1 } } }, 0, - "{\"hosts\":[" + "[" "{\"name\": \"h2\", \"last_update\": \"1970-01-01 00:00:00 +0000\", " "\"update_interval\": \"0s\", \"backends\": [], " "\"attributes\": [], " @@ -621,10 +628,10 @@ START_TEST(test_store_tojson) "\"update_interval\": \"0s\", \"backends\": []}," "]}" "]}" - "]}" }, + "]" }, { { sdb_store_le_matcher, SDB_FIELD_LAST_UPDATE, { SDB_TYPE_DATETIME, { .datetime = 1 } } }, 0, - "{\"hosts\":[" + "[" "{\"name\": \"h1\", \"last_update\": \"1970-01-01 00:00:00 +0000\", " "\"update_interval\": \"0s\", \"backends\": [], " "\"attributes\": [" @@ -639,16 +646,16 @@ START_TEST(test_store_tojson) "\"attributes\": []}" "], " "\"services\": []}" - "]}" }, + "]" }, { { sdb_store_ge_matcher, SDB_FIELD_LAST_UPDATE, { SDB_TYPE_DATETIME, { .datetime = 3 } } }, 0, - "{\"hosts\":[" + "[" "{\"name\": \"h2\", \"last_update\": \"1970-01-01 00:00:00 +0000\", " "\"update_interval\": \"0s\", \"backends\": [], " "\"attributes\": [], " "\"metrics\": [], " "\"services\": []}" - "]}" }, + "]" }, }; buf = sdb_strbuf_create(0); @@ -725,6 +732,17 @@ START_TEST(test_get_field) "sdb_store_get_field(NULL, SDB_FIELD_LAST_UPDATE, ) = %d; " "expected: <0"); + check = sdb_store_get_field(host, SDB_FIELD_NAME, &value); + fail_unless(check == 0, + "sdb_store_get_field(, SDB_FIELD_NAME, ) = " + "%d; expected: 0"); + fail_unless((value.type == SDB_TYPE_STRING) + && (! strcmp(value.data.string, "host")), + "sdb_store_get_field(, SDB_FIELD_NAME, ) " + "returned value {%d, %s}; expected {%d, host}", + value.type, value.data.string, SDB_TYPE_STRING); + sdb_data_free_datum(&value); + check = sdb_store_get_field(host, SDB_FIELD_LAST_UPDATE, &value); fail_unless(check == 0, "sdb_store_get_field(, SDB_FIELD_LAST_UPDATE, ) = "