[Libosinfo] [PATCH] tests: add one test case per OS tested
Daniel P. Berrangé
berrange at redhat.com
Mon Feb 4 11:18:08 UTC 2019
The image, media & tree URIs test suites just register one test case for
all the work they do. As a result when they run they just sit there
printing no progress information for a long time.
This changes then to register one test case per OS in the database. As a
result we get progress information. An added benefit is that it is
possible to now run tests for individual OS by passing the -p argument.
Signed-off-by: Daniel P. Berrangé <berrange at redhat.com>
---
tests/test-imageuris.c | 62 ++++++++++++++++++++++-------------------
tests/test-mediauris.c | 63 +++++++++++++++++++++++-------------------
tests/test-treeuris.c | 62 ++++++++++++++++++++++-------------------
3 files changed, 100 insertions(+), 87 deletions(-)
diff --git a/tests/test-imageuris.c b/tests/test-imageuris.c
index 775e80f..d58df02 100644
--- a/tests/test-imageuris.c
+++ b/tests/test-imageuris.c
@@ -64,14 +64,11 @@ static void test_image(OsinfoImageList *imagelist, GError **error, CURL *curl)
}
static void
-test_uris(void)
+test_uris(gconstpointer data)
{
+ OsinfoOs *os = OSINFO_OS(data);
CURL *curl;
- OsinfoLoader *loader = osinfo_loader_new();
- OsinfoDb *db = osinfo_loader_get_db(loader);
GError *error = NULL;
- OsinfoOsList *oslist = NULL;
- GList *osel = NULL, *tmp;
const gchar *debugstr;
curl = curl_easy_init();
@@ -87,33 +84,15 @@ test_uris(void)
curl_easy_setopt(curl, CURLOPT_VERBOSE, debug_level > 0 ? 1L : 0L);
}
- g_assert_true(OSINFO_IS_LOADER(loader));
- g_assert_true(OSINFO_IS_DB(db));
-
- osinfo_loader_process_default_path(loader, &error);
- g_assert_no_error(error);
-
- oslist = osinfo_db_get_os_list(db);
- tmp = osel = osinfo_list_get_elements(OSINFO_LIST(oslist));
- while (tmp) {
- OsinfoOs *os = tmp->data;
- OsinfoImageList *imagelist = osinfo_os_get_image_list(os);
+ OsinfoImageList *imagelist = osinfo_os_get_image_list(os);
- test_image(imagelist, &error, curl);
+ test_image(imagelist, &error, curl);
- g_assert_no_error(error);
+ g_assert_no_error(error);
- g_object_unref(imagelist);
- tmp = tmp->next;
- }
+ g_object_unref(imagelist);
curl_easy_cleanup(curl);
-
- g_list_free(osel);
- if (oslist)
- g_object_unref(oslist);
-
- g_object_unref(loader);
}
@@ -122,12 +101,15 @@ int
main(int argc, char *argv[])
{
int ret;
+ OsinfoLoader *loader = osinfo_loader_new();
+ OsinfoDb *db = osinfo_loader_get_db(loader);
+ OsinfoOsList *oslist = NULL;
+ GList *osel = NULL, *tmp;
+ GError *error = NULL;
g_test_init(&argc, &argv, NULL);
g_test_set_nonfatal_assertions();
- g_test_add_func("/imageuris/uris", test_uris);
-
if (!g_getenv("LIBOSINFO_NETWORK_TESTS"))
return 77; /* Skip */
@@ -139,8 +121,30 @@ main(int argc, char *argv[])
osinfo_oslist_get_type();
osinfo_filter_get_type();
+ osinfo_loader_process_default_path(loader, &error);
+ g_assert_no_error(error);
+
+ oslist = osinfo_db_get_os_list(db);
+ tmp = osel = osinfo_list_get_elements(OSINFO_LIST(oslist));
+ while (tmp) {
+ OsinfoOs *os = tmp->data;
+ gchar *name = g_strdup_printf("/imageuris/uris/%s",
+ osinfo_product_get_short_id(OSINFO_PRODUCT(os)));
+
+ g_test_add_data_func(name, os, test_uris);
+ g_free(name);
+
+ tmp = tmp->next;
+ }
+
ret = g_test_run();
+ g_list_free(osel);
+ if (oslist)
+ g_object_unref(oslist);
+
+ g_object_unref(loader);
+
curl_global_cleanup();
return ret;
diff --git a/tests/test-mediauris.c b/tests/test-mediauris.c
index 220dfb8..c5cde0d 100644
--- a/tests/test-mediauris.c
+++ b/tests/test-mediauris.c
@@ -64,14 +64,11 @@ static void test_media(OsinfoMediaList *medialist, GError **error, CURL *curl)
}
static void
-test_uris(void)
+test_uris(gconstpointer data)
{
+ OsinfoOs *os = OSINFO_OS(data);
CURL *curl;
- OsinfoLoader *loader = osinfo_loader_new();
- OsinfoDb *db = osinfo_loader_get_db(loader);
GError *error = NULL;
- OsinfoOsList *oslist = NULL;
- GList *osel = NULL, *tmp;
const gchar *debugstr;
curl = curl_easy_init();
@@ -87,33 +84,15 @@ test_uris(void)
curl_easy_setopt(curl, CURLOPT_VERBOSE, debug_level > 0 ? 1L : 0L);
}
- g_assert_true(OSINFO_IS_LOADER(loader));
- g_assert_true(OSINFO_IS_DB(db));
-
- osinfo_loader_process_default_path(loader, &error);
- g_assert_no_error(error);
-
- oslist = osinfo_db_get_os_list(db);
- tmp = osel = osinfo_list_get_elements(OSINFO_LIST(oslist));
- while (tmp) {
- OsinfoOs *os = tmp->data;
- OsinfoMediaList *medialist = osinfo_os_get_media_list(os);
+ OsinfoMediaList *medialist = osinfo_os_get_media_list(os);
- test_media(medialist, &error, curl);
+ test_media(medialist, &error, curl);
- g_assert_no_error(error);
+ g_assert_no_error(error);
- g_object_unref(medialist);
- tmp = tmp->next;
- }
+ g_object_unref(medialist);
curl_easy_cleanup(curl);
-
- g_list_free(osel);
- if (oslist)
- g_object_unref(oslist);
-
- g_object_unref(loader);
}
@@ -122,12 +101,15 @@ int
main(int argc, char *argv[])
{
int ret;
+ OsinfoLoader *loader = osinfo_loader_new();
+ OsinfoDb *db = osinfo_loader_get_db(loader);
+ OsinfoOsList *oslist = NULL;
+ GList *osel = NULL, *tmp;
+ GError *error = NULL;
g_test_init(&argc, &argv, NULL);
g_test_set_nonfatal_assertions();
- g_test_add_func("/mediauris/uris", test_uris);
-
if (!g_getenv("LIBOSINFO_NETWORK_TESTS"))
return 77; /* Skip */
@@ -144,8 +126,31 @@ main(int argc, char *argv[])
osinfo_oslist_get_type();
osinfo_filter_get_type();
+
+ osinfo_loader_process_default_path(loader, &error);
+ g_assert_no_error(error);
+
+ oslist = osinfo_db_get_os_list(db);
+ tmp = osel = osinfo_list_get_elements(OSINFO_LIST(oslist));
+ while (tmp) {
+ OsinfoOs *os = tmp->data;
+ gchar *name = g_strdup_printf("/mediauris/uris/%s",
+ osinfo_product_get_short_id(OSINFO_PRODUCT(os)));
+
+ g_test_add_data_func(name, os, test_uris);
+ g_free(name);
+
+ tmp = tmp->next;
+ }
+
ret = g_test_run();
+ g_list_free(osel);
+ if (oslist)
+ g_object_unref(oslist);
+
+ g_object_unref(loader);
+
curl_global_cleanup();
return ret;
diff --git a/tests/test-treeuris.c b/tests/test-treeuris.c
index 26c949b..547696b 100644
--- a/tests/test-treeuris.c
+++ b/tests/test-treeuris.c
@@ -64,14 +64,11 @@ static void test_tree(OsinfoTreeList *treelist, GError **error, CURL *curl)
}
static void
-test_uris(void)
+test_uris(gconstpointer data)
{
+ OsinfoOs *os = OSINFO_OS(data);
CURL *curl;
- OsinfoLoader *loader = osinfo_loader_new();
- OsinfoDb *db = osinfo_loader_get_db(loader);
GError *error = NULL;
- OsinfoOsList *oslist = NULL;
- GList *osel = NULL, *tmp;
const gchar *debugstr;
curl = curl_easy_init();
@@ -87,33 +84,15 @@ test_uris(void)
curl_easy_setopt(curl, CURLOPT_VERBOSE, debug_level > 0 ? 1L : 0L);
}
- g_assert_true(OSINFO_IS_LOADER(loader));
- g_assert_true(OSINFO_IS_DB(db));
-
- osinfo_loader_process_default_path(loader, &error);
- g_assert_no_error(error);
-
- oslist = osinfo_db_get_os_list(db);
- tmp = osel = osinfo_list_get_elements(OSINFO_LIST(oslist));
- while (tmp) {
- OsinfoOs *os = tmp->data;
- OsinfoTreeList *treelist = osinfo_os_get_tree_list(os);
+ OsinfoTreeList *treelist = osinfo_os_get_tree_list(os);
- test_tree(treelist, &error, curl);
+ test_tree(treelist, &error, curl);
- g_assert_no_error(error);
+ g_assert_no_error(error);
- g_object_unref(treelist);
- tmp = tmp->next;
- }
+ g_object_unref(treelist);
curl_easy_cleanup(curl);
-
- g_list_free(osel);
- if (oslist)
- g_object_unref(oslist);
-
- g_object_unref(loader);
}
@@ -122,12 +101,15 @@ int
main(int argc, char *argv[])
{
int ret;
+ OsinfoLoader *loader = osinfo_loader_new();
+ OsinfoDb *db = osinfo_loader_get_db(loader);
+ OsinfoOsList *oslist = NULL;
+ GList *osel = NULL, *tmp;
+ GError *error = NULL;
g_test_init(&argc, &argv, NULL);
g_test_set_nonfatal_assertions();
- g_test_add_func("/treeuris/uris", test_uris);
-
if (!g_getenv("LIBOSINFO_NETWORK_TESTS"))
return 77; /* Skip */
@@ -144,8 +126,30 @@ main(int argc, char *argv[])
osinfo_oslist_get_type();
osinfo_filter_get_type();
+ osinfo_loader_process_default_path(loader, &error);
+ g_assert_no_error(error);
+
+ oslist = osinfo_db_get_os_list(db);
+ tmp = osel = osinfo_list_get_elements(OSINFO_LIST(oslist));
+ while (tmp) {
+ OsinfoOs *os = tmp->data;
+ gchar *name = g_strdup_printf("/treeuris/uris/%s",
+ osinfo_product_get_short_id(OSINFO_PRODUCT(os)));
+
+ g_test_add_data_func(name, os, test_uris);
+ g_free(name);
+
+ tmp = tmp->next;
+ }
+
ret = g_test_run();
+ g_list_free(osel);
+ if (oslist)
+ g_object_unref(oslist);
+
+ g_object_unref(loader);
+
curl_global_cleanup();
return ret;
--
2.20.1
More information about the Libosinfo
mailing list