summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJakub Hrozek <jhrozek@redhat.com>2015-05-29 15:46:57 +0200
committerJakub Hrozek <jhrozek@redhat.com>2015-06-14 21:47:20 +0200
commit28600ab8d160faa24aae379628dd8a58f50d13c6 (patch)
tree3ec8124bb25a6c7ad8bbc2e9fdcf4d494812d9f3
parentd43c9d18fb263b1ea4071b20e93ce4994583f62f (diff)
downloadsssd-28600ab8d160faa24aae379628dd8a58f50d13c6.tar.gz
sssd-28600ab8d160faa24aae379628dd8a58f50d13c6.tar.xz
sssd-28600ab8d160faa24aae379628dd8a58f50d13c6.zip
TESTS: Add a common function to set up sdap_id_ctx
Reduces code duplication between tests. Reviewed-by: Sumit Bose <sbose@redhat.com>
-rw-r--r--src/tests/cmocka/common_mock_sdap.c15
-rw-r--r--src/tests/cmocka/common_mock_sdap.h4
-rw-r--r--src/tests/cmocka/test_nested_groups.c14
3 files changed, 26 insertions, 7 deletions
diff --git a/src/tests/cmocka/common_mock_sdap.c b/src/tests/cmocka/common_mock_sdap.c
index 4f6988c26..1adfc7cae 100644
--- a/src/tests/cmocka/common_mock_sdap.c
+++ b/src/tests/cmocka/common_mock_sdap.c
@@ -33,6 +33,21 @@ errno_t krb5_try_kdcip(struct confdb_ctx *cdb,
return EOK;
}
+struct sdap_id_ctx *mock_sdap_id_ctx(TALLOC_CTX *mem_ctx,
+ struct be_ctx *be_ctx,
+ struct sdap_options *sdap_opts)
+{
+ struct sdap_id_ctx *sdap_id_ctx;
+
+ sdap_id_ctx = talloc_zero(mem_ctx, struct sdap_id_ctx);
+ assert_non_null(sdap_id_ctx);
+
+ sdap_id_ctx->be = be_ctx;
+ sdap_id_ctx->opts = sdap_opts;
+
+ return sdap_id_ctx;
+}
+
struct sdap_options *mock_sdap_options_ldap(TALLOC_CTX *mem_ctx,
struct sss_domain_info *domain,
struct confdb_ctx *confdb_ctx,
diff --git a/src/tests/cmocka/common_mock_sdap.h b/src/tests/cmocka/common_mock_sdap.h
index 937b83137..6fd1fb79c 100644
--- a/src/tests/cmocka/common_mock_sdap.h
+++ b/src/tests/cmocka/common_mock_sdap.h
@@ -38,6 +38,10 @@ struct sdap_options *mock_sdap_options_ldap(TALLOC_CTX *mem_ctx,
struct confdb_ctx *confdb_ctx,
const char *conf_path);
+struct sdap_id_ctx *mock_sdap_id_ctx(TALLOC_CTX *mem_ctx,
+ struct be_ctx *be_ctx,
+ struct sdap_options *sdap_opts);
+
struct sdap_handle *mock_sdap_handle(TALLOC_CTX *mem_ctx);
#endif /* COMMON_MOCK_SDAP_H_ */
diff --git a/src/tests/cmocka/test_nested_groups.c b/src/tests/cmocka/test_nested_groups.c
index 75fb3a19f..390b39950 100644
--- a/src/tests/cmocka/test_nested_groups.c
+++ b/src/tests/cmocka/test_nested_groups.c
@@ -54,6 +54,7 @@
struct nested_groups_test_ctx {
struct sss_test_ctx *tctx;
+ struct be_ctx *be_ctx;
struct sdap_options *sdap_opts;
struct sdap_handle *sdap_handle;
struct sdap_domain *sdap_domain;
@@ -596,14 +597,13 @@ static int nested_groups_test_setup(void **state)
test_ctx->sdap_handle = mock_sdap_handle(test_ctx);
assert_non_null(test_ctx->sdap_handle);
- test_ctx->sdap_id_ctx = talloc_zero(test_ctx,
- struct sdap_id_ctx);
- assert_non_null(test_ctx->sdap_id_ctx);
-
- test_ctx->sdap_id_ctx->be = mock_be_ctx(test_ctx, test_ctx->tctx);
- assert_non_null(test_ctx->sdap_id_ctx->be);
+ test_ctx->be_ctx = mock_be_ctx(test_ctx, test_ctx->tctx);
+ assert_non_null(test_ctx->be_ctx);
- test_ctx->sdap_id_ctx->opts = test_ctx->sdap_opts;
+ test_ctx->sdap_id_ctx = mock_sdap_id_ctx(test_ctx,
+ test_ctx->be_ctx,
+ test_ctx->sdap_opts);
+ assert_non_null(test_ctx->sdap_id_ctx);
ret = sdap_idmap_init(test_ctx, test_ctx->sdap_id_ctx, &test_ctx->idmap_ctx);
assert_int_equal(ret, EOK);