[gnome-software/wip/jrocha/fix-runtime-extensions-update: 1/3] tests: Cover installing an app that has a mandatory extension



commit 3f8d724925f8d0cc06a5c6780f6abd48f53e3f2d
Author: Joaquim Rocha <jrocha endlessm com>
Date:   Mon Nov 6 14:56:16 2017 +0100

    tests: Cover installing an app that has a mandatory extension
    
    GNOME Software already installs extensions that should be installed
    together with apps. This patch covers that as well as the removal of
    such extensions.

 lib/gs-plugin-loader.c                    |  15 ++++
 lib/gs-plugin-loader.h                    |   1 +
 plugins/flatpak/gs-self-test.c            | 136 ++++++++++++++++++++++++++++++
 plugins/flatpak/tests/build.py            |  21 ++++-
 plugins/flatpak/tests/flatpakrepos.tar.gz | Bin 37465 -> 43104 bytes
 5 files changed, 170 insertions(+), 3 deletions(-)
---
diff --git a/lib/gs-plugin-loader.c b/lib/gs-plugin-loader.c
index 8ed0833d..1c0dd843 100644
--- a/lib/gs-plugin-loader.c
+++ b/lib/gs-plugin-loader.c
@@ -3687,4 +3687,19 @@ gs_plugin_loader_get_profile (GsPluginLoader *plugin_loader)
        return priv->profile;
 }
 
+/**
+ * gs_plugin_loader_get_global_cache:
+ * @plugin_loader: a #GsPluginLoader
+ *
+ * Returns the global cache.
+ *
+ * Returns: (transfer none): a #GsAppList
+ **/
+GsAppList *
+gs_plugin_loader_get_global_cache (GsPluginLoader *plugin_loader)
+{
+       GsPluginLoaderPrivate *priv = gs_plugin_loader_get_instance_private (plugin_loader);
+       return priv->global_cache;
+}
+
 /* vim: set noexpandtab: */
diff --git a/lib/gs-plugin-loader.h b/lib/gs-plugin-loader.h
index c4d9921b..7a4a2fc3 100644
--- a/lib/gs-plugin-loader.h
+++ b/lib/gs-plugin-loader.h
@@ -109,6 +109,7 @@ void                 gs_plugin_loader_setup_again           (GsPluginLoader 
*plugin_loader);
 void            gs_plugin_loader_clear_caches          (GsPluginLoader *plugin_loader);
 GsPlugin       *gs_plugin_loader_find_plugin           (GsPluginLoader *plugin_loader,
                                                         const gchar    *plugin_name);
+GsAppList      *gs_plugin_loader_get_global_cache      (GsPluginLoader *plugin_loader);
 
 
 G_END_DECLS
diff --git a/plugins/flatpak/gs-self-test.c b/plugins/flatpak/gs-self-test.c
index d2110fc3..d24d7e87 100644
--- a/plugins/flatpak/gs-self-test.c
+++ b/plugins/flatpak/gs-self-test.c
@@ -1280,6 +1280,7 @@ gs_plugins_flatpak_app_update_func (GsPluginLoader *plugin_loader)
        }
 
        /* add indirection so we can switch this after install */
+       unlink ("/var/tmp/self-test/repo");
        g_assert (symlink (repodir1_fn, "/var/tmp/self-test/repo") == 0);
 
        /* add a remote */
@@ -1461,6 +1462,138 @@ gs_plugins_flatpak_app_update_func (GsPluginLoader *plugin_loader)
        g_assert_cmpint (gs_app_get_state (app_source), ==, AS_APP_STATE_AVAILABLE);
 }
 
