[SSSD] [PATCH] TEST: recent_valid filter testing

Petr Cech pcech at redhat.com
Tue Nov 10 14:48:55 UTC 2015


On 11/10/2015 08:29 AM, Pavel Reichl wrote:
>
>
> On 11/05/2015 05:29 PM, Petr Cech wrote:
>> +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 **group_names = NULL;
>> +    const char **ldb_results = NULL;
>> +    const char *ldbname = NULL;
>> +    void *tmp_ctx = NULL;
> Could you use TALLOC_CTX?
Yes, I could :-)
>
>> +    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();
>> +
>> +    /* Group TEST_GROUP1 and TEST_GROUP2 are created with a DP
>> callback. */
>> +    req = cache_req_group_by_filter_send(req_mem_ctx,
>> test_ctx->tctx->ev,
>> +                                         test_ctx->rctx,
>> +                                         test_ctx->tctx->dom->name,
>> +                                         TEST_USER_PREFIX);
>> +    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);
>> +
>> +    tmp_ctx = talloc_zero(NULL, void *);
>
> Why not to use talloc_new(parent_ctx)?
>
>> +
>> +    group_names = talloc_array(tmp_ctx, const char *, 2);
>> +    assert_non_null(group_names);
>> +    group_names[0] = TEST_GROUP_NAME;
>> +    group_names[1] = TEST_GROUP_NAME2;
>> +
>> +    ldb_results = talloc_array(tmp_ctx, const char *, 2);
>> +    assert_non_null(ldb_results);
>> +    for (int i = 0; i < 2; ++i) {
>> +        ldbname = ldb_msg_find_attr_as_string(test_ctx->result->msgs[i],
>> +                                              SYSDB_NAME, NULL);
>> +        assert_non_null(ldbname);
>> +        ldb_results[i] = ldbname;
>> +    }
>> +
>> +    assert_string_not_equal(ldb_results[0], ldb_results[1]);
>> +
>> +    assert_true(are_values_in_ldb_result(ldb_results, group_names));
>> +
>> +    talloc_zfree(tmp_ctx);
>> +}
>
> Thanks!

Your comments will be addressed in nex patchset.

Petr


More information about the sssd-devel mailing list