tests/sandbox: Use isolated-directories

So we don't have to bother to manually remove the created artifacts.
This commit is contained in:
Marco Trevisan (Treviño) 2022-11-24 04:23:57 +01:00
parent 4ba188c906
commit 660242af07

View File

@ -30,28 +30,24 @@ test_sandbox_none (void)
static void
test_sandbox_snap (void)
{
gchar *temp_dir, *snap_path, *snap_version_path, *meta_path, *yaml_path;
const char *temp_dir;
gchar *snap_path, *meta_path, *yaml_path;
GError *error = NULL;
temp_dir = g_dir_make_tmp ("gio-test-sandbox_XXXXXX", &error);
g_assert_no_error (error);
snap_path = g_build_filename (temp_dir, "snap", NULL);
snap_version_path = g_build_filename (snap_path, "current", NULL);
meta_path = g_build_filename (snap_version_path, "meta", NULL);
temp_dir = g_getenv ("G_TEST_TMPDIR");
g_assert_nonnull (temp_dir);
snap_path = g_build_filename (temp_dir, "snap", "current", NULL);
meta_path = g_build_filename (snap_path, "meta", NULL);
yaml_path = g_build_filename (meta_path, "snap.yaml", NULL);
g_mkdir_with_parents (meta_path, 0700);
g_file_set_contents (yaml_path, "", -1, NULL);
g_setenv ("SNAP", snap_version_path, TRUE);
g_file_set_contents (yaml_path, "", -1, &error);
g_assert_no_error (error);
g_setenv ("SNAP", snap_path, TRUE);
g_assert_cmpint (glib_get_sandbox_type (), ==, G_SANDBOX_TYPE_SNAP);
g_unsetenv ("SNAP");
g_unlink (yaml_path);
g_rmdir (meta_path);
g_rmdir (snap_version_path);
g_rmdir (snap_path);
g_rmdir (temp_dir);
g_free (temp_dir);
g_free (snap_path);
g_free (meta_path);
g_free (yaml_path);
@ -60,7 +56,7 @@ test_sandbox_snap (void)
int
main (int argc, char **argv)
{
g_test_init (&argc, &argv, NULL);
g_test_init (&argc, &argv, G_TEST_OPTION_ISOLATE_DIRS, NULL);
g_test_add_func ("/sandbox/none", test_sandbox_none);
g_test_add_func ("/sandbox/snap", test_sandbox_snap);