[gnome-software] Add unit tests for the packagekit-local plugin



commit c21aa784ea5438a95f8c3c444827c58ff4a01dae
Author: Richard Hughes <richard hughsie com>
Date:   Tue Apr 26 07:52:14 2016 +0100

    Add unit tests for the packagekit-local plugin

 data/tests/build-rpm.sh                  |    2 +
 data/tests/chiron-1.1-1.fc24.x86_64.rpm  |  Bin 0 -> 6414 bytes
 data/tests/chiron.spec                   |   22 +++++++++++++++++
 src/gs-self-test.c                       |   38 ++++++++++++++++++++++++++++++
 src/plugins/gs-plugin-packagekit-local.c |    8 ++----
 5 files changed, 65 insertions(+), 5 deletions(-)
---
diff --git a/data/tests/build-rpm.sh b/data/tests/build-rpm.sh
new file mode 100755
index 0000000..90a4163
--- /dev/null
+++ b/data/tests/build-rpm.sh
@@ -0,0 +1,2 @@
+rpmbuild -ba chiron.spec
+cp ~/rpmbuild/RPMS/*/chiron*.rpm .
diff --git a/data/tests/chiron-1.1-1.fc24.x86_64.rpm b/data/tests/chiron-1.1-1.fc24.x86_64.rpm
new file mode 100644
index 0000000..1453f48
Binary files /dev/null and b/data/tests/chiron-1.1-1.fc24.x86_64.rpm differ
diff --git a/data/tests/chiron.spec b/data/tests/chiron.spec
new file mode 100644
index 0000000..6cbba7e
--- /dev/null
+++ b/data/tests/chiron.spec
@@ -0,0 +1,22 @@
+Summary:       Single line synopsis
+Name:          chiron
+Version:       1.1
+Release:       1%{?dist}
+URL:           http://127.0.0.1/
+License:       GPLv2+
+
+%description
+This is the first paragraph in the example package spec file.
+
+This is the second paragraph.
+
+%install
+mkdir -p $RPM_BUILD_ROOT/%{_bindir}
+touch $RPM_BUILD_ROOT/%{_bindir}/chiron
+
+%files
+%{_bindir}/chiron
+
+%changelog
+* Tue Apr 26 2016 Richard Hughes <richard hughsie com> - 1.1-1
+- Initial version
diff --git a/src/gs-self-test.c b/src/gs-self-test.c
index cae8df4..4c561e8 100644
--- a/src/gs-self-test.c
+++ b/src/gs-self-test.c
@@ -466,6 +466,40 @@ gs_plugin_loader_dpkg_func (GsPluginLoader *plugin_loader)
        g_assert (gs_app_get_local_file (app) != NULL);
 }
 
+static void
+gs_plugin_loader_packagekit_local_func (GsPluginLoader *plugin_loader)
+{
+       g_autoptr(GsApp) app = NULL;
+       g_autoptr(GError) error = NULL;
+       g_autofree gchar *fn = NULL;
+       g_autoptr(GFile) file = NULL;
+
+       /* no dpkg, abort */
+       if (!gs_plugin_loader_get_enabled (plugin_loader, "packagekit-local"))
+               return;
+
+       /* load local file */
+       fn = gs_test_get_filename ("tests/chiron-1.1-1.fc24.x86_64.rpm");
+       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_cmpstr (gs_app_get_id (app), ==, NULL);
+       g_assert_cmpstr (gs_app_get_source_default (app), ==, "chiron");
+       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_version (app), ==, "1.1-1.fc24");
+       g_assert_cmpstr (gs_app_get_summary (app), ==, "Single line synopsis");
+       g_assert_cmpstr (gs_app_get_description (app), ==,
+                        "This is the first paragraph in the example "
+                        "package spec file.  This is the second paragraph.");
+}
+
 int
 main (int argc, char **argv)
 {
@@ -483,6 +517,7 @@ main (int argc, char **argv)
                "icons",
                "menu-spec-refine",
                "provenance",
+               "packagekit-local",
                NULL
        };
 
@@ -567,6 +602,9 @@ main (int argc, char **argv)
        g_assert (gs_plugin_loader_get_enabled (plugin_loader, "dummy"));
 
        /* plugin tests go here */
+       g_test_add_data_func ("/gnome-software/plugin-loader{packagekit-local}",
+                             plugin_loader,
+                             (GTestDataFunc) gs_plugin_loader_packagekit_local_func);
        g_test_add_data_func ("/gnome-software/plugin-loader{dpkg}",
                              plugin_loader,
                              (GTestDataFunc) gs_plugin_loader_dpkg_func);
diff --git a/src/plugins/gs-plugin-packagekit-local.c b/src/plugins/gs-plugin-packagekit-local.c
index b35549e..6d0a402 100644
--- a/src/plugins/gs-plugin-packagekit-local.c
+++ b/src/plugins/gs-plugin-packagekit-local.c
@@ -262,11 +262,9 @@ gs_plugin_file_to_app (GsPlugin *plugin,
        gs_app_set_management_plugin (app, "packagekit");
        gs_app_set_kind (app, AS_APP_KIND_GENERIC);
        gs_app_set_state (app, AS_APP_STATE_AVAILABLE_LOCAL);
-       if (pk_details_get_summary (item))
-               gs_app_set_name (app, GS_APP_QUALITY_LOWEST,
-                                pk_details_get_summary (item));
-       else
-               gs_app_set_name (app, GS_APP_QUALITY_LOWEST, split[PK_PACKAGE_ID_NAME]);
+       gs_app_set_name (app, GS_APP_QUALITY_LOWEST, split[PK_PACKAGE_ID_NAME]);
+       gs_app_set_summary (app, GS_APP_QUALITY_LOWEST,
+                           pk_details_get_summary (item));
        gs_app_set_version (app, split[PK_PACKAGE_ID_VERSION]);
        gs_app_set_origin (app, basename);
        gs_app_add_source (app, split[PK_PACKAGE_ID_NAME]);


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