[gnome-software] trivial: Add self tests for .flatpakrepo support
- From: Richard Hughes <rhughes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software] trivial: Add self tests for .flatpakrepo support
- Date: Thu, 28 Jul 2016 11:04:11 +0000 (UTC)
commit d05599574a71692397a75b533c4bd817e1ccf919
Author: Richard Hughes <richard hughsie com>
Date: Thu Jul 28 11:32:12 2016 +0100
trivial: Add self tests for .flatpakrepo support
data/tests/Makefile.am | 1 +
data/tests/example.flatpakrepo | 7 +++
src/gs-self-test.c | 86 ++++++++++++++++++++++++++++++++++
src/plugins/gs-flatpak.c | 19 ++++++-
src/plugins/gs-plugin-flatpak-user.c | 3 +-
5 files changed, 112 insertions(+), 4 deletions(-)
---
diff --git a/data/tests/Makefile.am b/data/tests/Makefile.am
index 29feb92..a9ac657 100644
--- a/data/tests/Makefile.am
+++ b/data/tests/Makefile.am
@@ -3,6 +3,7 @@ EXTRA_DIST = \
chiron-0.2.cab \
chiron-1.1-1.deb \
chiron-1.1-1.fc24.x86_64.rpm \
+ example.flatpakrepo \
yum.repos.d/utopia.repo
-include $(top_srcdir)/git.mk
diff --git a/data/tests/example.flatpakrepo b/data/tests/example.flatpakrepo
new file mode 100644
index 0000000..f8f7f5e
--- /dev/null
+++ b/data/tests/example.flatpakrepo
@@ -0,0 +1,7 @@
+[Flatpak Repo]
+Title=foo-bar
+Comment=Longer one line comment
+Description=Longer multiline comment that does into detail.
+Url=http://foo.bar/apps
+Homepage=http://foo.bar
+GPGKey=LS0tLS1CRUdJTiBQR1AgUFVCTElDIEtFWSBCTE9DSy0tLS0tClZlcnNpb246IEdudVBHIHYyCgptUUVOQkZYWGFCQUJDQURTK0w3V2ZrZG5GTTlrNVNRSUhSd2pLYXY2c1dIQ2NDMGRLUjVxTklNQUF4ZmNLaVhPCkFMdlBjWkFNa2NhTnFmWGd1L2EwWU43cDhnTStvWjUxVzBtWnFnbytFTWtvbGMwQXlRQkNUdERqY1BBVmo0Sm8KYm91RjBub3pod1dJ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b/src/gs-self-test.c
index 4fae27a..91888b0 100644
--- a/src/gs-self-test.c
+++ b/src/gs-self-test.c
@@ -677,6 +677,86 @@ gs_plugin_loader_repos_func (GsPluginLoader *plugin_loader)
}
static void
+gs_plugin_loader_flatpak_repo_func (GsPluginLoader *plugin_loader)
+{
+ const gchar *group_name = "remote \"example\"";
+ const gchar *root = NULL;
+ gboolean ret;
+ g_autofree gchar *config_fn = NULL;
+ g_autofree gchar *fn = NULL;
+ g_autofree gchar *remote_url = NULL;
+ g_autoptr(GError) error = NULL;
+ g_autoptr(GFile) file = NULL;
+ g_autoptr(GKeyFile) kf = NULL;
+ g_autoptr(GsApp) app2 = NULL;
+ g_autoptr(GsApp) app = NULL;
+
+ /* no flatpak, abort */
+ if (!gs_plugin_loader_get_enabled (plugin_loader, "flatpak-user"))
+ return;
+
+ /* load local file */
+ fn = gs_test_get_filename ("tests/example.flatpakrepo");
+ g_assert (fn != NULL);
+ file = g_file_new_for_path (fn);
+ app = gs_plugin_loader_file_to_app (plugin_loader,
+ file,
+ GS_PLUGIN_REFINE_FLAGS_DEFAULT,
+ NULL,
+ &error);
+ g_assert_no_error (error);
+ g_assert (app != NULL);
+ g_assert_cmpint (gs_app_get_kind (app), ==, AS_APP_KIND_SOURCE);
+ g_assert_cmpint (gs_app_get_state (app), ==, AS_APP_STATE_AVAILABLE);
+ g_assert_cmpstr (gs_app_get_id (app), ==, "example");
+ g_assert_cmpstr (gs_app_get_management_plugin (app), ==, "flatpak-user");
+ g_assert_cmpstr (gs_app_get_origin_hostname(app), ==, "foo.bar");
+ g_assert_cmpstr (gs_app_get_url (app, AS_URL_KIND_HOMEPAGE), ==, "http://foo.bar");
+ g_assert_cmpstr (gs_app_get_name (app), ==, "foo-bar");
+ g_assert_cmpstr (gs_app_get_summary (app), ==, "Longer one line comment");
+ g_assert_cmpstr (gs_app_get_description (app), ==,
+ "Longer multiline comment that does into detail.");
+ g_assert (gs_app_get_local_file (app) != NULL);
+ g_assert (gs_app_get_pixbuf (app) != NULL);
+
+ /* now install the remote */
+ ret = gs_plugin_loader_app_action (plugin_loader, app,
+ GS_PLUGIN_LOADER_ACTION_INSTALL,
+ NULL,
+ &error);
+ g_assert_no_error (error);
+ g_assert (ret);
+ g_assert_cmpint (gs_app_get_state (app), ==, AS_APP_STATE_INSTALLED);
+
+ /* check config file was updated */
+ root = g_getenv ("GS_SELF_TEST_FLATPACK_DATADIR");
+ config_fn = g_build_filename (root, "flatpak", "repo", "config", NULL);
+ kf = g_key_file_new ();
+ ret = g_key_file_load_from_file (kf, config_fn, 0, &error);
+ g_assert_no_error (error);
+ g_assert (ret);
+
+ g_assert (g_key_file_has_group (kf, "core"));
+ g_assert (g_key_file_has_group (kf, group_name));
+ g_assert (g_key_file_get_boolean (kf, group_name, "gpg-verify", NULL));
+
+ /* check the URL was unmangled */
+ remote_url = g_key_file_get_string (kf, group_name, "url", &error);
+ g_assert_no_error (error);
+ g_assert_cmpstr (remote_url, ==, "http://foo.bar");
+
+ /* try again, check state is correct */
+ app2 = gs_plugin_loader_file_to_app (plugin_loader,
+ file,
+ GS_PLUGIN_REFINE_FLAGS_DEFAULT,
+ NULL,
+ &error);
+ g_assert_no_error (error);
+ g_assert (app2 != NULL);
+ g_assert_cmpint (gs_app_get_state (app2), ==, AS_APP_STATE_INSTALLED);
+}
+
+static void
gs_plugin_loader_flatpak_func (GsPluginLoader *plugin_loader)
{
GsApp *app;
@@ -1197,6 +1277,12 @@ main (int argc, char **argv)
g_test_add_data_func ("/gnome-software/plugin-loader{distro-upgrades}",
plugin_loader,
(GTestDataFunc) gs_plugin_loader_distro_upgrades_func);
+
+ /* done last as it would otherwise try to do downloading in other
+ * gs_plugin_file_to_app()-using tests */
+ g_test_add_data_func ("/gnome-software/plugin-loader{flatpak:repo}",
+ plugin_loader,
+ (GTestDataFunc) gs_plugin_loader_flatpak_repo_func);
return g_test_run ();
}
diff --git a/src/plugins/gs-flatpak.c b/src/plugins/gs-flatpak.c
index 4e445fc..79016e2 100644
--- a/src/plugins/gs-flatpak.c
+++ b/src/plugins/gs-flatpak.c
@@ -1696,11 +1696,24 @@ gs_flatpak_file_to_app_repo (GsFlatpak *self,
if (repo_title == NULL || repo_url == NULL || repo_gpgkey == NULL ||
repo_title[0] == '\0' || repo_url[0] == '\0' || repo_gpgkey[0] == '\0') {
g_set_error_literal (error,
- GS_PLUGIN_ERROR,
- GS_PLUGIN_ERROR_NOT_SUPPORTED,
- "not enough data in file, expected Title, Url, GPGKey");
+ GS_PLUGIN_ERROR,
+ GS_PLUGIN_ERROR_NOT_SUPPORTED,
+ "not enough data in file, "
+ "expected Title, Url, GPGKey");
+ return FALSE;
+ }
+
+ /* user specified a URL */
+ if (g_str_has_prefix (repo_gpgkey, "http://") ||
+ g_str_has_prefix (repo_gpgkey, "https://")) {
+ g_set_error_literal (error,
+ GS_PLUGIN_ERROR,
+ GS_PLUGIN_ERROR_NOT_SUPPORTED,
+ "Base64 encoded GPGKey required, not URL");
return FALSE;
}
+
+ /* create source */
app = gs_app_new (repo_id);
gs_app_set_kind (app, AS_APP_KIND_SOURCE);
gs_app_set_name (app, GS_APP_QUALITY_NORMAL, repo_title);
diff --git a/src/plugins/gs-plugin-flatpak-user.c b/src/plugins/gs-plugin-flatpak-user.c
index c87efbd..02d3b30 100644
--- a/src/plugins/gs-plugin-flatpak-user.c
+++ b/src/plugins/gs-plugin-flatpak-user.c
@@ -182,7 +182,8 @@ gs_plugin_file_to_app (GsPlugin *plugin,
GsPluginData *priv = gs_plugin_get_data (plugin);
/* only handle when installing bundles user-wide */
- if (g_settings_get_boolean (priv->settings,
+ if (g_getenv ("GS_SELF_TEST_FLATPACK_DATADIR") == NULL &&
+ g_settings_get_boolean (priv->settings,
"install-bundles-system-wide")) {
g_debug ("not handling bundle as per-system specified");
return TRUE;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]