[glib/wip/hadess/installed-tests: 82/82] tests: Don't run tests that require fuse on rootless containers



commit 429eac97a93c8e0334ac75e4552df3fd57e84760
Author: Bastien Nocera <hadess hadess net>
Date:   Wed Nov 20 16:54:19 2019 +0100

    tests: Don't run tests that require fuse on rootless containers
    
    If the fuse module is loaded but /dev/fuse doesn't exist, it's likely
    that we're running in a rootless container, or a badly setup one, and we
    won't be able to use fuse, so skip this test.
    
    This happened on my local system using podman running as a normal user,
    but this apparently works as expected in our CI[1].
    
    [1]: https://gitlab.gnome.org/GNOME/glib/merge_requests/466

 gio/tests/g-file-info-filesystem-readonly.c | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)
---
diff --git a/gio/tests/g-file-info-filesystem-readonly.c b/gio/tests/g-file-info-filesystem-readonly.c
index a715ef8d0..d2eb4dfd5 100644
--- a/gio/tests/g-file-info-filesystem-readonly.c
+++ b/gio/tests/g-file-info-filesystem-readonly.c
@@ -61,6 +61,17 @@ assert_remove (const gchar *file)
     g_error ("failed to remove %s: %s", file, g_strerror (errno));
 }
 
+static gboolean
+fuse_module_loaded (void)
+{
+  g_autofree char *contents = NULL;
+
+  if (!g_file_get_contents ("/proc/modules", &contents, NULL, NULL))
+    return FALSE;
+
+  return (strstr (contents, "\nfuse ") != NULL);
+}
+
 static void
 test_filesystem_readonly (gconstpointer with_mount_monitor)
 {
@@ -87,6 +98,18 @@ test_filesystem_readonly (gconstpointer with_mount_monitor)
       return;
     }
 
+  /* If the fuse module is loaded but there's no /dev/fuse, then we're
+   * we're probably in a rootless container and won't be able to
+   * use bindfs to run our tests */
+  if (fuse_module_loaded () &&
+      !g_file_test ("/dev/fuse", G_FILE_TEST_EXISTS))
+    {
+      g_test_skip ("fuse support is needed to run this test (rootless container?)");
+      g_free (fusermount);
+      g_free (bindfs);
+      return;
+    }
+
   curdir = g_get_current_dir ();
   dir_to_mount = g_strdup_printf ("%s/dir_bindfs_to_mount", curdir);
   file_in_mount = g_strdup_printf ("%s/example.txt", dir_to_mount);


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