From b76ed3a2a95b45fb9a75cfd01613d826bebc9bb9 Mon Sep 17 00:00:00 2001 From: Sebastian Harl Date: Thu, 18 Sep 2014 20:24:11 -0700 Subject: [PATCH] store: Don't wrap JSON serialized LIST replies in a separate object. Previously, the reply was {"hosts": []} while now it's just the list. This way, the response format matches that of other commands which return host lists. --- src/core/store.c | 4 ++-- t/unit/core/store_test.c | 32 ++++++++++++++++---------------- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/core/store.c b/src/core/store.c index 3bc1114..401780e 100644 --- a/src/core/store.c +++ b/src/core/store.c @@ -967,7 +967,7 @@ sdb_store_tojson(sdb_strbuf_t *buf, sdb_store_matcher_t *filter, int flags) return -1; } - sdb_strbuf_append(buf, "{\"hosts\":["); + sdb_strbuf_append(buf, "["); len = sdb_strbuf_len(buf); while (sdb_avltree_iter_has_next(host_iter)) { @@ -987,7 +987,7 @@ sdb_store_tojson(sdb_strbuf_t *buf, sdb_store_matcher_t *filter, int flags) return -1; } - sdb_strbuf_append(buf, "]}"); + sdb_strbuf_append(buf, "]"); sdb_avltree_iter_destroy(host_iter); pthread_rwlock_unlock(&host_lock); diff --git a/t/unit/core/store_test.c b/t/unit/core/store_test.c index e8c77c7..796c50c 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,17 @@ 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_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 +621,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 +639,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); -- 2.30.2