On (19/08/14 12:03), Jakub Hrozek wrote:
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.
From 7ba79d4a57af22450c9dce797b77d605b2013eed Mon Sep 17 00:00:00
2001
From: Jakub Hrozek <jhrozek(a)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);
copy&paste problem ?
sysdb_gpo_get_gpo_by_guid is calle twice, just debug message for "ret != EOK"
is different.
and you forgot to release test context at the ond of tests.
@@ -5578,6 +5578,7 @@ START_TEST(test_gpo_store_retrieve)
version = ldb_msg_find_attr_as_uint(result->msgs[0],
SYSDB_GPO_VERSION_ATTR, 0);
ck_assert_int_eq(version, 1);
+ talloc_free(test_ctx);
}
END_TEST
@@ -5631,6 +5632,7 @@ START_TEST(test_gpo_replace)
version = ldb_msg_find_attr_as_uint(result->msgs[0],
SYSDB_GPO_VERSION_ATTR, 0);
ck_assert_int_eq(version, 2);
+ talloc_free(test_ctx);
}
END_TEST
LS