90 lines
4.8 KiB
C
90 lines
4.8 KiB
C
/* Run only inside a disposable Arch build/test root. */
|
|
#define ARCHIPELAGO_PKEXEC "/tmp/archipelago-plugin-helper"
|
|
#include "gs-plugin-archipelago.c"
|
|
#include <glib/gstdio.h>
|
|
|
|
static GMainLoop *loop;
|
|
static GsAppList *result_list;
|
|
static GError *result_error;
|
|
static gboolean update_result;
|
|
static void shutdown_completed (GObject *source, GAsyncResult *result, gpointer data)
|
|
{
|
|
g_assert_true (gs_plugin_shutdown_finish (GS_PLUGIN (source), result, &result_error));
|
|
g_assert_no_error (result_error);
|
|
g_main_loop_quit (loop);
|
|
}
|
|
static void updated (GObject *source, GAsyncResult *result, gpointer data)
|
|
{
|
|
update_result = update_finish (GS_PLUGIN (source), result, &result_error);
|
|
g_main_loop_quit (loop);
|
|
}
|
|
static void completed (GObject *source, GAsyncResult *result, gpointer data)
|
|
{
|
|
result_list = list_apps_finish (GS_PLUGIN (source), result, &result_error);
|
|
g_main_loop_quit (loop);
|
|
}
|
|
|
|
int main (void)
|
|
{
|
|
g_autoptr(GTestDBus) test_bus = g_test_dbus_new (G_TEST_DBUS_NONE);
|
|
g_test_dbus_up (test_bus);
|
|
g_autoptr(GDBusConnection) bus = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, NULL);
|
|
g_assert_nonnull (bus);
|
|
g_autoptr(GsPlugin) plugin = g_object_new (gs_plugin_archipelago_get_type (),
|
|
"session-bus-connection", bus, "system-bus-connection", bus, NULL);
|
|
g_autoptr(GsAppQuery) query = gs_app_query_new ("is-for-update", GS_APP_QUERY_TRISTATE_TRUE, NULL);
|
|
g_mkdir_with_parents ("/var/lib/archipelago/software", 0755);
|
|
const gchar *fixture = "{\"version\":1,\"state\":\"available\",\"plan_id\":\"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",\"plan\":{\"base\":\"bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\",\"target\":\"cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc\",\"package_changes\":[{\"name\":\"linux\",\"old_version\":\"1\",\"new_version\":\"2\"},{\"name\":\"added\",\"old_version\":null,\"new_version\":\"3\"},{\"name\":\"removed\",\"old_version\":\"4\",\"new_version\":null}]}}";
|
|
g_assert_true (g_file_set_contents (STATUS_FILE, fixture, -1, NULL));
|
|
loop = g_main_loop_new (NULL, FALSE);
|
|
list_apps_async (plugin, query, 0, NULL, NULL, NULL, completed, NULL);
|
|
g_main_loop_run (loop);
|
|
g_assert_no_error (result_error);
|
|
g_assert_cmpuint (gs_app_list_length (result_list), ==, 1);
|
|
GsApp *app = gs_app_list_index (result_list, 0);
|
|
g_assert_true (gs_app_has_management_plugin (app, plugin));
|
|
g_assert_true (gs_app_has_quirk (app, GS_APP_QUIRK_NEEDS_REBOOT));
|
|
g_assert_cmpuint (gs_app_list_length (gs_app_get_related (app)), ==, 3);
|
|
g_assert_nonnull (strstr (gs_app_get_update_details_markup (app), "linux"));
|
|
g_assert_true (g_file_set_contents (ARCHIPELAGO_PKEXEC,
|
|
"#!/bin/sh\nprintf '%s\\n' \"$2\" > /tmp/archipelago-plugin-operation\n"
|
|
"if test -f /tmp/archipelago-plugin-fail; then echo 'fixture transaction rejected' >&2; exit 1; fi\n", -1, NULL));
|
|
g_assert_cmpint (g_chmod (ARCHIPELAGO_PKEXEC, 0700), ==, 0);
|
|
update_async (plugin, result_list, GS_PLUGIN_UPDATE_APPS_FLAGS_NO_APPLY, NULL, NULL, NULL, NULL, NULL, NULL, NULL, updated, NULL);
|
|
g_main_loop_run (loop);
|
|
g_assert_no_error (result_error);
|
|
g_assert_true (update_result);
|
|
g_assert_cmpint (gs_app_get_state (app), ==, GS_APP_STATE_UPDATABLE_LIVE);
|
|
g_assert_true (gs_app_is_downloaded (app));
|
|
g_autofree gchar *operation = NULL;
|
|
g_assert_true (g_file_get_contents ("/tmp/archipelago-plugin-operation", &operation, NULL, NULL));
|
|
g_assert_cmpstr (operation, ==, "download\n");
|
|
g_assert_true (g_file_set_contents ("/tmp/archipelago-plugin-fail", "fail", -1, NULL));
|
|
update_async (plugin, result_list, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, updated, NULL);
|
|
g_main_loop_run (loop);
|
|
g_assert_false (update_result);
|
|
g_assert_error (result_error, GS_PLUGIN_ERROR, GS_PLUGIN_ERROR_FAILED);
|
|
g_assert_cmpint (gs_app_get_state (app), ==, GS_APP_STATE_UPDATABLE_LIVE);
|
|
g_clear_error (&result_error);
|
|
g_unlink ("/tmp/archipelago-plugin-fail");
|
|
update_async (plugin, result_list, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, updated, NULL);
|
|
g_main_loop_run (loop);
|
|
g_assert_no_error (result_error);
|
|
g_assert_true (update_result);
|
|
g_assert_cmpint (gs_app_get_state (app), ==, GS_APP_STATE_INSTALLED);
|
|
g_clear_object (&result_list);
|
|
g_assert_true (g_file_set_contents (STATUS_FILE, "{\"version\":1,\"state\":\"error\",\"error\":\"signature rejected\"}", -1, NULL));
|
|
list_apps_async (plugin, query, 0, NULL, NULL, NULL, completed, NULL);
|
|
g_main_loop_run (loop);
|
|
g_assert_null (result_list);
|
|
g_assert_error (result_error, GS_PLUGIN_ERROR, GS_PLUGIN_ERROR_FAILED);
|
|
g_clear_error (&result_error);
|
|
gs_plugin_shutdown_async (plugin, NULL, shutdown_completed, NULL);
|
|
g_main_loop_run (loop);
|
|
g_main_loop_unref (loop);
|
|
g_clear_object (&plugin);
|
|
g_clear_object (&bus);
|
|
g_test_dbus_down (test_bus);
|
|
g_print ("PLUGIN_DIFF_DOWNLOAD_APPLY_ERROR_STATES_PASS\n");
|
|
return 0;
|
|
}
|