Ejemplo n.º 1
0
END_TEST

START_TEST(test_sack_create)
{
    g_autoptr(HifSack) sack = hif_sack_new();
    hif_sack_set_cachedir(sack, test_globals.tmpdir);
    fail_unless(hif_sack_setup(sack, HIF_SACK_SETUP_FLAG_MAKE_CACHE_DIR, NULL));
    fail_if(sack == NULL, NULL);
    fail_if(hif_sack_get_pool(sack) == NULL, NULL);
}
Ejemplo n.º 2
0
END_TEST

START_TEST(test_filelist_from_cache)
{
    HifSack *sack = hif_sack_new();
    hif_sack_set_cachedir(sack, test_globals.tmpdir);
    fail_unless(hif_sack_setup(sack, HIF_SACK_SETUP_FLAG_MAKE_CACHE_DIR, NULL));
    setup_yum_sack(sack, YUM_REPO_NAME);

    HyRepo repo = hrepo_by_name(sack, YUM_REPO_NAME);
    fail_unless(repo->state_filelists == _HY_LOADED_CACHE);
    check_filelist(hif_sack_get_pool(sack));
    g_object_unref(sack);
}
Ejemplo n.º 3
0
END_TEST

START_TEST(test_sack_create)
{
    g_autoptr(GError) error = NULL;
    HifSack *sack = hif_sack_new();
    hif_sack_set_cachedir(sack, test_globals.tmpdir);
    fail_unless(hif_sack_setup(sack, HIF_SACK_SETUP_FLAG_MAKE_CACHE_DIR, NULL));
    fail_if(sack == NULL, NULL);
    fail_if(hif_sack_get_pool(sack) == NULL, NULL);
    g_object_unref(sack);

    sack = hif_sack_new ();
    fail_if(hif_sack_set_arch(sack, "", &error));
    fail_if(error == NULL);
}
Ejemplo n.º 4
0
END_TEST

START_TEST(test_load_repo_err)
{
    g_autoptr(GError) error = NULL;
    HifSack *sack = hif_sack_new();
    hif_sack_set_cachedir(sack, test_globals.tmpdir);
    fail_unless(hif_sack_setup(sack, HIF_SACK_SETUP_FLAG_MAKE_CACHE_DIR, &error));
    g_assert(sack != NULL);
    HyRepo repo = hy_repo_create("crabalocker");
    g_assert(repo != NULL);
    hy_repo_set_string(repo, HY_REPO_MD_FN, "/non/existing");
    fail_unless(!hif_sack_load_repo(sack, repo, 0, &error));
    fail_unless(g_error_matches (error, HIF_ERROR, HIF_ERROR_FILE_INVALID));
    hy_repo_free(repo);
    g_object_unref(sack);
}
Ejemplo n.º 5
0
END_TEST

START_TEST(test_list_arches)
{
    HifSack *sack = hif_sack_new();
    hif_sack_set_cachedir(sack, test_globals.tmpdir);
    hif_sack_set_arch(sack, TEST_FIXED_ARCH, NULL);
    fail_unless(hif_sack_setup(sack, HIF_SACK_SETUP_FLAG_MAKE_CACHE_DIR, NULL));
    const char ** arches = hif_sack_list_arches(sack);

    /* noarch, x86_64, athlon, i686, i586, i486, i386 */
    fail_unless(g_strv_length((gchar**)arches), 7);
    ck_assert_str_eq(arches[3], "i686");

    g_free(arches);
    g_object_unref(sack);
}
Ejemplo n.º 6
0
END_TEST

START_TEST(test_give_cache_fn)
{
    HifSack *sack = hif_sack_new();
    hif_sack_set_cachedir(sack, test_globals.tmpdir);
    fail_unless(hif_sack_setup(sack, HIF_SACK_SETUP_FLAG_MAKE_CACHE_DIR, NULL));

    char *path = hif_sack_give_cache_fn(sack, "rain", NULL);
    fail_if(strstr(path, "rain.solv") == NULL);
    g_free(path);

    path = hif_sack_give_cache_fn(sack, "rain", HY_EXT_FILENAMES);
    fail_if(strstr(path, "rain-filenames.solvx") == NULL);
    g_free(path);
    g_object_unref(sack);
}
Ejemplo n.º 7
0
END_TEST

