On (18/07/13 15:45), Pavel Březina wrote:
On 07/18/2013 02:38 PM, Pavel Březina wrote:
>Hi,
>this is the first unit test for nested groups. It covers only the most
>basic situation when we are trying to resolve one group with no members.
>
>Even though it is only one test, the patch set is quite big. This is
>because it creates the possibility to mock providers related modules.
>Most of the patches are just a preparation for unit testing providers.
>
>Patches 1-5
>Moves the code around to reduce number of dependencies. (E.g. you do not
>want to load fail over when you are testing nested groups.)
>
>Patch 6
>Mocks basic SDAP interface.
>
>Patch 7
>Mocks sysdb objects - currently user and rfc2307bis group. You can
>decide what set of attributes the object should posses. For example,
>creating a user requires only basedn and name parameter, to construct
>originalDN and name attributes. The rest is provided by (attrname,
>value) pairs via variadic function.
>
>E.g.:
>mock_sysdb_user(mem_ctx, basedn, name, SYSDB_UIDNUM, uid, ...)
>
>get_attr_type() translates the sysdb attribute name to proper data type.
>This should be extended as needed.
>
>Patch 8
>Adds provider tests related common object files and cflags in makefile
>
>Patch 9
>New macro sss_will_return_always(fn, value). This can be used to mock
>function data in such way that any call of mock() will return the value.
>
>It was just pushed also to cmocka upstream as will_return_always().
>
>Patch 10-11
>Unit test.
>
>Patch 12
>Removes a noisy debug message.
>
>I would like to get this reviewed before I continue with more test
>cases, so the framework is tuned enough.
>
>Off topic:
>I also created new macro called fail_msg, which will make the test fail
>printing a message. I didn't use this macro in the end, but it made its
>way to cmocka upstream.
Oops, I did some reorganization while writing this mail but sent
patches generated sooner, so the numbers does not match. Reordered
patches are attached.
From 3054f4e5359b3f46faa33545b1cd36d11ef646ba Mon Sep 17 00:00:00
2001
From: =?UTF-8?q?Pavel=20B=C5=99ezina?= <pbrezina(a)redhat.com>
Date: Wed, 17 Jul 2013 13:51:37 +0200
Subject: [PATCH 05/12] ldap_options.c: do not call krb5_try_kdcip when unit
testing
---
src/providers/ldap/ldap_options.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/src/providers/ldap/ldap_options.c b/src/providers/ldap/ldap_options.c
index 68bf0d280ba1611ba414576ce0289742911d51da..9e8030f08c4f4de77cc78f7c96a42daca283059c
100644
--- a/src/providers/ldap/ldap_options.c
+++ b/src/providers/ldap/ldap_options.c
@@ -429,6 +429,7 @@ int ldap_get_options(TALLOC_CTX *memctx,
goto done;
}
+#ifndef UNIT_TESTING
/* If there is no KDC, try the deprecated krb5_kdcip option, too */
/* FIXME - this can be removed in a future version */
ret = krb5_try_kdcip(cdb, conf_path, opts->basic, SDAP_KRB5_KDC);
@@ -436,6 +437,7 @@ int ldap_get_options(TALLOC_CTX *memctx,
DEBUG(1, ("sss_krb5_try_kdcip failed.\n"));
goto done;
}
+#endif
Why do you need conditional build?
I think, that you can mock krb5_try_kdcip and every time return EOK.
authtok_type = dp_opt_get_string(opts->basic, SDAP_DEFAULT_AUTHTOK_TYPE);
if (authtok_type != NULL &&
--
1.7.11.7
From 7f909490572f3edf4c8f6540ee0b62bc5f226ea0 Mon Sep 17 00:00:00
2001
From: =?UTF-8?q?Pavel=20B=C5=99ezina?= <pbrezina(a)redhat.com>
Date: Wed, 17 Jul 2013 13:58:54 +0200
Subject: [PATCH 08/12] tests: prepare makefile for provider related unit
tests
---
Makefile.am | 13 +++++++++++++
1 file changed, 13 insertions(+)
diff --git a/Makefile.am b/Makefile.am
index 6cfc363cea9eae833a8a4bdff12309286475b89a..9065ee4b6312bc808de0253d81df68e38f5c633e
100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -1209,6 +1209,19 @@ TEST_MOCK_RESP_OBJ = \
src/responder/common/responder_cmd.c \
src/responder/common/negcache.c \
src/responder/common/responder_common.c
+
^^^^^
trailing whitespaces
+TEST_MOCK_PROVIDER_OBJ = \
+ src/util/sss_ldap.c \
+ src/providers/data_provider_opts.c \
+ src/providers/ldap/ldap_options.c \
+ src/providers/ldap/sdap.c \
+ src/providers/ldap/sdap_utils.c \
+ src/providers/ldap/sdap_range.c \
+ src/tests/cmocka/common_mock_sdap.c \
+ src/tests/cmocka/common_mock_sysdb_objects.c
+
^^^^^
trailing whitespaces
+TEST_MOCK_PROVIDER_CFLAGS = \
+ -DUNIT_TESTING
nss_srv_tests_DEPENDENCIES = \
$(ldblib_LTLIBRARIES)
--
1.7.11.7