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
This commit is contained in:
Bastien Nocera 2019-11-20 16:54:19 +01:00
parent ead670b1c4
commit fc95385627

View File

@ -61,6 +61,24 @@ assert_remove (const gchar *file)
g_error ("failed to remove %s: %s", file, g_strerror (errno));
}
static gboolean
fuse_module_loaded (void)
{
char *contents = NULL;
gboolean ret;
if (!g_file_get_contents ("/proc/modules", &contents, NULL, NULL) ||
contents == NULL)
{
g_free (contents);
return FALSE;
}
ret = (strstr (contents, "\nfuse ") != NULL);
g_free (contents);
return ret;
}
static void
test_filesystem_readonly (gconstpointer with_mount_monitor)
{
@ -87,6 +105,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);