On 10/27/2015 09:42 AM, Petr Cech wrote:
The removed tests were:
  * users_by_filter_valid
  * users_by_filter_multiple_domains_valid
  * groups_by_filter_valid
  * groups_by_filter_multiple_domains_valid

Hello,

another patch set is attached.

This patch set covers groups_by_filter_valid by two new tests:
 * group_by_recent_filter_valid
 * groups_by_recent_filter_valid

The first of them tests the recent filter. The second tests interface ability to return more groups.


I looked at multiple_domains tests too. But I am afraid I misunderstood their purpose. Because users/groups are set with the same domains. I will look at it once again.

Regards,

Petr
>From 9c2cf658b62734df71650b568bd1c6be6c4c6e43 Mon Sep 17 00:00:00 2001
From: Petr Cech <pc...@redhat.com>
Date: Sun, 1 Nov 2015 07:09:28 -0500
Subject: [PATCH 4/6] TEST: Add test_group_by_recent_filter_valid

Test groups_by_filter_valid() was removed in past. We will add two new
tests instead of it. Logic of those tests is connected to RECENT
filter. It returns only records which have been wrote or updated after
filter was created (or another given time).

groups_by_filter_valid() --> group_by_recent_filter_valid()
                             grous_by_recent_filter_valid()

The first of new tests, group_by_recent_filter_valid(), counts with two
groups. One is stored before filter request creation and the second
group is stored after filter request creation. So filter returns only
one group.

The second of new tests, groups_by_recent_filter_valid(), counts with
three users. One is stored before filter request creation and two
groups are stored after filter request creation. So filter returns two
groups.

This patch adds group_by_recent_filter_valid().

Resolves:
https://fedorahosted.org/sssd/ticket/2730
---
 src/tests/cmocka/test_responder_cache_req.c | 45 +++++++++++++++++++++++++++++
 1 file changed, 45 insertions(+)

diff --git a/src/tests/cmocka/test_responder_cache_req.c b/src/tests/cmocka/test_responder_cache_req.c
index e4fccdab883f267cced1cf2e9995bd9828242690..77bdde40917b576b2b97d92d9dc23900085a11ae 100644
--- a/src/tests/cmocka/test_responder_cache_req.c
+++ b/src/tests/cmocka/test_responder_cache_req.c
@@ -1495,6 +1495,50 @@ static void cache_req_group_by_filter_test_done(struct tevent_req *req)
     ctx->tctx->done = true;
 }
 
