Date: Fri, 6 Sep 2013 13:05:13 GMT From: mattbw@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r257013 - soc2013/mattbw/backend Message-ID: <201309061305.r86D5D33021652@socsvn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: mattbw Date: Fri Sep 6 13:05:13 2013 New Revision: 257013 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=257013 Log: Add test case for checking the type-of-repo functionality. This necessitated a separation of the package database-dependent code in repo.c. Modified: soc2013/mattbw/backend/repo.c soc2013/mattbw/backend/repo.h soc2013/mattbw/backend/repo_test.c Modified: soc2013/mattbw/backend/repo.c ============================================================================== --- soc2013/mattbw/backend/repo.c Fri Sep 6 12:59:48 2013 (r257012) +++ soc2013/mattbw/backend/repo.c Fri Sep 6 13:05:13 2013 (r257013) @@ -30,25 +30,45 @@ /* * Finds the type of the given PackageKit repository name. + * + * This function checks remote repositories to ensure they match actually + * configured repositories, and instead returns 'REPO_INVALID' when they don't. + * A separate function 'repo_type_no_remote_check' does not do this and can + * thus be unit tested. */ enum repo_type repo_type(const char *name) { - enum repo_type rtype; + enum repo_type type; + + /* 'name' may be NULL. This implies REPO_ANY. */ + + type = repo_type_no_remote_check(name); + + if (type == REPO_REMOTE && + (pkg_repo_find_ident(pkg_repo_ident_from_name(name)) != NULL)) { + type = REPO_INVALID; + } + + return type; +} + +/* As repo_type, but without the remote repository check. */ +enum repo_type +repo_type_no_remote_check(const char *name) +{ + enum repo_type type; /* Null or empty implies no specific repository */ if (name == NULL || name[0] == '\0') { - rtype = REPO_ANY; + type = REPO_ANY; } else if (strcmp(name, "installed") == 0) { - rtype = REPO_LOCAL; - } else if (pkg_repo_find_ident(pkg_repo_ident_from_name(name)) - != NULL) { - rtype = REPO_REMOTE; + type = REPO_LOCAL; } else { - rtype = REPO_INVALID; + type = REPO_REMOTE; } - return rtype; + return type; } /* Modified: soc2013/mattbw/backend/repo.h ============================================================================== --- soc2013/mattbw/backend/repo.h Fri Sep 6 12:59:48 2013 (r257012) +++ soc2013/mattbw/backend/repo.h Fri Sep 6 13:05:13 2013 (r257013) @@ -31,6 +31,7 @@ }; enum repo_type repo_type(const char *name); +enum repo_type repo_type_no_remote_check(const char *name); const char *repo_of_package(struct pkg *package); #endif /* !_PKGNG_BACKEND_REPO_H_ */ Modified: soc2013/mattbw/backend/repo_test.c ============================================================================== --- soc2013/mattbw/backend/repo_test.c Fri Sep 6 12:59:48 2013 (r257012) +++ soc2013/mattbw/backend/repo_test.c Fri Sep 6 13:05:13 2013 (r257013) @@ -84,12 +84,29 @@ pkg_free(pkg); } +ATF_TC(repo_type_test); +ATF_TC_HEAD(repo_type_test, tc) +{ + + atf_tc_set_md_var(tc, "descr", "Test repo_type_no_remote_check."); +} +ATF_TC_BODY(repo_type_test, tc) +{ + + ATF_CHECK_EQ(repo_type_no_remote_check("installed"), REPO_LOCAL); + ATF_CHECK_EQ(repo_type_no_remote_check("derp"), REPO_REMOTE); + ATF_CHECK_EQ(repo_type_no_remote_check(""), REPO_ANY); + ATF_CHECK_EQ(repo_type_no_remote_check(NULL), REPO_ANY); +} + + /* * TEST PACK */ ATF_TP_ADD_TCS(tp) { + ATF_TP_ADD_TC(tp, repo_type_test); ATF_TP_ADD_TC(tp, repo_of_package_valid_local); ATF_TP_ADD_TC(tp, repo_of_package_valid_installed); ATF_TP_ADD_TC(tp, repo_of_package_valid_remote);
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201309061305.r86D5D33021652>