X-Git-Url: https://git.tokkee.org/?p=sysdb.git;a=blobdiff_plain;f=t%2Funit%2Fcore%2Fstore_test.c;h=6715a5b0868a49714b3a9e3664ff586e6455166c;hp=0a022e430508276e80563c7b37fc2fb494f6e511;hb=0a17f3d9f23b988420acbf5669bda4f2a0936c6b;hpb=b1208c38f5098db7fb76ee760b29b57d89366807 diff --git a/t/unit/core/store_test.c b/t/unit/core/store_test.c index 0a022e4..6715a5b 100644 --- a/t/unit/core/store_test.c +++ b/t/unit/core/store_test.c @@ -240,6 +240,54 @@ START_TEST(test_store_service) } END_TEST +START_TEST(test_store_service_attr) +{ + struct { + const char *host; + const char *svc; + const char *attr; + const sdb_data_t value; + sdb_time_t last_update; + int expected; + } golden_data[] = { + { "k", "s1", "a1", { SDB_TYPE_INTEGER, { .integer = 123 } }, 1, -1 }, + /* retry, it should still fail */ + { "k", "s1", "a1", { SDB_TYPE_INTEGER, { .integer = 123 } }, 1, -1 }, + { "l", "sX", "a1", { SDB_TYPE_INTEGER, { .integer = 123 } }, 1, -1 }, + /* retry, it should still fail */ + { "l", "sX", "a1", { SDB_TYPE_INTEGER, { .integer = 123 } }, 1, -1 }, + { "l", "s1", "a1", { SDB_TYPE_INTEGER, { .integer = 123 } }, 1, 0 }, + { "l", "s1", "a1", { SDB_TYPE_INTEGER, { .integer = 123 } }, 1, 1 }, + { "l", "s1", "a1", { SDB_TYPE_INTEGER, { .integer = 123 } }, 2, 0 }, + { "l", "s1", "a2", { SDB_TYPE_INTEGER, { .integer = 123 } }, 1, 0 }, + { "l", "s1", "a2", { SDB_TYPE_INTEGER, { .integer = 123 } }, 1, 1 }, + { "l", "s2", "a2", { SDB_TYPE_INTEGER, { .integer = 123 } }, 1, 0 }, + { "m", "s1", "a1", { SDB_TYPE_INTEGER, { .integer = 123 } }, 1, 0 }, + }; + + size_t i; + + sdb_store_host("m", 1); + sdb_store_host("l", 1); + sdb_store_service("m", "s1", 1); + sdb_store_service("l", "s1", 1); + sdb_store_service("l", "s2", 1); + + for (i = 0; i < SDB_STATIC_ARRAY_LEN(golden_data); ++i) { + int status; + + status = sdb_store_service_attr(golden_data[i].host, + golden_data[i].svc, golden_data[i].attr, + &golden_data[i].value, golden_data[i].last_update); + fail_unless(status == golden_data[i].expected, + "sdb_store_service_attr(%s, %s, %s, %d, %d) = %d; " + "expected: %d", golden_data[i].host, golden_data[i].svc, + golden_data[i].attr, golden_data[i].value.data.integer, + golden_data[i].last_update, status, golden_data[i].expected); + } +} +END_TEST + static void verify_json_output(sdb_strbuf_t *buf, const char *expected, int flags) { @@ -497,6 +545,7 @@ core_store_suite(void) tcase_add_test(tc, test_store_get_host); tcase_add_test(tc, test_store_attr); tcase_add_test(tc, test_store_service); + tcase_add_test(tc, test_store_service_attr); tcase_add_test(tc, test_interval); tcase_add_test(tc, test_iterate); tcase_add_unchecked_fixture(tc, NULL, sdb_store_clear);