[gnome-software: 12/15] dummy: Remove an environment variable for setting unit test behaviour




commit f3feb9810386df4abc5b3f8cc5185a55686debe5
Author: Philip Withnall <pwithnall endlessos org>
Date:   Wed May 4 11:55:43 2022 +0100

    dummy: Remove an environment variable for setting unit test behaviour
    
    Instead hackily use the max-results query property. We can’t use an
    environment variable because setting them is not thread-safe (and it
    can’t be made thread-safe without modifying libc).
    
    Drop the second hard-coded app from the dummy plugin, as the wildcard
    app now successfully matches against `zeus.desktop` from the appstream
    plugin. The previous setup, where `GNOME_SOFTWARE_POPULAR` overrode all
    the results from the `GsPluginLoader`, couldn’t do this as it overrode
    the results from the appstream plugin.
    
    Signed-off-by: Philip Withnall <pwithnall endlessos org>
    
    Helps: #1472

 plugins/dummy/gs-plugin-dummy.c | 22 +++++++---------------
 plugins/dummy/gs-self-test.c    | 17 +++++++----------
 2 files changed, 14 insertions(+), 25 deletions(-)
---
diff --git a/plugins/dummy/gs-plugin-dummy.c b/plugins/dummy/gs-plugin-dummy.c
index 792ae5e2f..e618912fa 100644
--- a/plugins/dummy/gs-plugin-dummy.c
+++ b/plugins/dummy/gs-plugin-dummy.c
@@ -869,6 +869,7 @@ gs_plugin_dummy_list_apps_async (GsPlugin              *plugin,
        g_autoptr(GsAppList) list = gs_app_list_new ();
        GDateTime *released_since = NULL;
        GsAppQueryTristate is_curated = GS_APP_QUERY_TRISTATE_UNSET;
+       guint max_results = 0;
 
        task = g_task_new (plugin, cancellable, callback, user_data);
        g_task_set_source_tag (task, gs_plugin_dummy_list_apps_async);
@@ -876,6 +877,7 @@ gs_plugin_dummy_list_apps_async (GsPlugin              *plugin,
        if (query != NULL) {
                released_since = gs_app_query_get_released_since (query);
                is_curated = gs_app_query_get_is_curated (query);
+               max_results = gs_app_query_get_max_results (query);
        }
 
        /* Currently only support released-since or is-curated queries (but not both).
@@ -905,14 +907,12 @@ gs_plugin_dummy_list_apps_async (GsPlugin              *plugin,
        if (is_curated != GS_APP_QUERY_TRISTATE_UNSET) {
                g_autoptr(GsApp) app1 = NULL;
                g_autoptr(GsApp) app2 = NULL;
-               g_auto(GStrv) apps = NULL;
 
-               if (g_getenv ("GNOME_SOFTWARE_POPULAR") != NULL) {
-                       apps = g_strsplit (g_getenv ("GNOME_SOFTWARE_POPULAR"), ",", 0);
-               }
-
-               if (apps != NULL && g_strv_length (apps) > 0) {
-                       for (gsize i = 0; apps[i] != NULL; i++) {
+               /* Hacky way of letting callers indicate which set of results
+                * they want, for unit testing. */
+               if (max_results == 6) {
+                       const gchar *apps[] = { "chiron.desktop", "zeus.desktop" };
+                       for (gsize i = 0; i < G_N_ELEMENTS (apps); i++) {
                                g_autoptr(GsApp) app = gs_app_new (apps[i]);
                                gs_app_add_quirk (app, GS_APP_QUIRK_IS_WILDCARD);
                                gs_app_list_add (list, app);
@@ -924,14 +924,6 @@ gs_plugin_dummy_list_apps_async (GsPlugin              *plugin,
                        gs_app_set_metadata (app1, "GnomeSoftware::Creator",
                                             gs_plugin_get_name (plugin));
                        gs_app_list_add (list, app1);
-
-                       /* add again, this time with a prefix so it gets deduplicated */
-                       app2 = gs_app_new ("zeus.desktop");
-                       gs_app_set_scope (app2, AS_COMPONENT_SCOPE_USER);
-                       gs_app_set_bundle_kind (app2, AS_BUNDLE_KIND_SNAP);
-                       gs_app_set_metadata (app2, "GnomeSoftware::Creator",
-                                            gs_plugin_get_name (plugin));
-                       gs_app_list_add (list, app2);
                }
        }
 
diff --git a/plugins/dummy/gs-self-test.c b/plugins/dummy/gs-self-test.c
index 010e822f4..38fc26e04 100644
--- a/plugins/dummy/gs-self-test.c
+++ b/plugins/dummy/gs-self-test.c
@@ -575,13 +575,13 @@ gs_plugins_dummy_wildcard_func (GsPluginLoader *plugin_loader)
        g_autoptr(GError) error = NULL;
        g_autoptr(GsAppList) list1 = NULL;
        g_autoptr(GsAppList) list2 = NULL;
-       const gchar *popular_override = "chiron.desktop,zeus.desktop";
-       g_auto(GStrv) apps = NULL;
+       const gchar *expected_apps2[] = { "chiron.desktop", "zeus.desktop", NULL };
        g_autoptr(GsPluginJob) plugin_job = NULL;
        g_autoptr(GsAppQuery) query = NULL;
 
-       /* use the plugin's default curated list */
+       /* use the plugin's default curated list, indicated by setting max-results=5 */
        query = gs_app_query_new ("is-curated", GS_APP_QUERY_TRISTATE_TRUE,
+                                 "max-results", 5,
                                  "refine-flags", GS_PLUGIN_REFINE_FLAGS_REQUIRE_ICON,
                                  NULL);
        plugin_job = gs_plugin_job_list_apps_new (query, GS_PLUGIN_LIST_APPS_FLAGS_NONE);
@@ -591,13 +591,12 @@ gs_plugins_dummy_wildcard_func (GsPluginLoader *plugin_loader)
        g_assert_no_error (error);
        g_assert (list1 != NULL);
        g_assert_cmpint (gs_app_list_length (list1), ==, 1);
-
-       /* override the list */
-       g_setenv ("GNOME_SOFTWARE_POPULAR", popular_override, TRUE);
        g_object_unref (plugin_job);
        g_object_unref (query);
 
+       /* use the plugin’s second list, indicated by setting max-results=6 */
        query = gs_app_query_new ("is-curated", GS_APP_QUERY_TRISTATE_TRUE,
+                                 "max-results", 6,
                                  "refine-flags", GS_PLUGIN_REFINE_FLAGS_REQUIRE_ICON,
                                  NULL);
        plugin_job = gs_plugin_job_list_apps_new (query, GS_PLUGIN_LIST_APPS_FLAGS_NONE);
@@ -607,12 +606,11 @@ gs_plugins_dummy_wildcard_func (GsPluginLoader *plugin_loader)
        g_assert_no_error (error);
        g_assert (list2 != NULL);
 
-       apps = g_strsplit (popular_override, ",", 0);
-       g_assert_cmpint (gs_app_list_length (list2), ==, g_strv_length (apps));
+       g_assert_cmpint (gs_app_list_length (list2), ==, g_strv_length ((gchar **) expected_apps2));
 
        for (guint i = 0; i < gs_app_list_length (list2); ++i) {
                GsApp *app = gs_app_list_index (list2, i);
-               g_assert (g_strv_contains ((const gchar * const *) apps, gs_app_get_id (app)));
+               g_assert (g_strv_contains (expected_apps2, gs_app_get_id (app)));
        }
 }
 
@@ -768,7 +766,6 @@ main (int argc, char **argv)
        g_setenv ("GS_SELF_TEST_PROVENANCE_SOURCES", "london*,boston", TRUE);
        g_setenv ("GS_SELF_TEST_PROVENANCE_LICENSE_SOURCES", "london*,boston", TRUE);
        g_setenv ("GS_SELF_TEST_PROVENANCE_LICENSE_URL", "https://www.debian.org/";, TRUE);
-       g_setenv ("GNOME_SOFTWARE_POPULAR", "", TRUE);
 
        /* Use a common cache directory for all tests, since the appstream
         * plugin uses it and cannot be reinitialised for each test. */


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]