[gnome-software] flatpak: Add a test for installing a bundle
- From: Richard Hughes <rhughes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software] flatpak: Add a test for installing a bundle
- Date: Fri, 12 Jun 2020 15:03:49 +0000 (UTC)
commit c42bad07e986d9aded4b3899dbaa3ea17cc7fb8b
Author: Matthew Leeds <matthew leeds endlessm com>
Date: Fri Jan 17 20:03:34 2020 -0800
flatpak: Add a test for installing a bundle
Add a unit test for installing a flatpak bundle, re-using much of the
code for the flatpakref install test.
plugins/flatpak/gs-self-test.c | 93 +++++++++++++++++++++++++----------
plugins/flatpak/tests/build.py | 14 ++++++
plugins/flatpak/tests/chiron.flatpak | Bin 0 -> 5316 bytes
plugins/flatpak/tests/meson.build | 6 +++
4 files changed, 86 insertions(+), 27 deletions(-)
---
diff --git a/plugins/flatpak/gs-self-test.c b/plugins/flatpak/gs-self-test.c
index 7d792dcb..f610c4b8 100644
--- a/plugins/flatpak/gs-self-test.c
+++ b/plugins/flatpak/gs-self-test.c
@@ -1020,14 +1020,14 @@ gs_plugins_flatpak_broken_remote_func (GsPluginLoader *plugin_loader)
}
static void
-gs_plugins_flatpak_ref_func (GsPluginLoader *plugin_loader)
+flatpak_bundle_or_ref_helper (GsPluginLoader *plugin_loader,
+ gboolean is_bundle)
{
GsApp *app_tmp;
GsApp *runtime;
gboolean ret;
- const gchar *fn = "test.flatpakref";
- g_autofree gchar *testdir2 = NULL;
- g_autofree gchar *testdir2_repourl = NULL;
+ GsPluginRefineFlags refine_flags;
+ g_autofree gchar *fn = NULL;
g_autofree gchar *testdir = NULL;
g_autofree gchar *testdir_repourl = NULL;
g_autoptr(GError) error = NULL;
@@ -1103,23 +1103,37 @@ gs_plugins_flatpak_ref_func (GsPluginLoader *plugin_loader)
g_assert (ret);
g_assert_cmpint (gs_app_get_state (runtime), ==, AS_APP_STATE_INSTALLED);
- /* write a flatpakref file */
- testdir2 = gs_test_get_filename (TESTDATADIR, "app-with-runtime");
- if (testdir2 == NULL)
- return;
- testdir2_repourl = g_strdup_printf ("file://%s/repo", testdir2);
- ret = gs_flatpak_test_write_ref_file (fn, testdir2_repourl, NULL, &file, &error);
- g_assert_no_error (error);
- g_assert (ret);
+ if (is_bundle) {
+ /* find the flatpak bundle file */
+ fn = gs_test_get_filename (TESTDATADIR, "chiron.flatpak");
+ g_assert (fn != NULL);
+ file = g_file_new_for_path (fn);
+ refine_flags = GS_PLUGIN_REFINE_FLAGS_DEFAULT;
+ } else {
+ g_autofree gchar *testdir2 = NULL;
+ g_autofree gchar *testdir2_repourl = NULL;
+
+ /* write a flatpakref file */
+ testdir2 = gs_test_get_filename (TESTDATADIR, "app-with-runtime");
+ if (testdir2 == NULL)
+ return;
+ testdir2_repourl = g_strdup_printf ("file://%s/repo", testdir2);
+ fn = g_strdup ("test.flatpakref");
+ ret = gs_flatpak_test_write_ref_file (fn, testdir2_repourl, NULL, &file, &error);
+ g_assert_no_error (error);
+ g_assert (ret);
+
+ refine_flags = GS_PLUGIN_REFINE_FLAGS_REQUIRE_VERSION |
+ GS_PLUGIN_REFINE_FLAGS_REQUIRE_URL |
+ GS_PLUGIN_REFINE_FLAGS_REQUIRE_DESCRIPTION |
+ GS_PLUGIN_REFINE_FLAGS_REQUIRE_RUNTIME;
+ }
/* convert it to a GsApp */
g_object_unref (plugin_job);
plugin_job = gs_plugin_job_newv (GS_PLUGIN_ACTION_FILE_TO_APP,
"file", file,
- "refine-flags", GS_PLUGIN_REFINE_FLAGS_REQUIRE_VERSION |
- GS_PLUGIN_REFINE_FLAGS_REQUIRE_URL |
- GS_PLUGIN_REFINE_FLAGS_REQUIRE_DESCRIPTION |
- GS_PLUGIN_REFINE_FLAGS_REQUIRE_RUNTIME,
+ "refine-flags", refine_flags,
NULL);
app = gs_plugin_loader_job_process_app (plugin_loader, plugin_job, NULL, &error);
g_assert_no_error (error);
@@ -1127,19 +1141,29 @@ gs_plugins_flatpak_ref_func (GsPluginLoader *plugin_loader)
g_assert_cmpint (gs_app_get_kind (app), ==, AS_APP_KIND_DESKTOP);
g_assert_cmpint (gs_app_get_state (app), ==, AS_APP_STATE_AVAILABLE_LOCAL);
g_assert_cmpstr (gs_app_get_id (app), ==, "org.test.Chiron");
-#if FLATPAK_CHECK_VERSION(1,1,2)
- g_assert (as_utils_unique_id_equal (gs_app_get_unique_id (app),
- "user/flatpak/chiron-origin/desktop/org.test.Chiron/master"));
-#else
- g_assert (as_utils_unique_id_equal (gs_app_get_unique_id (app),
- "user/flatpak/org.test.Chiron-origin/desktop/org.test.Chiron/master"));
-#endif
- g_assert_cmpstr (gs_app_get_url (app, AS_URL_KIND_HOMEPAGE), ==, "http://127.0.0.1/");
g_assert_cmpstr (gs_app_get_name (app), ==, "Chiron");
g_assert_cmpstr (gs_app_get_summary (app), ==, "Single line synopsis");
- g_assert_cmpstr (gs_app_get_description (app), ==, "Long description.");
g_assert_cmpstr (gs_app_get_version (app), ==, "1.2.3");
g_assert (gs_app_get_local_file (app) != NULL);
+ if (is_bundle) {
+ /* Note: The origin is set to "flatpak" here because an origin remote
+ * won't be created until the app is installed.
+ */
+ g_assert (as_utils_unique_id_equal (gs_app_get_unique_id (app),
+ "user/flatpak/flatpak/desktop/org.test.Chiron/master"));
+ g_assert (gs_flatpak_app_get_file_kind (app) == GS_FLATPAK_APP_FILE_KIND_BUNDLE);
+ } else {
+#if FLATPAK_CHECK_VERSION(1,1,2)
+ g_assert (as_utils_unique_id_equal (gs_app_get_unique_id (app),
+ "user/flatpak/chiron-origin/desktop/org.test.Chiron/master"));
+#else
+ g_assert (as_utils_unique_id_equal (gs_app_get_unique_id (app),
+ "user/flatpak/org.test.Chiron-origin/desktop/org.test.Chiron/master"));
+#endif
+ g_assert (gs_flatpak_app_get_file_kind (app) == GS_FLATPAK_APP_FILE_KIND_REF);
+ g_assert_cmpstr (gs_app_get_url (app, AS_URL_KIND_HOMEPAGE), ==, "http://127.0.0.1/");
+ g_assert_cmpstr (gs_app_get_description (app), ==, "Long description.");
+ }
/* get runtime */
runtime = gs_app_get_runtime (app);
@@ -1163,7 +1187,7 @@ gs_plugins_flatpak_ref_func (GsPluginLoader *plugin_loader)
g_object_unref (plugin_job);
plugin_job = gs_plugin_job_newv (GS_PLUGIN_ACTION_SEARCH,
"search", "chiron",
- "refine-flags", GS_PLUGIN_REFINE_FLAGS_REQUIRE_ICON,
+ "refine-flags", is_bundle ? GS_PLUGIN_REFINE_FLAGS_REQUIRE_RUNTIME :
GS_PLUGIN_REFINE_FLAGS_REQUIRE_ICON,
NULL);
search1 = gs_plugin_loader_job_process (plugin_loader, plugin_job, NULL, &error);
gs_test_flush_main_context ();
@@ -1231,7 +1255,7 @@ gs_plugins_flatpak_ref_func (GsPluginLoader *plugin_loader)
g_object_unref (plugin_job);
plugin_job = gs_plugin_job_newv (GS_PLUGIN_ACTION_SEARCH,
"search", "chiron",
- "refine-flags", GS_PLUGIN_REFINE_FLAGS_REQUIRE_ICON,
+ "refine-flags", is_bundle ? GS_PLUGIN_REFINE_FLAGS_REQUIRE_RUNTIME :
GS_PLUGIN_REFINE_FLAGS_REQUIRE_ICON,
NULL);
search2 = gs_plugin_loader_job_process (plugin_loader, plugin_job, NULL, &error);
gs_test_flush_main_context ();
@@ -1240,6 +1264,18 @@ gs_plugins_flatpak_ref_func (GsPluginLoader *plugin_loader)
g_assert_cmpint (gs_app_list_length (search2), ==, 0);
}
+static void
+gs_plugins_flatpak_ref_func (GsPluginLoader *plugin_loader)
+{
+ flatpak_bundle_or_ref_helper (plugin_loader, FALSE);
+}
+
+static void
+gs_plugins_flatpak_bundle_func (GsPluginLoader *plugin_loader)
+{
+ flatpak_bundle_or_ref_helper (plugin_loader, TRUE);
+}
+
static void
gs_plugins_flatpak_count_signal_cb (GsPluginLoader *plugin_loader, guint *cnt)
{
@@ -1813,6 +1849,9 @@ main (int argc, char **argv)
g_test_add_data_func ("/gnome-software/plugins/flatpak/ref",
plugin_loader,
(GTestDataFunc) gs_plugins_flatpak_ref_func);
+ g_test_add_data_func ("/gnome-software/plugins/flatpak/bundle",
+ plugin_loader,
+ (GTestDataFunc) gs_plugins_flatpak_bundle_func);
g_test_add_data_func ("/gnome-software/plugins/flatpak/broken-remote",
plugin_loader,
(GTestDataFunc) gs_plugins_flatpak_broken_remote_func);
diff --git a/plugins/flatpak/tests/build.py b/plugins/flatpak/tests/build.py
index 35ea0792..071761e7 100755
--- a/plugins/flatpak/tests/build.py
+++ b/plugins/flatpak/tests/build.py
@@ -55,6 +55,14 @@ def build_flatpak(appid, srcdir, repodir, branch='master', cleanrepodir=True):
argv.append('--runtime')
subprocess.call(argv)
+def build_flatpak_bundle(appid, srcdir, repodir, filename, branch='master'):
+ argv = ['flatpak', 'build-bundle']
+ argv.append(repodir)
+ argv.append(filename)
+ argv.append(appid)
+ argv.append(branch)
+ subprocess.call(argv)
+
def copy_repo(srcdir, destdir):
srcdir_repo = os.path.join(srcdir, 'repo')
destdir_repo = os.path.join(destdir, 'repo')
@@ -72,6 +80,12 @@ build_flatpak('org.test.Runtime',
'app-with-runtime/repo',
cleanrepodir=False)
+# build a flatpak bundle for the app
+build_flatpak_bundle('org.test.Chiron',
+ 'app-with-runtime',
+ 'app-with-runtime/repo',
+ 'chiron.flatpak')
+
# app referencing remote that cannot be found
build_flatpak('org.test.Chiron',
'app-with-runtime',
diff --git a/plugins/flatpak/tests/chiron.flatpak b/plugins/flatpak/tests/chiron.flatpak
new file mode 100644
index 00000000..b0fc314b
Binary files /dev/null and b/plugins/flatpak/tests/chiron.flatpak differ
diff --git a/plugins/flatpak/tests/meson.build b/plugins/flatpak/tests/meson.build
index 9a778d8b..27a84c25 100644
--- a/plugins/flatpak/tests/meson.build
+++ b/plugins/flatpak/tests/meson.build
@@ -24,3 +24,9 @@ custom_target(
'only-runtime/repo/',
],
)
+
+configure_file(
+ input : 'chiron.flatpak',
+ output : 'chiron.flatpak',
+ copy : true,
+)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]