+void test_group_by_recent_filter_valid(void **state)
+{
+    struct cache_req_test_ctx *test_ctx = NULL;
+    TALLOC_CTX *req_mem_ctx = NULL;
+    struct tevent_req *req = NULL;
+    const char *ldbname = NULL;
+    errno_t ret;
+
+    test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
+    test_ctx->create_group = true;
+
+    ret = sysdb_store_group(test_ctx->tctx->dom, TEST_GROUP_NAME2,
+                            1001, NULL, 1001, time(NULL));
+    assert_int_equal(ret, EOK);
+
+    sleep(1);
+
+    req_mem_ctx = talloc_new(global_talloc_context);
+    check_leaks_push(req_mem_ctx);
+
+    /* Filters always go to DP */
+    will_return(__wrap_sss_dp_get_account_send, test_ctx);
+    mock_account_recv_simple();
+
+    req = cache_req_group_by_filter_send(req_mem_ctx, test_ctx->tctx->ev,
+                                         test_ctx->rctx,
+                                         test_ctx->tctx->dom->name,
+                                         "test*");
+    assert_non_null(req);
+    tevent_req_set_callback(req, cache_req_group_by_filter_test_done, test_ctx);
+
+    ret = test_ev_loop(test_ctx->tctx);
+    assert_int_equal(ret, ERR_OK);
+    assert_true(check_leaks_pop(req_mem_ctx));
+
+    assert_non_null(test_ctx->result);
+    assert_int_equal(test_ctx->result->count, 1);
+
+    ldbname = ldb_msg_find_attr_as_string(test_ctx->result->msgs[0],
+                                          SYSDB_NAME, NULL);
+    assert_non_null(ldbname);
+    assert_string_equal(ldbname, TEST_GROUP_NAME);
+}
+
 void test_groups_by_filter_notfound(void **state)
 {
     struct cache_req_test_ctx *test_ctx = NULL;
@@ -1615,6 +1659,7 @@ int main(int argc, const char *argv[])
 
         new_single_domain_test(user_by_recent_filter_valid),
         new_single_domain_test(users_by_recent_filter_valid),
+        new_single_domain_test(group_by_recent_filter_valid),
 
         new_single_domain_test(users_by_filter_filter_old),
         new_single_domain_test(users_by_filter_notfound),
-- 
2.4.3

>From 4efa3966f20791d65c439ff450b473c6d9419eff Mon Sep 17 00:00:00 2001
From: Petr Cech <pc...@redhat.com>
Date: Sun, 1 Nov 2015 07:21:18 -0500
Subject: [PATCH 5/6] TEST: Refactor of test_responder_cache_req.c

We need little more in backroung of responder_cache_req tests. There
will be tests which will use three test groups. This patch add support
for it.

Resolves:
https://fedorahosted.org/sssd/ticket/2730
---
 src/tests/cmocka/test_responder_cache_req.c | 20 +++++++++++++++-----
 1 file changed, 15 insertions(+), 5 deletions(-)

diff --git a/src/tests/cmocka/test_responder_cache_req.c b/src/tests/cmocka/test_responder_cache_req.c
index 77bdde40917b576b2b97d92d9dc23900085a11ae..4fc8be02a9df98781878ad04e683d98445f68c68 100644
--- a/src/tests/cmocka/test_responder_cache_req.c
+++ b/src/tests/cmocka/test_responder_cache_req.c
@@ -91,7 +91,8 @@ struct cache_req_test_ctx {
     bool dp_called;
     bool create_user1;
     bool create_user2;
-    bool create_group;
+    bool create_group1;
+    bool create_group2;
 };
 
 const char *domains[] = {"responder_cache_req_test_a",
@@ -339,11 +340,17 @@ __wrap_sss_dp_get_account_send(TALLOC_CTX *mem_ctx,
                               TEST_USER_ID2, TEST_GROUP_ID2, 1000, time(NULL));
     }
 
-    if (ctx->create_group) {
+    if (ctx->create_group1) {
         ret = sysdb_store_group(ctx->tctx->dom, TEST_GROUP_NAME,
                                 TEST_GROUP_ID, NULL, 1000, time(NULL));
         assert_int_equal(ret, EOK);
     }
+    if (ctx->create_group2) {
+        ret = sysdb_store_group(ctx->tctx->dom, TEST_GROUP_NAME2,
+                                TEST_GROUP_ID2, NULL, 1000, time(NULL));
+        assert_int_equal(ret, EOK);
+    }
+
 
     return test_req_succeed_send(mem_ctx, rctx->ev);
 }
@@ -1090,7 +1097,8 @@ void test_group_by_name_missing_found(void **state)
     will_return(__wrap_sss_dp_get_account_send, test_ctx);
     mock_account_recv_simple();
 
-    test_ctx->create_group = true;
+    test_ctx->create_group1 = true;
+    test_ctx->create_group2 = false;
 
     /* Test. */
     run_group_by_name(test_ctx, test_ctx->tctx->dom, 0, ERR_OK);
@@ -1230,7 +1238,8 @@ void test_group_by_id_missing_found(void **state)
     will_return(__wrap_sss_dp_get_account_send, test_ctx);
     mock_account_recv_simple();
 
-    test_ctx->create_group = true;
+    test_ctx->create_group1 = true;
+    test_ctx->create_group2 = false;
 
     /* Test. */
     run_group_by_id(test_ctx, test_ctx->tctx->dom, 0, ERR_OK);
@@ -1504,7 +1513,8 @@ void test_group_by_recent_filter_valid(void **state)
     errno_t ret;
 
     test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
-    test_ctx->create_group = true;
+    test_ctx->create_group1 = true;
+    test_ctx->create_group2 = false;
 
     ret = sysdb_store_group(test_ctx->tctx->dom, TEST_GROUP_NAME2,
                             1001, NULL, 1001, time(NULL));
-- 
2.4.3

>From 4d8aa364836901389752b20446393f6ea4abc2d0 Mon Sep 17 00:00:00 2001
From: Petr Cech <pc...@redhat.com>
Date: Sun, 1 Nov 2015 07:45:56 -0500
Subject: [PATCH 6/6] TEST: Add test_groups_by_recent_filter_valid

Test groups_by_filter_valid() was removed in past. We will add two new
tests instead of it. Logic of those tests is connected to RECENT
filter. It returns only records which have been wrote or updated after
filter was created (or another given time).

groups_by_filter_valid() --> group_by_recent_filter_valid()
                             grous_by_recent_filter_valid()

The first of new tests, group_by_recent_filter_valid(), counts with two
groups. One is stored before filter request creation and the second
group is stored after filter request creation. So filter returns only
one group.

The second of new tests, groups_by_recent_filter_valid(), counts with
three users. One is stored before filter request creation and two
groups are stored after filter request creation. So filter returns two
groups.

This patch adds groups_by_recent_filter_valid().

Resolves:
https://fedorahosted.org/sssd/ticket/2730
---
 src/tests/cmocka/test_responder_cache_req.c | 62 +++++++++++++++++++++++++++++
 1 file changed, 62 insertions(+)

diff --git a/src/tests/cmocka/test_responder_cache_req.c b/src/tests/cmocka/test_responder_cache_req.c
index 4fc8be02a9df98781878ad04e683d98445f68c68..5ecd22d944216be0774ed7e9f796035b79b1d4dd 100644
--- a/src/tests/cmocka/test_responder_cache_req.c
+++ b/src/tests/cmocka/test_responder_cache_req.c
@@ -1549,6 +1549,67 @@ void test_group_by_recent_filter_valid(void **state)
     assert_string_equal(ldbname, TEST_GROUP_NAME);
 }
 