+static void
+gs_plugins_flatpak_runtime_extension_func (GsPluginLoader *plugin_loader)
+{
+       GsApp *app;
+       GsApp *runtime;
+       GsApp *extension;
+       gboolean ret;
+       g_autofree gchar *repodir1_fn = NULL;
+       g_autoptr(GError) error = NULL;
+       g_autoptr(GsApp) app_source = NULL;
+       g_autoptr(GsAppList) list = NULL;
+       g_autoptr(GsAppList) list_updates = NULL;
+       g_autoptr(GsPluginJob) plugin_job = NULL;
+       g_autoptr(GMainLoop) loop = g_main_loop_new (NULL, FALSE);
+       GsAppList *global_cache = NULL;
+
+       /* drop all caches */
+       gs_plugin_loader_setup_again (plugin_loader);
+
+       /* no flatpak, abort */
+       g_assert_true (gs_plugin_loader_get_enabled (plugin_loader, "flatpak"));
+
+       /* no files to use */
+       repodir1_fn = gs_test_get_filename (TESTDATADIR, "app-extension/repo");
+       if (repodir1_fn == NULL ||
+           !g_file_test (repodir1_fn, G_FILE_TEST_EXISTS)) {
+               g_test_skip ("no flatpak test repo");
+               return;
+       }
+
+       /* add indirection so we can switch this after install */
+       g_assert_cmpint (symlink (repodir1_fn, "/var/tmp/self-test/repo"), ==, 0);
+
+       /* add a remote */
+       app_source = gs_flatpak_app_new ("test");
+       gs_app_set_kind (app_source, AS_APP_KIND_SOURCE);
+       gs_app_set_management_plugin (app_source, "flatpak");
+       gs_app_set_state (app_source, AS_APP_STATE_AVAILABLE);
+       gs_flatpak_app_set_repo_url (app_source, "file:///var/tmp/self-test/repo");
+       plugin_job = gs_plugin_job_newv (GS_PLUGIN_ACTION_INSTALL,
+                                        "app", app_source,
+                                        NULL);
+       ret = gs_plugin_loader_job_action (plugin_loader, plugin_job, NULL, &error);
+       gs_test_flush_main_context ();
+       g_assert_no_error (error);
+       g_assert_true (ret);
+       g_assert_cmpint (gs_app_get_state (app_source), ==, AS_APP_STATE_INSTALLED);
+
+       /* refresh the appstream metadata */
+       g_object_unref (plugin_job);
+       plugin_job = gs_plugin_job_newv (GS_PLUGIN_ACTION_REFRESH,
+                                        "age", (guint64) G_MAXUINT,
+                                        "refresh-flags", GS_PLUGIN_REFRESH_FLAGS_METADATA,
+                                        NULL);
+       ret = gs_plugin_loader_job_action (plugin_loader, plugin_job, NULL, &error);
+       gs_test_flush_main_context ();
+       g_assert_no_error (error);
+       g_assert_true (ret);
+
+       /* find available application */
+       g_object_unref (plugin_job);
+       plugin_job = gs_plugin_job_newv (GS_PLUGIN_ACTION_SEARCH,
+                                        "search", "Bingo",
+                                        "refine-flags", GS_PLUGIN_REFINE_FLAGS_REQUIRE_ICON,
+                                        NULL);
+       list = gs_plugin_loader_job_process (plugin_loader, plugin_job, NULL, &error);
+       gs_test_flush_main_context ();
+       g_assert_no_error (error);
+       g_assert_nonnull (list);
+
+       /* make sure there is one entry, the flatpak app */
+       g_assert_cmpint (gs_app_list_length (list), ==, 1);
+       app = gs_app_list_index (list, 0);
+       g_assert_cmpstr (gs_app_get_id (app), ==, "org.test.Chiron.desktop");
+       g_assert_cmpint (gs_app_get_state (app), ==, AS_APP_STATE_AVAILABLE);
+
+       /* install, also installing runtime and suggested extensions */
+       g_object_unref (plugin_job);
+       plugin_job = gs_plugin_job_newv (GS_PLUGIN_ACTION_INSTALL,
+                                        "app", app,
+                                        NULL);
+       ret = gs_plugin_loader_job_action (plugin_loader, plugin_job, NULL, &error);
+       gs_test_flush_main_context ();
+       g_assert_no_error (error);
+       g_assert_true (ret);
+       g_assert_cmpint (gs_app_get_state (app), ==, AS_APP_STATE_INSTALLED);
+       g_assert_cmpstr (gs_app_get_version (app), ==, "1.2.3");
+
+       /* check if the extension was installed */
+       global_cache = gs_plugin_loader_get_global_cache (plugin_loader);
+       extension = gs_app_list_lookup (global_cache, 
"user/flatpak/*/runtime/org.test.Chiron.Extension/master");
+       g_assert_nonnull (extension);
+       g_assert_cmpint (gs_app_get_state (extension), ==, AS_APP_STATE_INSTALLED);
+
+       /* getting the runtime for later removal */
+       runtime = gs_app_get_runtime (app);
+
+       /* remove the app */
+       g_object_unref (plugin_job);
+       plugin_job = gs_plugin_job_newv (GS_PLUGIN_ACTION_REMOVE,
+                                        "app", app,
+                                        NULL);
+       ret = gs_plugin_loader_job_action (plugin_loader, plugin_job, NULL, &error);
+       g_assert_no_error (error);
+       g_assert_true (ret);
+
+       /* remove the runtime */
+       g_object_unref (plugin_job);
+       plugin_job = gs_plugin_job_newv (GS_PLUGIN_ACTION_REMOVE,
+                                        "app", runtime,
+                                        NULL);
+       ret = gs_plugin_loader_job_action (plugin_loader, plugin_job, NULL, &error);
+       gs_test_flush_main_context ();
+       g_assert_no_error (error);
+       g_assert (ret);
+       g_assert_cmpint (gs_app_get_state (runtime), ==, AS_APP_STATE_AVAILABLE);
+
+       /* remove the remote */
+       g_object_unref (plugin_job);
+       plugin_job = gs_plugin_job_newv (GS_PLUGIN_ACTION_REMOVE,
+                                        "app", app_source,
+                                        NULL);
+       ret = gs_plugin_loader_job_action (plugin_loader, plugin_job, NULL, &error);
+       gs_test_flush_main_context ();
+       g_assert_no_error (error);
+       g_assert (ret);
+       g_assert_cmpint (gs_app_get_state (app_source), ==, AS_APP_STATE_AVAILABLE);
+
+       /* verify that the extension has been removed by the app's removal */
+       g_assert_false (gs_app_is_installed (extension));
+}
+
 int
 main (int argc, char **argv)
 {
@@ -1539,6 +1672,9 @@ main (int argc, char **argv)
        g_test_add_data_func ("/gnome-software/plugins/flatpak/runtime-repo-redundant",
                              plugin_loader,
                              (GTestDataFunc) gs_plugins_flatpak_runtime_repo_redundant_func);
+       g_test_add_data_func ("/gnome-software/plugins/flatpak/app-runtime-extension",
+                             plugin_loader,
+                             (GTestDataFunc) gs_plugins_flatpak_runtime_extension_func);
        g_test_add_data_func ("/gnome-software/plugins/flatpak/app-update-runtime",
                              plugin_loader,
                              (GTestDataFunc) gs_plugins_flatpak_app_update_func);
diff --git a/plugins/flatpak/tests/build.py b/plugins/flatpak/tests/build.py
index ae9f3f11..3db9e8af 100755
--- a/plugins/flatpak/tests/build.py
+++ b/plugins/flatpak/tests/build.py
@@ -3,6 +3,7 @@
 import subprocess
 import os
 import shutil
+import configparser
 
 def build_flatpak(appid, srcdir, repodir, cleanrepodir=True):
     print('Building %s from %s into %s' % (appid, srcdir, repodir))
@@ -25,12 +26,15 @@ def build_flatpak(appid, srcdir, repodir, cleanrepodir=True):
     else:
         flatpak_cmd = 'flatpak'
 
+    metadata_path = os.path.join(srcdir, appid, 'metadata')
+    metadata = configparser.ConfigParser()
+    metadata.read(metadata_path)
+    is_runtime = True if 'Runtime' in metadata.sections() else False
+
     # runtimes have different defaults
-    if appid.find('Runtime') != -1:
-        is_runtime = True
+    if is_runtime:
         prefix = 'usr'
     else:
-        is_runtime = False
         prefix = 'files'
 
     # finish the build
@@ -90,3 +94,14 @@ build_flatpak('org.test.Chiron',
 build_flatpak('org.test.Runtime',
               'only-runtime',
               'only-runtime/repo')
+
+# app with an extension
+copy_repo('only-runtime', 'app-extension')
+build_flatpak('org.test.Chiron',
+              'app-extension',
+              'app-extension/repo',
+              cleanrepodir=False)
+build_flatpak('org.test.Chiron.Extension',
+              'app-extension',
+              'app-extension/repo',
+              cleanrepodir=False)
diff --git a/plugins/flatpak/tests/flatpakrepos.tar.gz b/plugins/flatpak/tests/flatpakrepos.tar.gz
index 0a63de42..8ed3adf0 100644
Binary files a/plugins/flatpak/tests/flatpakrepos.tar.gz and b/plugins/flatpak/tests/flatpakrepos.tar.gz 
differ


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