START_TEST(test_repo_written)
{
    HifSack *sack = hif_sack_new();
    hif_sack_set_cachedir(sack, test_globals.tmpdir);
    fail_unless(hif_sack_setup(sack, HIF_SACK_SETUP_FLAG_MAKE_CACHE_DIR, NULL));
    char *filename = hif_sack_give_cache_fn(sack, "test_sack_written", NULL);

    fail_unless(access(filename, R_OK|W_OK));
    setup_yum_sack(sack, "test_sack_written");

    HyRepo repo = hrepo_by_name(sack, "test_sack_written");
    fail_if(repo == NULL);
    fail_unless(repo->state_main == _HY_WRITTEN);
    fail_unless(repo->state_filelists == _HY_WRITTEN);
    fail_unless(repo->state_presto == _HY_WRITTEN);
    fail_if(access(filename, R_OK|W_OK));

    g_free(filename);
    g_object_unref(sack);
}
Ejemplo n.º 8
0
END_TEST

START_TEST(test_add_cmdline_package)
{
    HifSack *sack = hif_sack_new();
    hif_sack_set_cachedir(sack, test_globals.tmpdir);

    char *path_mystery = solv_dupjoin(TESTDATADIR, "/hawkey/yum/mystery-devel-19.67-1.noarch.rpm", NULL);
    HifPackage *pkg_mystery = hif_sack_add_cmdline_package(sack, path_mystery);
    char *location_mystery = hif_package_get_location(pkg_mystery);
    ck_assert_str_eq(path_mystery, location_mystery);

    char *path_tour = solv_dupjoin(TESTDATADIR, "/hawkey/yum/tour-4-6.noarch.rpm", NULL);
    HifPackage *pkg_tour = hif_sack_add_cmdline_package(sack, path_tour);
    char *location_tour = hif_package_get_location(pkg_tour);
    ck_assert_str_eq(path_tour, location_tour);

    g_free(path_mystery);
    g_free(location_mystery);
    g_free(path_tour);
    g_free(location_tour);
    g_object_unref(sack);
}
Ejemplo n.º 9
0
static int
sack_init(_SackObject *self, PyObject *args, PyObject *kwds)
{
    g_autoptr(GError) error = NULL;
    PyObject *custom_class = NULL;
    PyObject *custom_val = NULL;
    const char *cachedir = NULL;
    const char *arch = NULL;
    const char *rootdir = NULL;
    PyObject *tmp_py_str = NULL;
    PyObject *tmp2_py_str = NULL;
    PyObject *cachedir_py = NULL;
    int make_cache_dir = 0;
    const char *kwlist[] = {"cachedir", "arch", "rootdir", "pkgcls",
                      "pkginitval", "make_cache_dir", NULL};

    if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OssOOi", (char**) kwlist,
                                     &cachedir_py, &arch, &rootdir,
                                     &custom_class, &custom_val,
                                     &make_cache_dir))
        return -1;
    if (cachedir_py != NULL)
        cachedir = pycomp_get_string(cachedir_py, &tmp_py_str);
    int flags = 0;
    if (make_cache_dir)
        flags |= HIF_SACK_SETUP_FLAG_MAKE_CACHE_DIR;
    self->sack = hif_sack_new();
    Py_XDECREF(tmp_py_str);
    Py_XDECREF(tmp2_py_str);
    if (!hif_sack_set_arch(self->sack, arch, &error)) {
        PyErr_SetString(HyExc_Arch, "Unrecognized arch for the sack.");
        return -1;
    }
    hif_sack_set_rootdir(self->sack, rootdir);
    hif_sack_set_cachedir(self->sack, cachedir);
    if (!hif_sack_setup(self->sack, flags, &error)) {
        switch (error->code) {
        case HIF_ERROR_FILE_INVALID:
            PyErr_SetString(PyExc_IOError,
                            "Failed creating working files for the Sack.");
            break;
        case HIF_ERROR_INVALID_ARCHITECTURE:
            PyErr_SetString(HyExc_Arch, "Unrecognized arch for the sack.");
            break;
        default:
            assert(0);
        }
        return -1;
    }

    if (custom_class && custom_class != Py_None) {
        if (!PyType_Check(custom_class)) {
            PyErr_SetString(PyExc_TypeError, "Expected a class object.");
            return -1;
        }
        Py_INCREF(custom_class);
        self->custom_package_class = custom_class;
    }
    if (custom_val && custom_val != Py_None) {
        Py_INCREF(custom_val);
        self->custom_package_val = custom_val;

    }
    return 0;
}