[SSSD] [PATCH] TESTS: Add unit tests for the GPO interface

Jakub Hrozek jhrozek at redhat.com
Tue Aug 19 10:03:36 UTC 2014


On Wed, Aug 13, 2014 at 02:31:36PM -0400, Yassir Elley wrote:
> I have one nitpick.
> 
> +    ret = sysdb_gpo_store_gpo(test_ctx->domain,
> +                              test_guid, 1, 5, 0);
> +    fail_if(ret != EOK, "Could not store a test GPO");
> +
> +    ret = sysdb_gpo_get_gpos(test_ctx, test_ctx->domain, &result);
> +    fail_if(ret != EOK, "GPOs not in cache before store op");
> +    fail_if(result == NULL);
> +    fail_if(result->count != 1);
> 
> In the above snippet, you store a gpo and then attempt to retrieve all gpos. The error message after sysdb_gpo_get_gpos says "GPOs not in cache before store op", whereas it should really say "GPOs not in cache after store op".
> 
> Otherwise, the code looks good!
> 
> Regards,
> Yassir.

Thanks for catching that, a new patch is attached.
-------------- next part --------------
>From 7ba79d4a57af22450c9dce797b77d605b2013eed Mon Sep 17 00:00:00 2001
From: Jakub Hrozek <jhrozek at redhat.com>
Date: Mon, 21 Jul 2014 20:31:15 +0200
Subject: [PATCH] TESTS: Add unit tests for the GPO interface

---
 src/tests/sysdb-tests.c | 105 ++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 105 insertions(+)

diff --git a/src/tests/sysdb-tests.c b/src/tests/sysdb-tests.c
index d24bd4f7d4f0e8f85afa7c98da8edc0635b2e328..56e329784ba2a4250b80ae9f92cac05801282e2e 100644
--- a/src/tests/sysdb-tests.c
+++ b/src/tests/sysdb-tests.c
@@ -5535,6 +5535,106 @@ START_TEST(test_upn_dup)
 }
 END_TEST
 
+START_TEST(test_gpo_store_retrieve)
+{
+    struct sysdb_test_ctx *test_ctx;
+    errno_t ret;
+    struct ldb_result *result = NULL;
+    const char *guid;
+    int version;
+    static const char *test_guid = "3610EDA5-77EF-11D2-8DC5-00C04FA31A66";
+
+    ret = setup_sysdb_tests(&test_ctx);
+    fail_if(ret != EOK, "Could not set up the test");
+
+    ret = sysdb_gpo_get_gpo_by_guid(test_ctx, test_ctx->domain,
+                                    test_guid,
+                                    &result);
+    fail_if(ret != ENOENT, "GPO present in cache before store op");
+
+    ret = sysdb_gpo_get_gpos(test_ctx, test_ctx->domain, &result);
+    fail_if(ret != ENOENT, "GPO present in cache before store op");
+
+    ret = sysdb_gpo_store_gpo(test_ctx->domain,
+                              test_guid, 1, 5, 0);
+    fail_if(ret != EOK, "Could not store a test GPO");
+
+    ret = sysdb_gpo_get_gpos(test_ctx, test_ctx->domain, &result);
+    fail_if(ret != EOK, "GPOs not in cache after store op");
+    fail_if(result == NULL);
+    fail_if(result->count != 1);
+
+    result = NULL;
+    ret = sysdb_gpo_get_gpo_by_guid(test_ctx, test_ctx->domain,
+                                    test_guid, &result);
+    fail_if(ret != EOK, "GPO not in cache after store op");
+    fail_if(result == NULL);
+    fail_if(result->count != 1);
+
+    guid = ldb_msg_find_attr_as_string(result->msgs[0],
+                                       SYSDB_GPO_GUID_ATTR, NULL);
+    ck_assert_str_eq(guid, test_guid);
+
+    version = ldb_msg_find_attr_as_uint(result->msgs[0],
+                                        SYSDB_GPO_VERSION_ATTR, 0);
+    ck_assert_int_eq(version, 1);
+}
+END_TEST
+
+START_TEST(test_gpo_replace)
+{
+    struct sysdb_test_ctx *test_ctx;
+    errno_t ret;
+    struct ldb_result *result = NULL;
+    const char *guid;
+    int version;
+    static const char *test_guid = "3610EDA5-77EF-11D2-8DC5-00C04FA31A66";
+
+    ret = setup_sysdb_tests(&test_ctx);
+    fail_if(ret != EOK, "Could not setup the test");
+
+    ret = sysdb_gpo_get_gpo_by_guid(test_ctx, test_ctx->domain,
+                                    test_guid, &result);
+    fail_if(ret != EOK, "GPO not in cache after store op");
+    fail_if(result == NULL);
+    fail_if(result->count != 1);
+
+    guid = ldb_msg_find_attr_as_string(result->msgs[0],
+                                       SYSDB_GPO_GUID_ATTR, NULL);
+    ck_assert_str_eq(guid, test_guid);
+
+    version = ldb_msg_find_attr_as_uint(result->msgs[0],
+                                        SYSDB_GPO_VERSION_ATTR, 0);
+    ck_assert_int_eq(version, 1);
+
+    /* Modify the version */
+    ret = sysdb_gpo_store_gpo(test_ctx->domain,
+                              test_guid, 2, 5, 0);
+    fail_if(ret != EOK, "Could not store a test GPO");
+
+    ret = sysdb_gpo_get_gpo_by_guid(test_ctx, test_ctx->domain,
+                                    test_guid, &result);
+    fail_if(ret != EOK, "GPO not in cache after modify op");
+    fail_if(result == NULL);
+    fail_if(result->count != 1);
+
+    ret = sysdb_gpo_get_gpo_by_guid(test_ctx, test_ctx->domain,
+                                    test_guid, &result);
+    fail_if(ret != EOK, "GPO not in cache after store op");
+    fail_if(result == NULL);
+    fail_if(result->count != 1);
+
+    guid = ldb_msg_find_attr_as_string(result->msgs[0],
+                                       SYSDB_GPO_GUID_ATTR, NULL);
+    ck_assert_str_eq(guid, test_guid);
+
+    version = ldb_msg_find_attr_as_uint(result->msgs[0],
+                                        SYSDB_GPO_VERSION_ATTR, 0);
+    ck_assert_int_eq(version, 2);
+
+}
+END_TEST
+
 START_TEST(test_confdb_list_all_domain_names_multi_dom)
 {
     int ret;
@@ -5944,6 +6044,11 @@ Suite *create_sysdb_suite(void)
 
     suite_add_tcase(s, tc_upn);
 
+    TCase *tc_gpo = tcase_create("SYSDB GPO tests");
+    tcase_add_test(tc_gpo, test_gpo_store_retrieve);
+    tcase_add_test(tc_gpo, test_gpo_replace);
+    suite_add_tcase(s, tc_gpo);
+
     /* ConfDB tests -- modify confdb, must always be last!! */
     TCase *tc_confdb = tcase_create("confDB tests");
 
-- 
1.9.3



More information about the sssd-devel mailing list