diff options
author | Pavel Březina <pbrezina@redhat.com> | 2014-11-21 14:41:03 +0100 |
---|---|---|
committer | Jakub Hrozek <jhrozek@redhat.com> | 2015-01-09 15:16:04 +0100 |
commit | cb4742876508a08ba90c82466c9dba708e4bf999 (patch) | |
tree | 47333fc91bca25295690b5f9b11658275f49b90f /src/tests/common_dom.c | |
parent | 629a188ec71155911301fddc36e360831045d2c6 (diff) | |
download | sssd-cb4742876508a08ba90c82466c9dba708e4bf999.tar.gz sssd-cb4742876508a08ba90c82466c9dba708e4bf999.tar.xz sssd-cb4742876508a08ba90c82466c9dba708e4bf999.zip |
tests: remove code duplication in single domain cleanup
Reviewed-by: Michal Židek <mzidek@redhat.com>
Diffstat (limited to 'src/tests/common_dom.c')
-rw-r--r-- | src/tests/common_dom.c | 70 |
1 files changed, 12 insertions, 58 deletions
diff --git a/src/tests/common_dom.c b/src/tests/common_dom.c index d314aef41..41f876555 100644 --- a/src/tests/common_dom.c +++ b/src/tests/common_dom.c @@ -339,8 +339,14 @@ void test_multidom_suite_cleanup(const char *tests_path, if (domains != NULL) { for (i = 0; domains[i] != NULL; i++) { - sysdb_path = talloc_asprintf(tmp_ctx, "%s/cache_%s.ldb", - tests_path, domains[i]); + if (strcmp(domains[i], LOCAL_SYSDB_FILE) == 0) { + /* local domain */ + sysdb_path = talloc_asprintf(tmp_ctx, "%s/%s", + tests_path, domains[i]); + } else { + sysdb_path = talloc_asprintf(tmp_ctx, "%s/cache_%s.ldb", + tests_path, domains[i]); + } if (sysdb_path == NULL) { DEBUG(SSSDBG_CRIT_FAILURE, "Could not construct sysdb path\n"); goto done; @@ -371,62 +377,10 @@ done: } void test_dom_suite_cleanup(const char *tests_path, - const char *confdb_path, - const char *sysdb_path) + const char *cdb_file, + const char *domain) { - errno_t ret; - char *conf_db; - char *sys_db; - TALLOC_CTX *tmp_ctx; - - tmp_ctx = talloc_new(NULL); - if (!tmp_ctx) { - DEBUG(SSSDBG_CRIT_FAILURE, "talloc_new failed\n"); - return; - } - - if (confdb_path != NULL) { - conf_db = talloc_asprintf(tmp_ctx, "%s/%s", tests_path, confdb_path); - if (!conf_db) { - DEBUG(SSSDBG_CRIT_FAILURE, - "Could not construct conf_db path\n"); - goto done; - } - - errno = 0; - ret = unlink(conf_db); - if (ret != 0 && errno != ENOENT) { - DEBUG(SSSDBG_CRIT_FAILURE, - "Could not delete the test config ldb file (%d) (%s)\n", - errno, strerror(errno)); - } - } - - if (sysdb_path != NULL) { - sys_db = talloc_asprintf(tmp_ctx, "%s/%s", tests_path, sysdb_path); - if (!sys_db) { - DEBUG(SSSDBG_CRIT_FAILURE, - "Could not construct sys_db path\n"); - goto done; - } - - errno = 0; - ret = unlink(sys_db); - if (ret != 0 && errno != ENOENT) { - DEBUG(SSSDBG_CRIT_FAILURE, - "Could not delete the test ldb file (%d) (%s)\n", - errno, strerror(errno)); - } - } + const char *domains[] = {domain, NULL}; - errno = 0; - ret = rmdir(tests_path); - if (ret != 0 && errno != ENOENT) { - DEBUG(SSSDBG_CRIT_FAILURE, - "Could not delete the test dir (%d) (%s)\n", - errno, strerror(errno)); - } - -done: - talloc_free(tmp_ctx); + test_multidom_suite_cleanup(tests_path, cdb_file, domains); } |