+void test_groups_by_recent_filter_valid(void **state)
+{
+    struct cache_req_test_ctx *test_ctx = NULL;
+    TALLOC_CTX *req_mem_ctx = NULL;
+    struct tevent_req *req = NULL;
+    const char *ldbname1 = NULL;
+    const char *ldbname2 = NULL;
+    bool comparison1 = false;
+    bool comparison2 = false;
+    bool comparison3 = false;
+    bool comparison4 = false;
+    errno_t ret;
+
+    test_ctx = talloc_get_type_abort(*state, struct cache_req_test_ctx);
+    test_ctx->create_group1 = true;
+    test_ctx->create_group2 = true;
+
+    ret = sysdb_store_group(test_ctx->tctx->dom, TEST_GROUP_NAME2,
+                            1001, NULL, 1001, time(NULL));
+    assert_int_equal(ret, EOK);
+
+    sleep(1);
+
+    req_mem_ctx = talloc_new(global_talloc_context);
+    check_leaks_push(req_mem_ctx);
+
+    /* Filters always go to DP */
+    will_return(__wrap_sss_dp_get_account_send, test_ctx);
+    mock_account_recv_simple();
+
+    req = cache_req_group_by_filter_send(req_mem_ctx, test_ctx->tctx->ev,
+                                         test_ctx->rctx,
+                                         test_ctx->tctx->dom->name,
+                                         "test*");
+    assert_non_null(req);
+
+    tevent_req_set_callback(req, cache_req_group_by_filter_test_done, test_ctx);
+
+    ret = test_ev_loop(test_ctx->tctx);
+    assert_int_equal(ret, ERR_OK);
+    assert_true(check_leaks_pop(req_mem_ctx));
+
+    assert_non_null(test_ctx->result);
+    assert_int_equal(test_ctx->result->count, 2);
+
+    ldbname1 = ldb_msg_find_attr_as_string(test_ctx->result->msgs[0],
+                                           SYSDB_NAME, NULL);
+    assert_non_null(ldbname1);
+
+    ldbname2 = ldb_msg_find_attr_as_string(test_ctx->result->msgs[1],
+                                           SYSDB_NAME, NULL);
+    assert_non_null(ldbname2);
+
+    assert_string_not_equal(ldbname1, ldbname2);
+    comparison1 = strcmp(ldbname1, TEST_GROUP_NAME) == 0 ? true : false;
+    comparison2 = strcmp(ldbname1, TEST_GROUP_NAME2) == 0 ? true : false;
+    comparison3 = strcmp(ldbname2, TEST_GROUP_NAME) == 0 ? true : false;
+    comparison4 = strcmp(ldbname2, TEST_GROUP_NAME2) == 0 ? true : false;
+    assert_true((comparison1 || comparison2) && (comparison3 || comparison4));
+}
+
 void test_groups_by_filter_notfound(void **state)
 {
     struct cache_req_test_ctx *test_ctx = NULL;
@@ -1670,6 +1731,7 @@ int main(int argc, const char *argv[])
         new_single_domain_test(user_by_recent_filter_valid),
         new_single_domain_test(users_by_recent_filter_valid),
         new_single_domain_test(group_by_recent_filter_valid),
+        new_single_domain_test(groups_by_recent_filter_valid),
 
         new_single_domain_test(users_by_filter_filter_old),
         new_single_domain_test(users_by_filter_notfound),
-- 
2.4.3

_______________________________________________
sssd-devel mailing list
sssd-devel@lists.fedorahosted.org
https://lists.fedorahosted.org/mailman/listinfo/sssd-devel

Reply via email to