END_TEST START_TEST(test_goal_list_err) { HyGoal goal = hy_goal_create(test_globals.sack); fail_unless(hy_goal_list_installs(goal) == NULL); fail_unless(hy_get_errno() == HY_E_OP); hy_goal_free(goal); }
static void goal_dealloc(_GoalObject *self) { if (self->goal) hy_goal_free(self->goal); Py_XDECREF(self->sack); Py_TYPE(self)->tp_free(self); }
END_TEST START_TEST(test_goal_install_weak_deps) { HySelector sltr = hy_selector_create(test_globals.sack); hy_selector_set(sltr, HY_PKG_NAME, HY_EQ, "B"); HyGoal goal = hy_goal_create(test_globals.sack); fail_if(!hy_goal_install_selector(goal, sltr, NULL)); HyGoal goal2 = hy_goal_clone(goal); fail_if(hy_goal_run(goal)); // recommended package C is installed too assert_iueo(goal, 2, 0, 0, 0); fail_if(hy_goal_run_flags(goal2, DNF_IGNORE_WEAK_DEPS)); assert_iueo(goal2, 1, 0, 0, 0); hy_goal_free(goal); hy_goal_free(goal2); hy_selector_free(sltr); }
END_TEST START_TEST(test_goal_list_err) { g_autoptr(GError) error = NULL; HyGoal goal = hy_goal_create(test_globals.sack); fail_unless(hy_goal_list_installs(goal, &error) == NULL); fail_unless(error->code == DNF_ERROR_INTERNAL_ERROR); hy_goal_free(goal); }
END_TEST START_TEST(test_goal_upgrade_disabled_repo) { DnfSack *sack = test_globals.sack; HyGoal goal = hy_goal_create(sack); hy_goal_upgrade_all(goal); hy_goal_run(goal); fail_unless(size_and_free(hy_goal_list_upgrades(goal, NULL)) == 5); hy_goal_free(goal); dnf_sack_repo_enabled(sack, "updates", 0); goal = hy_goal_create(sack); hy_goal_upgrade_all(goal); hy_goal_run(goal); assert_iueo(goal, 0, 1, 0, 0); hy_goal_free(goal); }
END_TEST START_TEST(test_goal_clone) { DnfSack *sack = test_globals.sack; HyGoal goal = hy_goal_create(sack); hy_goal_upgrade_all(goal); HyGoal goal2 = hy_goal_clone(goal); fail_if(hy_goal_run(goal)); assert_iueo(goal, 0, 1, 0, 0); fail_unless(size_and_free(hy_goal_list_reinstalls(goal, NULL)) == 1); hy_goal_free(goal); fail_if(hy_goal_run(goal2)); assert_iueo(goal2, 0, 1, 0, 0); fail_unless(size_and_free(hy_goal_list_reinstalls(goal2, NULL)) == 1); hy_goal_free(goal2); }
END_TEST START_TEST(test_goal_erase_with_deps) { DnfSack *sack = test_globals.sack; DnfPackage *pkg = by_name_repo(sack, "penny-lib", HY_SYSTEM_REPO_NAME); // by default can not remove penny-lib, flying depends on it: HyGoal goal = hy_goal_create(sack); hy_goal_erase(goal, pkg); fail_unless(hy_goal_run(goal)); hy_goal_free(goal); goal = hy_goal_create(sack); hy_goal_erase(goal, pkg); fail_if(hy_goal_run_flags(goal, DNF_ALLOW_UNINSTALL)); assert_iueo(goal, 0, 0, 2, 0); hy_goal_free(goal); g_object_unref(pkg); }
END_TEST START_TEST(test_goal_actions) { HyPackage pkg = get_latest_pkg(test_globals.sack, "walrus"); HyGoal goal = hy_goal_create(test_globals.sack); fail_if(hy_goal_has_actions(goal, HY_INSTALL)); fail_if(hy_goal_install(goal, pkg)); fail_unless(hy_goal_has_actions(goal, HY_INSTALL)); hy_package_free(pkg); hy_goal_free(goal); }
END_TEST START_TEST(test_goal_upgrade) { DnfPackage *pkg = get_latest_pkg(test_globals.sack, "fool"); HyGoal goal = hy_goal_create(test_globals.sack); fail_if(hy_goal_upgrade_to_flags(goal, pkg, HY_CHECK_INSTALLED)); g_object_unref(pkg); fail_if(hy_goal_run(goal)); assert_iueo(goal, 0, 1, 0, 1); hy_goal_free(goal); }
END_TEST START_TEST(test_goal_install) { DnfPackage *pkg = get_latest_pkg(test_globals.sack, "walrus"); HyGoal goal = hy_goal_create(test_globals.sack); fail_if(hy_goal_install(goal, pkg)); g_object_unref(pkg); fail_if(hy_goal_run(goal)); assert_iueo(goal, 2, 0, 0, 0); hy_goal_free(goal); }
END_TEST START_TEST(test_goal_actions) { DnfPackage *pkg = get_latest_pkg(test_globals.sack, "walrus"); HyGoal goal = hy_goal_create(test_globals.sack); fail_if(hy_goal_has_actions(goal, DNF_INSTALL)); fail_if(hy_goal_install(goal, pkg)); fail_unless(hy_goal_has_actions(goal, DNF_INSTALL)); g_object_unref(pkg); hy_goal_free(goal); }
static void update(HySack sack, HyPackage pkg) { HyGoal goal = hy_goal_create(sack); if (hy_goal_upgrade_to_flags(goal, pkg, HY_CHECK_INSTALLED)) { printf("no package of that name installed, trying install\n"); hy_goal_install(goal, pkg); } if (hy_goal_run(goal)) { dump_goal_errors(goal); // handle errors goto finish; } // handle upgrades HyPackageList plist = hy_goal_list_upgrades(goal); printf("upgrade count: %d\n", hy_packagelist_count(plist)); for (int i = 0; i < hy_packagelist_count(plist); ++i) { HyPackage pkg = hy_packagelist_get(plist, i); char *nvra = hy_package_get_nevra(pkg); char *location = hy_package_get_location(pkg); HyPackageList obsoleted = hy_goal_list_obsoleted_by_package(goal, pkg); HyPackage installed = hy_packagelist_get(obsoleted, 0); char *nvra_installed = hy_package_get_nevra(installed); printf("upgrading: %s using %s\n", nvra, location); printf("\tfrom: %s\n", nvra_installed); printf("\tsize: %lld kB\n", hy_package_get_size(pkg) / 1024); hy_free(nvra_installed); hy_packagelist_free(obsoleted); hy_free(location); hy_free(nvra); } hy_packagelist_free(plist); // handle installs plist = hy_goal_list_installs(goal); printf("install count: %d\n", hy_packagelist_count(plist)); for (int i = 0; i < hy_packagelist_count(plist); ++i) { HyPackage pkg = hy_packagelist_get(plist, i); char *nvra = hy_package_get_nevra(pkg); char *location = hy_package_get_location(pkg); printf("installing: %s using %s\n", nvra, location); printf("\tsize: %lld kB\n", hy_package_get_size(pkg) / 1024); hy_free(location); hy_free(nvra); } hy_packagelist_free(plist); finish: hy_goal_free(goal); }
END_TEST START_TEST(test_cmdline_file_provides) { HySack sack = test_globals.sack; HyGoal goal = hy_goal_create(sack); hy_goal_upgrade_all(goal); ck_assert(!hy_goal_run_flags(goal, HY_FORCE_BEST)); assert_iueo(goal, 0, 1, 0, 0); hy_goal_free(goal); }
END_TEST START_TEST(test_goal_update_impossible) { DnfPackage *pkg = get_latest_pkg(test_globals.sack, "walrus"); fail_if(pkg == NULL); HyGoal goal = hy_goal_create(test_globals.sack); // can not try an update, walrus is not installed: fail_unless(hy_goal_upgrade_to_flags(goal, pkg, HY_CHECK_INSTALLED)); g_object_unref(pkg); hy_goal_free(goal); }
END_TEST START_TEST(test_cmdline_file_provides) { DnfSack *sack = test_globals.sack; dnf_sack_set_running_kernel_fn(sack, mock_running_kernel_no); HyGoal goal = hy_goal_create(sack); hy_goal_upgrade_all(goal); ck_assert(!hy_goal_run_flags(goal, DNF_FORCE_BEST)); assert_iueo(goal, 0, 1, 0, 0); hy_goal_free(goal); }
END_TEST START_TEST(test_goal_erase_simple) { HySack sack = test_globals.sack; HyPackage pkg = by_name_repo(sack, "penny", HY_SYSTEM_REPO_NAME); HyGoal goal = hy_goal_create(sack); fail_if(hy_goal_erase(goal, pkg)); hy_package_free(pkg); fail_if(hy_goal_run(goal)); assert_iueo(goal, 0, 0, 1, 0); hy_goal_free(goal); }
END_TEST START_TEST(test_goal_no_reinstall) { HySack sack = test_globals.sack; HyPackage pkg = get_latest_pkg(sack, "penny"); HyGoal goal = hy_goal_create(sack); fail_if(hy_goal_install(goal, pkg)); hy_package_free(pkg); fail_if(hy_goal_run(goal)); assert_iueo(goal, 0, 0, 0, 0); hy_goal_free(goal); }
END_TEST START_TEST(test_goal_erase_simple) { DnfSack *sack = test_globals.sack; DnfPackage *pkg = by_name_repo(sack, "penny", HY_SYSTEM_REPO_NAME); HyGoal goal = hy_goal_create(sack); fail_if(hy_goal_erase(goal, pkg)); g_object_unref(pkg); fail_if(hy_goal_run(goal)); assert_iueo(goal, 0, 0, 1, 0); hy_goal_free(goal); }
static void erase(HySack sack, const char *name) { HyQuery q = hy_query_create(sack); hy_query_filter(q, HY_PKG_NAME, HY_EQ, name); hy_query_filter(q, HY_PKG_REPONAME, HY_EQ, HY_SYSTEM_REPO_NAME); HyPackageList plist = hy_query_run(q); if (hy_packagelist_count(plist) < 1) { printf("No installed package to erase found.\n"); goto finish; } if (hy_packagelist_count(plist) > 1) printf("(more than one updatables found, selecting the first one)\n"); HyGoal goal = hy_goal_create(sack); hy_goal_erase(goal, hy_packagelist_get(plist, 0)); if (hy_goal_run(goal)) { dump_goal_errors(goal); hy_goal_free(goal); goto finish; } hy_packagelist_free(plist); plist = hy_goal_list_erasures(goal); printf("erasure count: %d\n", hy_packagelist_count(plist)); for (int i = 0; i < hy_packagelist_count(plist); ++i) { HyPackage pkg = hy_packagelist_get(plist, i); char *nvra = hy_package_get_nevra(pkg); printf("erasing %s\n", nvra); hy_free(nvra); } hy_goal_free(goal); finish: hy_packagelist_free(plist); hy_query_free(q); }
END_TEST START_TEST(test_goal_no_reinstall) { DnfSack *sack = test_globals.sack; DnfPackage *pkg = get_latest_pkg(sack, "penny"); HyGoal goal = hy_goal_create(sack); fail_if(hy_goal_install(goal, pkg)); g_object_unref(pkg); fail_if(hy_goal_run(goal)); assert_iueo(goal, 0, 0, 0, 0); hy_goal_free(goal); }
static void erase(HifSack *sack, const char *name) { HyQuery q = hy_query_create(sack); hy_query_filter(q, HY_PKG_NAME, HY_EQ, name); hy_query_filter(q, HY_PKG_REPONAME, HY_EQ, HY_SYSTEM_REPO_NAME); GPtrArray *plist = hy_query_run(q); if (plist->len < 1) { printf("No installed package to erase found.\n"); goto finish; } if (plist->len > 1) printf("(more than one updatables found, selecting the first one)\n"); HyGoal goal = hy_goal_create(sack); hy_goal_erase(goal, g_ptr_array_index(plist, 0)); if (hy_goal_run(goal)) { dump_goal_errors(goal); hy_goal_free(goal); goto finish; } g_ptr_array_unref(plist); plist = hy_goal_list_erasures(goal, NULL); printf("erasure count: %d\n", plist->len); for (unsigned int i = 0; i < plist->len; ++i) { HifPackage *pkg = g_ptr_array_index(plist, i); const char *nvra = hif_package_get_nevra(pkg); printf("erasing %s\n", nvra); } hy_goal_free(goal); finish: g_ptr_array_unref(plist); hy_query_free(q); }
static void update(HifSack *sack, HifPackage *pkg) { HyGoal goal = hy_goal_create(sack); if (hy_goal_upgrade_to_flags(goal, pkg, HY_CHECK_INSTALLED)) { printf("no package of that name installed, trying install\n"); hy_goal_install(goal, pkg); } if (hy_goal_run(goal)) { dump_goal_errors(goal); // handle errors goto finish; } // handle upgrades GPtrArray *plist = hy_goal_list_upgrades(goal, NULL); printf("upgrade count: %d\n", plist->len); for (unsigned int i = 0; i < plist->len; ++i) { HifPackage *upkg = g_ptr_array_index(plist, i); const char *nvra = hif_package_get_nevra(upkg); char *location = hif_package_get_location(upkg); GPtrArray *obsoleted = hy_goal_list_obsoleted_by_package(goal, upkg); HifPackage *installed = g_ptr_array_index(obsoleted, 0); const char *nvra_installed = hif_package_get_nevra(installed); printf("upgrading: %s using %s\n", nvra, location); printf("\tfrom: %s\n", nvra_installed); printf("\tsize: %lu kB\n", hif_package_get_size(upkg) / 1024); g_ptr_array_unref(obsoleted); g_free(location); } g_ptr_array_unref(plist); // handle installs plist = hy_goal_list_installs(goal, NULL); printf("install count: %d\n", plist->len); for (unsigned int i = 0; i < plist->len; ++i) { HifPackage *ipkg = g_ptr_array_index(plist, i); const char *nvra = hif_package_get_nevra(ipkg); char *location = hif_package_get_location(ipkg); printf("installing: %s using %s\n", nvra, location); printf("\tsize: %lu kB\n", hif_package_get_size(ipkg) / 1024); g_free(location); } g_ptr_array_unref(plist); finish: hy_goal_free(goal); }
END_TEST START_TEST(test_goal_selector_glob) { HySelector sltr = hy_selector_create(test_globals.sack); HyGoal goal = hy_goal_create(test_globals.sack); fail_if(hy_selector_set(sltr, HY_PKG_NAME, HY_GLOB, "*emolin*")); fail_if(!hy_goal_install_selector(goal, sltr, NULL)); fail_if(hy_goal_run(goal)); assert_iueo(goal, 1, 0, 0, 0); hy_goal_free(goal); hy_selector_free(sltr); }
END_TEST START_TEST(test_goal_install_selector_nomatch) { HySelector sltr = hy_selector_create(test_globals.sack); HyGoal goal = hy_goal_create(test_globals.sack); hy_selector_set(sltr, HY_PKG_NAME, HY_EQ, "crabalocker"); fail_if(!hy_goal_install_selector(goal, sltr, NULL)); hy_selector_free(sltr); fail_if(hy_goal_run(goal)); assert_iueo(goal, 0, 0, 0, 0); hy_goal_free(goal); }
END_TEST START_TEST(test_goal_selector_provides_glob) { HySelector sltr = hy_selector_create(test_globals.sack); HyGoal goal = hy_goal_create(test_globals.sack); fail_if(hy_selector_set(sltr, HY_PKG_PROVIDES, HY_GLOB, "P*")); fail_if(hy_goal_erase_selector(goal, sltr)); fail_if(hy_goal_run(goal)); assert_iueo(goal, 0, 0, 1, 0); hy_goal_free(goal); hy_selector_free(sltr); }
END_TEST START_TEST(test_goal_kernel_protected) { DnfSack *sack = test_globals.sack; dnf_sack_set_running_kernel_fn(sack, mock_running_kernel); Id kernel_id = mock_running_kernel(sack); DnfPackage *kernel = dnf_package_new(sack, kernel_id); HyGoal goal = hy_goal_create(sack); hy_goal_erase(goal, kernel); fail_unless(hy_goal_run_flags(goal, 0)); g_object_unref(kernel); hy_goal_free(goal); }
END_TEST START_TEST(test_goal_forcebest_arches) { DnfSack *sack = test_globals.sack; HyGoal goal = hy_goal_create(sack); HySelector sltr = hy_selector_create(sack); hy_selector_set(sltr, HY_PKG_NAME, HY_EQ, "gun"); fail_if(hy_goal_upgrade_selector(goal, sltr)); fail_if(hy_goal_run_flags(goal, DNF_FORCE_BEST)); assert_iueo(goal, 0, 0, 0, 0); hy_selector_free(sltr); hy_goal_free(goal); }
END_TEST START_TEST(test_goal_forcebest) { DnfSack *sack = test_globals.sack; HyGoal goal = hy_goal_create(sack); HySelector sltr = hy_selector_create(sack); hy_selector_set(sltr, HY_PKG_NAME, HY_EQ, "flying"); hy_goal_upgrade_selector(goal, sltr); fail_unless(hy_goal_run_flags(goal, DNF_FORCE_BEST)); fail_unless(hy_goal_count_problems(goal) == 1); hy_selector_free(sltr); hy_goal_free(goal); }
END_TEST START_TEST(test_goal_change) { // test that changes are handled like reinstalls DnfSack *sack = test_globals.sack; HyGoal goal = hy_goal_create(sack); hy_goal_upgrade_all(goal); fail_if(hy_goal_run(goal)); assert_iueo(goal, 0, 1, 0, 0); fail_unless(size_and_free(hy_goal_list_reinstalls(goal, NULL)) == 1); hy_goal_free(goal); }
END_TEST START_TEST(test_goal_installonly) { const char *installonly[] = {"fool", NULL}; DnfSack *sack = test_globals.sack; dnf_sack_set_installonly(sack, installonly); dnf_sack_set_installonly_limit(sack, 2); DnfPackage *pkg = get_latest_pkg(sack, "fool"); HyGoal goal = hy_goal_create(sack); fail_if(hy_goal_upgrade_to_flags(goal, pkg, HY_CHECK_INSTALLED)); g_object_unref(pkg); fail_if(hy_goal_run(goal)); assert_iueo(goal, 1, 0, 1, 0); hy_goal_free(goal); }